Class: Deliver::UploadScreenshots

Inherits:
Object
  • Object
show all
Defined in:
lib/deliver/upload_screenshots.rb

Overview

upload screenshots to iTunes Connect

Instance Method Summary collapse

Instance Method Details

#collect_screenshots(options) ⇒ Object



55
56
57
58
# File 'lib/deliver/upload_screenshots.rb', line 55

def collect_screenshots(options)
  return [] if options[:skip_screenshots]
  return collect_screenshots_for_languages(options[:screenshots_path])
end

#collect_screenshots_for_languages(path) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/deliver/upload_screenshots.rb', line 60

def collect_screenshots_for_languages(path)
  screenshots = []
  extensions = '{png,jpg,jpeg}'

  Loader.language_folders(path).each do |lng_folder|
    language = File.basename(lng_folder)

    # Check to see if we need to traverse multiple platforms or just a single platform
    if language == Loader::APPLE_TV_DIR_NAME
      screenshots.concat(collect_screenshots_for_languages(File.join(path, language)))
      next
    end

    files = Dir.glob(File.join(lng_folder, "*.#{extensions}"), File::FNM_CASEFOLD)
    next if files.count == 0

    prefer_framed = Dir.glob(File.join(lng_folder, "*_framed.#{extensions}"), File::FNM_CASEFOLD).count > 0

    language = File.basename(lng_folder)
    files.each do |file_path|
      if file_path.downcase.include?("_framed.")
        # That's cool
      else
        if file_path.downcase.include?("watch")
          # Watch doesn't support frames (yet)
        else
          # That might not be cool... if that screenshot is not framed but we only want framed
          next if prefer_framed
        end
      end

      screenshots << AppScreenshot.new(file_path, language)
    end
  end

  return screenshots
end

#upload(options, screenshots) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/deliver/upload_screenshots.rb', line 4

def upload(options, screenshots)
  return if options[:skip_screenshots]

  app = options[:app]

  v = app.edit_version
  raise "Could not find a version to edit for app '#{app.name}'".red unless v

  Helper.log.info "Starting with the upload of screenshots..."

  # First, clear all previously uploaded screenshots, but only where we have new ones
  # screenshots.each do |screenshot|
  #   to_remove = v.screenshots[screenshot.language].find_all do |current|
  #     current.device_type == screenshot.device_type
  #   end
  #   to_remove.each { |t| t.reset! }
  # end
  # This part is not working yet...

  # Now, fill in the new ones
  indized = {} # per language and device type

  screenshots_per_language = screenshots.group_by(&:language)
  screenshots_per_language.each do |language, screenshots_for_language|
    Helper.log.info "Uploading #{screenshots_for_language.length} screenshots for language #{language}"
    screenshots_for_language.each do |screenshot|
      indized[screenshot.language] ||= {}
      indized[screenshot.language][screenshot.device_type] ||= 0
      indized[screenshot.language][screenshot.device_type] += 1 # we actually start with 1... wtf iTC

      index = indized[screenshot.language][screenshot.device_type]

      if index > 5
        Helper.log.error "Too many screenshots found for device '#{screenshot.device_type}' in '#{screenshot.language}'"
        next
      end

      Helper.log.info "Uploading '#{screenshot.path}'..."
      v.upload_screenshot!(screenshot.path,
                           index,
                           screenshot.language,
                           screenshot.device_type)
    end
    # ideally we should only save once, but itunes server can't cope it seems
    # so we save per language. See issue #349
    Helper.log.info "Saving changes"
    v.save!
  end
  Helper.log.info "Successfully uploaded screenshots to iTunes Connect".green
end