program-tv 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/bin/program-tv +20 -16
 - data/channels.yml +51 -57
 - data/lib/program-tv/parser.rb +5 -12
 - data/lib/program-tv.rb +3 -2
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: cdd826e88236e4397312508d2281c44dbfb4ce78
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4369235cebee6af25943fe94ccd1cb7b4350d387
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 415971534ac63f85bf06855d7b34b537f3d6d0978e210767ec63131c3eb10d740b09671a1baf61e60bfba919d8a3b1759c25e0db2e1ef3c66d65f68f4ceb86e7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7bc7c87c47261aad47ab497a83c30c42015fcf818a442e8199d352bd55d585079d59072d7631fc75384725c2875cd63784e5e04733b41a5c37baa81139babcef
         
     | 
    
        data/bin/program-tv
    CHANGED
    
    | 
         @@ -5,29 +5,33 @@ $LOAD_PATH.push File.expand_path("../lib", File.dirname(__FILE__)) # add library 
     | 
|
| 
       5 
5 
     | 
    
         
             
            require 'program-tv'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            options   = { 
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            op.banner = <<-eos
         
     | 
| 
       11 
     | 
    
         
            -
            #{ProgramTV::DESCRIPTION}
         
     | 
| 
      
 8 
     | 
    
         
            +
            options   = {}
         
     | 
| 
      
 9 
     | 
    
         
            +
            OptionParser.new do |op|
         
     | 
| 
      
 10 
     | 
    
         
            +
              op.banner = <<-eos
         
     | 
| 
      
 11 
     | 
    
         
            +
              #{ProgramTV::DESCRIPTION}
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            Usage: program-tv [options]
         
     | 
| 
      
 13 
     | 
    
         
            +
              Usage: program-tv [options]
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            eos
         
     | 
| 
      
 15 
     | 
    
         
            +
              eos
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            op.on("-h", "--help") do
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
              op.on("-h", "--help") do
         
     | 
| 
      
 18 
     | 
    
         
            +
                puts op.to_s
         
     | 
| 
      
 19 
     | 
    
         
            +
                exit!
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            op.on("-v", "--version") do
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
              op.on("-v", "--version") do
         
     | 
| 
      
 23 
     | 
    
         
            +
                puts ProgramTV::VERSION
         
     | 
| 
      
 24 
     | 
    
         
            +
                exit!
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              op.on("-c", "--channel-list PATH", "path to yml channel list") do |path|
         
     | 
| 
      
 28 
     | 
    
         
            +
                options[:channel_list] = path
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end.parse!
         
     | 
| 
       26 
31 
     | 
    
         | 
| 
       27 
32 
     | 
    
         
             
            begin
         
     | 
| 
       28 
     | 
    
         
            -
              op.parse!(ARGV)
         
     | 
| 
       29 
33 
     | 
    
         
             
              ARGV.clear
         
     | 
| 
       30 
     | 
    
         
            -
              ProgramTV.run!
         
     | 
| 
      
 34 
     | 
    
         
            +
              ProgramTV.run!(options)
         
     | 
| 
       31 
35 
     | 
    
         
             
            rescue Exception => ex
         
     | 
| 
       32 
36 
     | 
    
         
             
              puts ex.message
         
     | 
| 
       33 
37 
     | 
    
         
             
              exit!
         
     | 
    
        data/channels.yml
    CHANGED
    
    | 
         @@ -1,57 +1,51 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            -  
     | 
| 
       2 
     | 
    
         
            -
            -  
     | 
| 
       3 
     | 
    
         
            -
            -  
     | 
| 
       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 
     | 
    
         
            -
            - "tvr"
         
     | 
| 
       53 
     | 
    
         
            -
            - "tvs"
         
     | 
| 
       54 
     | 
    
         
            -
            - "tvtrwam"
         
     | 
| 
       55 
     | 
    
         
            -
            - "viasatexplorer"
         
     | 
| 
       56 
     | 
    
         
            -
            - "viasathistory"
         
     | 
| 
       57 
     | 
    
         
            -
            - "viasatnature"
         
     | 
| 
      
 1 
     | 
    
         
            +
            atm-rozrywka : atmrozrywka
         
     | 
| 
      
 2 
     | 
    
         
            +
            4fun-tv : 4funtv
         
     | 
| 
      
 3 
     | 
    
         
            +
            belsat-tv : belsat
         
     | 
| 
      
 4 
     | 
    
         
            +
            bloomberg-(ang.) : bloomberg
         
     | 
| 
      
 5 
     | 
    
         
            +
            deutsches-musik-fernsehen : deutschesmusik
         
     | 
| 
      
 6 
     | 
    
         
            +
            edusat : edusat
         
     | 
| 
      
 7 
     | 
    
         
            +
            eska-tv : eskatv
         
     | 
| 
      
 8 
     | 
    
         
            +
            filmbox : filmbox
         
     | 
| 
      
 9 
     | 
    
         
            +
            france-24 : france24
         
     | 
| 
      
 10 
     | 
    
         
            +
            france-24-en : france24en
         
     | 
| 
      
 11 
     | 
    
         
            +
            itv : itv
         
     | 
| 
      
 12 
     | 
    
         
            +
            kino-polska : kinopolska
         
     | 
| 
      
 13 
     | 
    
         
            +
            mango-24 : mango24
         
     | 
| 
      
 14 
     | 
    
         
            +
            novela-tv : novelatv
         
     | 
| 
      
 15 
     | 
    
         
            +
            polonia-1 : polonia1
         
     | 
| 
      
 16 
     | 
    
         
            +
            polo-tv : polotv
         
     | 
| 
      
 17 
     | 
    
         
            +
            polsat : polsat
         
     | 
| 
      
 18 
     | 
    
         
            +
            polsat-biznes : polsatbiznes
         
     | 
| 
      
 19 
     | 
    
         
            +
            jim-jam-polsat : polsatjimjam
         
     | 
| 
      
 20 
     | 
    
         
            +
            polsat-sport : polsatsport
         
     | 
| 
      
 21 
     | 
    
         
            +
            polsat-sport-news : polsatsportnews
         
     | 
| 
      
 22 
     | 
    
         
            +
            puls : puls
         
     | 
| 
      
 23 
     | 
    
         
            +
            puls-2 : puls2
         
     | 
| 
      
 24 
     | 
    
         
            +
            rbl.tv : rbltv
         
     | 
| 
      
 25 
     | 
    
         
            +
            russia-today : russiatoday
         
     | 
| 
      
 26 
     | 
    
         
            +
            stars-tv : starstv
         
     | 
| 
      
 27 
     | 
    
         
            +
            tele-5 : tele5
         
     | 
| 
      
 28 
     | 
    
         
            +
            ttv : ttv
         
     | 
| 
      
 29 
     | 
    
         
            +
            tv-4 : tv4
         
     | 
| 
      
 30 
     | 
    
         
            +
            tv-6 : tv6
         
     | 
| 
      
 31 
     | 
    
         
            +
            tv.disco : tvdisco
         
     | 
| 
      
 32 
     | 
    
         
            +
            tvn : tvn
         
     | 
| 
      
 33 
     | 
    
         
            +
            tvn-24 : tvn24
         
     | 
| 
      
 34 
     | 
    
         
            +
            tvn-7 : tvn7
         
     | 
| 
      
 35 
     | 
    
         
            +
            tvn-cnbc : tvncnbc
         
     | 
| 
      
 36 
     | 
    
         
            +
            tvn-meteo : tvnmeteo
         
     | 
| 
      
 37 
     | 
    
         
            +
            tvn-style : tvnstyle
         
     | 
| 
      
 38 
     | 
    
         
            +
            tvn-turbo : tvnturbo
         
     | 
| 
      
 39 
     | 
    
         
            +
            tvp-1 : tvp1
         
     | 
| 
      
 40 
     | 
    
         
            +
            tvp-2 : tvp2
         
     | 
| 
      
 41 
     | 
    
         
            +
            tvp-historia : tvphistoria
         
     | 
| 
      
 42 
     | 
    
         
            +
            tvp-info : tvpinfo
         
     | 
| 
      
 43 
     | 
    
         
            +
            tvp-kultura : tvpkultura
         
     | 
| 
      
 44 
     | 
    
         
            +
            tvp-polonia : tvppolonia
         
     | 
| 
      
 45 
     | 
    
         
            +
            tvp-rozrywka : tvprozrywka
         
     | 
| 
      
 46 
     | 
    
         
            +
            tvr : tvr
         
     | 
| 
      
 47 
     | 
    
         
            +
            tvs : tvs
         
     | 
| 
      
 48 
     | 
    
         
            +
            tv-trwam : tvtrwam
         
     | 
| 
      
 49 
     | 
    
         
            +
            polsat-viasat-explorer : viasatexplorer
         
     | 
| 
      
 50 
     | 
    
         
            +
            polsat-viasat-history : viasathistory
         
     | 
| 
      
 51 
     | 
    
         
            +
            polsat-viasat-nature : viasatnature
         
     | 
    
        data/lib/program-tv/parser.rb
    CHANGED
    
    | 
         @@ -3,39 +3,32 @@ module ProgramTV 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
                def initialize
         
     | 
| 
       5 
5 
     | 
    
         
             
                  @agent = Mechanize.new
         
     | 
| 
       6 
     | 
    
         
            -
                  @channel_list_url = "http://www.cyfrowypolsat.pl/program-tv/lista-kanalow/"
         
     | 
| 
       7 
6 
     | 
    
         
             
                end
         
     | 
| 
       8 
7 
     | 
    
         | 
| 
       9 
8 
     | 
    
         
             
                # Runs dynamic-sprites command.
         
     | 
| 
       10 
9 
     | 
    
         
             
                #
         
     | 
| 
       11 
10 
     | 
    
         
             
                def run
         
     | 
| 
       12 
     | 
    
         
            -
                   
     | 
| 
       13 
     | 
    
         
            -
                    schedule( 
     | 
| 
      
 11 
     | 
    
         
            +
                  ProgramTV.selected_channels.map do |url_name, epg_name|
         
     | 
| 
      
 12 
     | 
    
         
            +
                    schedule(epg_name, "http://www.cyfrowypolsat.pl/program-tv/#{url_name}")
         
     | 
| 
       14 
13 
     | 
    
         
             
                  end
         
     | 
| 
       15 
14 
     | 
    
         
             
                end
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
16 
     | 
    
         
             
                private
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                def schedule(url)
         
     | 
| 
      
 18 
     | 
    
         
            +
                def schedule(epg_name, url)
         
     | 
| 
       20 
19 
     | 
    
         
             
                  page = Nokogiri::HTML(@agent.get(url).body)
         
     | 
| 
       21 
20 
     | 
    
         
             
                  data = page.css(".main.col > table:last > tbody > tr").map do |e|
         
     | 
| 
       22 
21 
     | 
    
         
             
                    {
         
     | 
| 
       23 
22 
     | 
    
         
             
                      start:   running_time(e),
         
     | 
| 
       24 
     | 
    
         
            -
                      channel:  
     | 
| 
      
 23 
     | 
    
         
            +
                      channel: epg_name,
         
     | 
| 
       25 
24 
     | 
    
         
             
                      title:   e.css('.name').text
         
     | 
| 
       26 
25 
     | 
    
         
             
                    }
         
     | 
| 
       27 
26 
     | 
    
         
             
                  end
         
     | 
| 
       28 
27 
     | 
    
         
             
                  data[0..-2].each_with_index{ |element, i| element[:end] = data[i+1][:start] }
         
     | 
| 
       29 
     | 
    
         
            -
                  data. 
     | 
| 
      
 28 
     | 
    
         
            +
                  data.pop
         
     | 
| 
       30 
29 
     | 
    
         
             
                  data
         
     | 
| 
       31 
30 
     | 
    
         
             
                end
         
     | 
| 
       32 
31 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                # Fetches page with channel list and returns Array of urls to subpages with channel schedule
         
     | 
| 
       34 
     | 
    
         
            -
                def channel_urls
         
     | 
| 
       35 
     | 
    
         
            -
                  page = Nokogiri::HTML(@agent.get(@channel_list_url).body)
         
     | 
| 
       36 
     | 
    
         
            -
                  page.css('.rowChannel a').select{ |c| ProgramTV.selected_channels.include?(c.text.to_s.strip) }.map{ |c| c.attr('href') }
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
32 
     | 
    
         
             
                # Methods to retrieve channel attributes
         
     | 
| 
       40 
33 
     | 
    
         
             
                def running_time(element)
         
     | 
| 
       41 
34 
     | 
    
         
             
                  time = element.css('.time').text.match(/([0-9]+):([0-9]+)/)
         
     | 
    
        data/lib/program-tv.rb
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ module ProgramTV 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
              #----------------------------------------------------------------------------
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
              VERSION     = "0.0. 
     | 
| 
      
 5 
     | 
    
         
            +
              VERSION     = "0.0.3"
         
     | 
| 
       6 
6 
     | 
    
         
             
              SUMMARY     = "TV Channel parser"
         
     | 
| 
       7 
7 
     | 
    
         
             
              DESCRIPTION = "Downloads TV channel list in XML format"
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
         @@ -16,6 +16,7 @@ module ProgramTV 
     | 
|
| 
       16 
16 
     | 
    
         
             
              # Initilizes Runner which controls all the magic stuff.
         
     | 
| 
       17 
17 
     | 
    
         
             
              #
         
     | 
| 
       18 
18 
     | 
    
         
             
              def self.run!(options = {})
         
     | 
| 
      
 19 
     | 
    
         
            +
                @@options = options
         
     | 
| 
       19 
20 
     | 
    
         
             
                data = Parser.new.run
         
     | 
| 
       20 
21 
     | 
    
         
             
                puts Writer.new(data).run
         
     | 
| 
       21 
22 
     | 
    
         
             
              end
         
     | 
| 
         @@ -27,6 +28,6 @@ module ProgramTV 
     | 
|
| 
       27 
28 
     | 
    
         
             
              end
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
              def self.selected_channels
         
     | 
| 
       30 
     | 
    
         
            -
                @channels ||= YAML::load(File.open(File.join(gem_root, 'channels.yml')))
         
     | 
| 
      
 31 
     | 
    
         
            +
                @channels ||= YAML::load(File.open(@@options[:channel_list] || File.join(gem_root, 'channels.yml')))
         
     | 
| 
       31 
32 
     | 
    
         
             
              end
         
     | 
| 
       32 
33 
     | 
    
         
             
            end
         
     |