<commit_before>=begin
  Radio Playlist
  --------------
    In order to face a radio, we need to stream audio content.
    The BBC radio streams as a playlist file, which contains
    a link to a time-restricted audio stream.
    
    Every few hours, the stream disconnects and you have to 
    download the playlist again to continue.

    This class downloads the playlists, parses the audio end point,
    and places it in MPD's playlist directory.
=end

require "em-synchrony/em-http"

class RadioPlaylist
  URL = "http://www.bbc.co.uk/radio/listen/live/r%s_aaclca.pls"
  STATIONS = %w{1 1x 2 3 4 4lw 4x 5l 5lsp 6}
  attr_reader :playlists
  
  def initialize(options)
    @path = options[:path]
    @playlists = {}
  end

  def [](station_name)
    @playlists[station_name]
  end

  def download
    print 'downloading...'
    STATIONS.each do |station|
      req = EM::HttpRequest.new(URL % station).get
      return false if req.response_header.status != 200
      
      url = req.response.match(/^File1=(.*)$/)[1]
      print " #{station}"
      
      station_name = "bbc_radio_#{station}"
      
      if url != @playlists[station_name]
        @playlists[station_name] = url
        File.open("#{@path}/#{station_name}.m3u", 'w'){ |f| f.write("#{url}\n") }
      end
    end
    puts '...doneloading'
  end
end<commit_msg>Defer missing methods to the playlist object<commit_after>=begin
  Radio Playlist
  --------------
    In order to face a radio, we need to stream audio content.
    The BBC radio streams as a playlist file, which contains
    a link to a time-restricted audio stream.
    
    Every few hours, the stream disconnects and you have to 
    download the playlist again to continue.

    This class downloads the playlists, parses the audio end point,
    and places it in MPD's playlist directory.
=end

require "em-synchrony/em-http"

class RadioPlaylist
  URL = "http://www.bbc.co.uk/radio/listen/live/r%s_aaclca.pls"
  STATIONS = %w{1 1x 2 3 4 4lw 4x 5l 5lsp 6}
  attr_reader :playlists

  def initialize(options)
    @path = options[:path]
    @playlists = {}
  end

  def download
    print 'downloading...'
    STATIONS.each do |station|
      req = EM::HttpRequest.new(URL % station).get
      return false if req.response_header.status != 200
      
      url = req.response.match(/^File1=(.*)$/)[1]
      print " #{station}"
      
      station_name = "bbc_radio_#{station}"
      
      if url != @playlists[station_name]
        @playlists[station_name] = url
        File.open("#{@path}/#{station_name}.m3u", 'w'){ |f| f.write("#{url}\n") }
      end
    end
    puts '...doneloading'
  end
  
  private
  def method_missing(method, *args, &block)
    if @playlists.respond_to?(method)
      @playlists.public_send(method, *args, &block)
    else
      super
    end
  end
end
{'fraction_non_alphanumeric': 0.12048192771084337, 'fraction_numerical': 0.011339475549255847, 'mean_word_length': 2.6238767650834403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7518719', 'n_tokens_mistral': 964, 'n_tokens_neox': 924, 'n_words': 277}