<commit_before>module Cifrado
  class CLI

    desc "jukebox CONTAINER", 
         "Play music randomly from the target container"
    option :match, :type => :string
    def jukebox(container)
      client = client_instance
      token = client.service.credentials[:token]
      mgmt_url = client.service.credentials[:server_management_url]
      
      tmpout = "/tmp/#{SecureRandom.hex}"

      mpbin = '/usr/bin/mplayer'
      mpbin = File.exist?(mpbin) ? \
        mpbin : `which /usr/bin/mplayer`.strip.chomp
      unless File.exist?(mpbin)
        Log.error "MPlayer binary not found. Install it first."
        exit 1
      end

      pipe = nil
      cb = Proc.new do |total, bytes, segment|
        pipe.write segment if bytes > 0
      end

      dir = client.service.directories.get container
      unless dir
        Log.error "Container #{container} not found."
        exit 1
      end
      songs = dir.files
      last_exit = Time.now.to_f

      Log.info
      Log.info set_color "Cifrado Jukebox", :bold
      Log.info "---------------"
      Log.info
      Log.info set_color("Ctrl-C once", :bold)+ "   -> next song"
      Log.info set_color("Ctrl-C twice", :bold)+ "  -> quit"
      Log.info
      songs.shuffle.each do |song|
        pipe = IO.popen("mplayer -cache 256 - > /dev/null 2>&1", "w")
        if options[:match] and song.key !~ /#{options[:match]}/i
          next
        end
        begin
          unless (song.content_type =~ /audio|ogg|mp3/) or \
                  song.key =~ /(mp3|wav|ogg)$/
            next
          end
          Log.info "#{set_color 'Playing', :bold} song"
          Log.info "  * #{song.key}"
          r = client.download container, 
                              song.key, 
                              :output => tmpout,
                              :progress_callback => cb
          puts 'end'
          pipe.close
        rescue Interrupt => e
          if Time.now.to_f - last_exit < 1
            Log.info
            Log.info set_color "Adios!", :bold
            exit 0
          else
            last_exit = Time.now.to_f
            Log.info 'Next song...'
          end
        rescue => e
          Log.error "Error streaming song #{song.key}"
          raise e
        end
      end
    rescue SystemExit
    rescue => e
      Log.error e.message
      Log.debug e.backtrace
    ensure 
      pipe.close if pipe
    end

  end
end
<commit_msg>Decrapify<commit_after>module Cifrado
  class CLI

    desc "jukebox CONTAINER", 
         "Play music randomly from the target container"
    option :match, :type => :string
    def jukebox(container)
      client = client_instance
      token = client.service.credentials[:token]
      mgmt_url = client.service.credentials[:server_management_url]
      
      tmpout = "/tmp/#{SecureRandom.hex}"

      mpbin = '/usr/bin/mplayer'
      mpbin = File.exist?(mpbin) ? \
        mpbin : `which /usr/bin/mplayer`.strip.chomp
      unless File.exist?(mpbin)
        Log.error "MPlayer binary not found. Install it first."
        exit 1
      end

      pipe = nil
      cb = Proc.new do |total, bytes, segment|
        pipe.write segment if bytes > 0
      end

      dir = client.service.directories.get container
      unless dir
        Log.error "Container #{container} not found."
        exit 1
      end
      songs = dir.files
      last_exit = Time.now.to_f

      Log.info
      Log.info set_color "Cifrado Jukebox", :bold
      Log.info "---------------"
      Log.info
      Log.info set_color("Ctrl-C once", :bold)+ "   -> next song"
      Log.info set_color("Ctrl-C twice", :bold)+ "  -> quit"
      Log.info
      songs.shuffle.each do |song|
        pipe = IO.popen("mplayer -cache 256 - > /dev/null 2>&1", "w")
        if options[:match] and song.key !~ /#{options[:match]}/i
          next
        end
        begin
          unless (song.content_type =~ /audio|ogg|mp3/) or \
                  song.key =~ /(mp3|wav|ogg)$/
            next
          end
          Log.info "#{set_color 'Playing', :bold} song"
          Log.info "  * #{song.key}"
          r = client.download container, 
                              song.key, 
                              :output => tmpout,
                              :progress_callback => cb
          pipe.close
          File.delete tmpout
        rescue Interrupt => e
          if Time.now.to_f - last_exit < 1
            Log.info set_color "\nAdios!", :bold
            exit 0
          else
            last_exit = Time.now.to_f
            Log.info 'Next song...'
          end
        rescue => e
          Log.error "Error streaming song #{song.key}"
          raise e
        end
      end
    rescue SystemExit
    rescue => e
      Log.error e.message
      Log.debug e.backtrace
    ensure 
      pipe.close if pipe
    end

  end
end

{'fraction_non_alphanumeric': 0.11157110329124405, 'fraction_numerical': 0.004967915545435728, 'mean_word_length': 1.5023303987571206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5739031', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1438, 'n_words': 379}