<commit_before>module Anyplayer
  class Itunes < Player
    def playpause
      tell_to 'playpause'
    end

    def prev
      tell_to 'previous track'
      super
    end

    def next
      tell_to 'next track'
      super
    end

    def voldown
      tell_to 'set sound volume to sound volume - 10'
    end

    def volup
      tell_to 'set sound volume to sound volume + 10'
    end

    def volume
      tell_to 'return sound volume'
    end

    def track
      tell_to 'return name of current track'
    end

    def artist
      tell_to 'return artist of current track'
    end

    def album
      tell_to 'return album of current track'
    end

    def launched?
      return false if RUBY_PLATFORM !~ /darwin/
      nb = %x(osascript -e 'tell app "System Events" to count (every process whose name is "iTunes")' 2>/dev/null).rstrip
      nb.match(/^\d+/) and nb.to_i > 0 ? true : false
    end

    def name
      "iTunes"
    end

    private
    def tell_to(command)
      %x(osascript -e 'tell app "iTunes" to #{command}').rstrip
    end
  end
end
<commit_msg>Using rb-appscript to make iTunes faster<commit_after>if RUBY_PLATFORM =~ /darwin/
  require 'appscript'
  include Appscript
end

module Anyplayer
  class Itunes < Player
    def playpause
      @app.playpause
    end

    def prev
      @app.previous_track
      super
    end

    def next
      @app.next_track
      super
    end

    def voldown
      @app.sound_volume.set(volume + 10)
    end

    def volup
      @app.sound_volume.set(volume + 10)
    end

    def volume
      @app.sound_volume.get
    end

    def track
      @app.current_track.name.get
    end

    def artist
      @app.current_track.artist.get
    end

    def album
      @app.current_track.album.get
    end

    def launched?
      return false unless RUBY_PLATFORM =~ /darwin/
      return false unless app('System Events').processes.name.get.include? "iTunes"
      @app = app('iTunes')
      true
    end

    def name
      "iTunes"
    end
  end
end

{'fraction_non_alphanumeric': 0.07040158651462568, 'fraction_numerical': 0.00495785820525533, 'mean_word_length': 1.9764011799410028, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2207164', 'n_tokens_mistral': 693, 'n_tokens_neox': 654, 'n_words': 208}