class AudioAddict::Commands::PlaylistCmd

Public Instance Methods

generate_command(name = nil) click to toggle source
# File lib/audio_addict/commands/playlist.rb, line 37
def generate_command(name = nil)
  needs :network, :channel, :listen_key

  require_premium_account

  name ||= args["NAME"]

  infile = "#{name}.yml"
  outfile = "#{name}.pls"

  if !File.exist? infile
    say "!txtred!Cannot find #{infile}"
  else
    say "!txtred!Warning!txtrst!: !txtgrn!#{outfile}!txtrst! already exists!" if File.exist? outfile
    proceed = prompt.yes? "Create #{outfile}?"
    generate_playlist infile, outfile if proceed
  end
end
init_command() click to toggle source
# File lib/audio_addict/commands/playlist.rb, line 20
def init_command
  needs :network, :channel, :listen_key

  require_premium_account

  name = args["NAME"]
  outfile = "#{name}.yml"

  say "!txtred!Warning!txtrst!: !txtgrn!#{outfile}!txtrst! already exists!" if File.exist? outfile
  proceed = prompt.yes? "Create #{outfile}?"
  if proceed
    generate_config outfile
    say ""
    generate_command name
  end
end

Private Instance Methods

fix_key(key) click to toggle source

This is a patch to circumvent some anomalies in the AudioAddict API

# File lib/audio_addict/commands/playlist.rb, line 106
def fix_key(key)
  key = :electrohouse if current_network == "di" and key == :electro
  key
end
generate_config(outfile) click to toggle source
# File lib/audio_addict/commands/playlist.rb, line 58
def generate_config(outfile)
  data = { template: radio.url_template }
  channels = {}

  radio.channels.each do |key, channel|
    key = fix_key key.to_sym
    channels[key] = channel.name
  end

  data[:channels] = channels

  File.write outfile, data.to_yaml
  say "Saved !txtgrn!#{outfile}"
end
generate_playlist(infile, outfile) click to toggle source
# File lib/audio_addict/commands/playlist.rb, line 73
def generate_playlist(infile, outfile)
  data = YAML.load_file infile
  template = data[:template]
  channels = data[:channels]

  output = []
  output << "[playlist]"
  output << "NumberOfEntries=#{channels.count}"

  index = 0

  channels.each do |key, name|
    index += 1
    output << "File#{index}=#{template}" % template_params(key)
    output << "Title#{index}=#{name}"
    output << "Length#{index}=0"
  end

  output = output.join("\n") + "\n"

  File.write outfile, output
  say "Saved !txtgrn!#{outfile}"
end
listen_key() click to toggle source
# File lib/audio_addict/commands/playlist.rb, line 101
def listen_key
  Config.listen_key
end
template_params(channel_key) click to toggle source
# File lib/audio_addict/commands/playlist.rb, line 97
def template_params(channel_key)
  { listen_key: listen_key, channel_key: channel_key }
end