Search code examples
iosmetadatamd5utilityachievements

iTMSTransporter metadata.xml md5 utility ios


So I have 100 achievements to upload, rather than using the website I thought it may be faster to create a metadata.xml file and use iTMSTransporter to upload the data. Unfortunately one snag is a MD5 checksum must be computed for each image file, or Apple rejects the entire itmsp package. Requiring this almost invalidates the whole "ease" of using iTMSTransporter.

Is there a utility to parse the metadata file and update it with the checksums? Or perhaps something which generates a metadata file and does it?


Solution

  • There is a command line program that will generate the metadata.xml file and compute the files' checksums. It requires you to put your metadata in a YAML file which it turns into a metadata.xml: https://github.com/colinhumber/itunes_transporter_generator

    You can use this script to update a directory containing a metadata.xml file (or files) and assets:

    require "rexml/document"
    require "digest"
    
    def set_checksum(path)
      xml = File.read(path)
      doc = Document.new(xml)
      doc.get_elements("//achievement//file_name").each do |e|  
        next unless e.text =~ /\S/
    
        file = File.join($source, e.text.strip)
        puts "Computing checksum for #{file}"
    
        $md5.file(file)
        checksum = $md5.hexdigest!
    
        node = e.parent.elements["checksum"]
        node = Element.new("checksum", e.parent) unless node
        node.text = checksum 
        node.add_attribute("type", "md5")
      end
    
      puts "Saving update file"
      File.write(path, doc.to_s)
    end
    
    include REXML
    
    $source = ARGV.shift || Dir.pwd
    $md5 = Digest::MD5.new
    Dir["#$source/*.xml"].each do |path| 
      puts "Processing #{path}"
      set_checksum(path) 
    end
    

    Use it as follows:

    > ruby script.rb
    

    or

    > ruby script.rb /path/to/metadata/directory