rtv 0.0.2 → 0.1.1
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.
- data/README +29 -12
- data/bin/tv.rb +16 -7
- data/lib/rtv.rb +94 -30
- metadata +3 -3
    
        data/README
    CHANGED
    
    | @@ -1,16 +1,31 @@ | |
| 1 1 | 
             
            RTV - a command line ruby tv guide
         | 
| 2 2 |  | 
| 3 | 
            +
             | 
| 3 4 | 
             
            REQUIREMENTS
         | 
| 4 5 |  | 
| 5 6 | 
             
            	Hpricot ab Version 0.6 wird für das Parsen des HTML Inhaltes verwendet und muss installiert sein.
         | 
| 6 7 | 
             
            	Es kann als Source .gz von http://code.whytheluckystiff.net/hpricot/ oder als gem "hpricot" bezogen werden.
         | 
| 7 8 |  | 
| 9 | 
            +
             | 
| 8 10 | 
             
            INSTALLATION
         | 
| 9 11 |  | 
| 10 12 | 
             
            	Ich empfehle einen symbolischen Link namens tv zu erstellen:
         | 
| 11 13 |  | 
| 12 14 | 
             
            	1. chmod +x rtv.rb
         | 
| 13 | 
            -
            	2. ln -s  | 
| 15 | 
            +
            	2. ln -s bin/tv.rb ~/bin/tv
         | 
| 16 | 
            +
             | 
| 17 | 
            +
             | 
| 18 | 
            +
            CONFIGURATION
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            	Folgende Optionen können in einer YAML Konfigurationsdatei  $HOME/.rtv eingestellt werden:
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            	charset		Ausgabe Charset, default UTF-8
         | 
| 23 | 
            +
            	senderfilter	Sender und -reihenfolge der anzuzeigenden Sender
         | 
| 24 | 
            +
            	senderressource	Sendergruppierung aus der Liste in doc/senderliste.txt
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            	Eine Beispieldatei kann als Basis verwendet werden:
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            	1. cp etc/config.yaml.example ~/.rtv
         | 
| 14 29 |  | 
| 15 30 |  | 
| 16 31 | 
             
            USAGE
         | 
| @@ -19,21 +34,23 @@ USAGE | |
| 19 34 |  | 
| 20 35 | 
             
            	ELEMENT kann folgende Werte enthalten:
         | 
| 21 36 |  | 
| 22 | 
            -
            	 | 
| 23 | 
            -
            	 | 
| 24 | 
            -
            	 | 
| 25 | 
            -
            	 | 
| 26 | 
            -
            	 | 
| 37 | 
            +
            	TIME		Sendezeit im Format HH oder HH:MM (maximal eine TIME sinnvoll)
         | 
| 38 | 
            +
            	DATE 		Datum im Format DD.MM
         | 
| 39 | 
            +
            	CHANNEL		Sender aus der Liste in doc/senderliste.txt
         | 
| 40 | 
            +
            	PATTERN		Suchbegriff (darf kein Sendername sein, siehe b))
         | 
| 41 | 
            +
            	DESCRIPTION	Beschreibung, feste Zeichenkette "-d"
         | 
| 42 | 
            +
            	HELP		Hilfe, feste Zeichenkette "help" (gibt diese Seite aus)
         | 
| 27 43 |  | 
| 28 44 |  | 
| 29 45 | 
             
            EXAMPLES
         | 
| 30 46 |  | 
| 31 | 
            -
            	tv | 
| 32 | 
            -
            	tv 20 | 
| 33 | 
            -
            	tv 24.12. | 
| 34 | 
            -
            	tv pro7 sat1 | 
| 35 | 
            -
            	tv simpsons | 
| 36 | 
            -
            	tv -d | 
| 47 | 
            +
            	tv		Aktuelle Sendungen für ausgewählte Sender
         | 
| 48 | 
            +
            	tv 20		Heute 20 Uhr alle Sendungen für ausgewählte Sender
         | 
| 49 | 
            +
            	tv 24.12.	Alle Sendungen an Heilig Abend für ausgewählte Sender
         | 
| 50 | 
            +
            	tv pro7 sat1	Aktuelle Sendungen von nur Pro7 und Sat.1
         | 
| 51 | 
            +
            	tv simpsons	Alle Sendungen über Die Simpsons für alle Sender
         | 
| 52 | 
            +
            	tv -d		Aktuelle Sendungen für ausgewählte Sender mit Beschreibung
         | 
| 53 | 
            +
            	tv help		Gibt diese Seite aus
         | 
| 37 54 |  | 
| 38 55 | 
             
            	Beliebige sinnvolle Kombinationen in beliebiger Reihenfolge sind möglich:
         | 
| 39 56 | 
             
            	tv pro7 -d 20 11.07. sat1 - Alle Sendungen auf Pro7 und Sat.1 um 20 Uhr am 11.07. mit Beschreibung
         | 
    
        data/bin/tv.rb
    CHANGED
    
    | @@ -1,20 +1,29 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'rubygems'
         | 
| 2 4 | 
             
            require 'rtv'
         | 
| 5 | 
            +
            require 'yaml'
         | 
| 3 6 |  | 
| 4 7 | 
             
            if __FILE__ == $0
         | 
| 5 | 
            -
               | 
| 6 | 
            -
               | 
| 8 | 
            +
              config =
         | 
| 9 | 
            +
              begin
         | 
| 10 | 
            +
                configfile = File.join(Gem.user_home, '.rtv')
         | 
| 11 | 
            +
                YAML.load(File.read(configfile))
         | 
| 12 | 
            +
              rescue
         | 
| 13 | 
            +
                {:senderfilter=>["pro7", "arte", "3sat", "rtl2", "sat1", "vox", "rtl", "k1"],
         | 
| 14 | 
            +
                  :senderressource=>"sendergruppeId:1,3",
         | 
| 15 | 
            +
                  :charset=>"UTF-8"}
         | 
| 16 | 
            +
              end
         | 
| 7 17 |  | 
| 8 18 | 
             
              swtch = RTV::Switcher.new
         | 
| 9 | 
            -
              swtch. | 
| 19 | 
            +
              swtch.config = config
         | 
| 10 20 |  | 
| 11 21 | 
             
              rtv = RTV::Fetcher.new
         | 
| 12 | 
            -
              rtv. | 
| 22 | 
            +
              rtv.config = swtch.config
         | 
| 13 23 | 
             
              rtv.options = swtch.uri_options(ARGV.dup)
         | 
| 14 24 | 
             
              program = rtv.fetch
         | 
| 15 25 |  | 
| 16 | 
            -
              prtr = RTV::Presenter.new  | 
| 17 | 
            -
             | 
| 18 | 
            -
              prtr.options = swtch.options
         | 
| 26 | 
            +
              prtr = RTV::Presenter.new rtv.config[:charset]
         | 
| 27 | 
            +
              prtr.config = swtch.config
         | 
| 19 28 | 
             
              prtr.show program
         | 
| 20 29 | 
             
            end
         | 
    
        data/lib/rtv.rb
    CHANGED
    
    | @@ -9,7 +9,7 @@ require 'time' | |
| 9 9 |  | 
| 10 10 | 
             
            $KCODE = 'u'
         | 
| 11 11 |  | 
| 12 | 
            -
             | 
| 12 | 
            +
            Channel = %w{ard zdf rtl sat1 pro7 k1 rtl2 super vox arte tele5 3sat dvier br hr mdr n3 rbb swr wdr bralp tvb h1 orf1 orf2 atv sf1 sf2 prs dwtv extra fes mux ztk zdoku zinfo dsf euro mtv viva nick kika qvc tw1 teno cc bbc cnn euron n24 ntv blm dmax nl1 nl2 nl3 pspo1 dir1 gold heima aplan butv disco junio mgm plane scifi 13th hit24 disge foge blum blume arena axn kinow sat1c silve histo nasn toon pr1 pr2 pr3 pr4 disne prfc prff prn prser krimi}
         | 
| 13 13 |  | 
| 14 14 | 
             
            module RTV
         | 
| 15 15 | 
             
              class Program
         | 
| @@ -25,7 +25,12 @@ module RTV | |
| 25 25 | 
             
              end
         | 
| 26 26 | 
             
              class Show
         | 
| 27 27 | 
             
                attr_accessor :channel, :name, :time, :date, :desc, :showview, :options
         | 
| 28 | 
            +
                
         | 
| 28 29 | 
             
                Filler = "\t"
         | 
| 30 | 
            +
                
         | 
| 31 | 
            +
                def initialize
         | 
| 32 | 
            +
                  @date = nil
         | 
| 33 | 
            +
                end
         | 
| 29 34 |  | 
| 30 35 | 
             
                def dont_repeat lastshow = ['', '', '', '']
         | 
| 31 36 | 
             
                  self.to_a.zip(lastshow.to_a).map{|x,y| (x == y) ? (' ' * x.to_s.size) : x}.compact.join(Filler)
         | 
| @@ -35,11 +40,14 @@ module RTV | |
| 35 40 | 
             
                  tmp << @desc if @options[:desc]
         | 
| 36 41 | 
             
                  tmp
         | 
| 37 42 | 
             
                end
         | 
| 43 | 
            +
                def to_s
         | 
| 44 | 
            +
                  @name.to_s
         | 
| 45 | 
            +
                end
         | 
| 38 46 | 
             
              end
         | 
| 39 47 | 
             
              class Fetcher
         | 
| 40 48 | 
             
                TVURL = 'http://www.tvtoday.de/program2007'
         | 
| 41 49 |  | 
| 42 | 
            -
                attr_accessor :options, : | 
| 50 | 
            +
                attr_accessor :options, :config
         | 
| 43 51 |  | 
| 44 52 | 
             
                def initialize
         | 
| 45 53 | 
             
                  @options = {}
         | 
| @@ -47,9 +55,16 @@ module RTV | |
| 47 55 | 
             
                end
         | 
| 48 56 |  | 
| 49 57 | 
             
                def fetch
         | 
| 50 | 
            -
                   | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 58 | 
            +
                  while search_results?(doc = get_hdoc)
         | 
| 59 | 
            +
                    extract_shows doc
         | 
| 60 | 
            +
                    @options[:offset] += 1
         | 
| 61 | 
            +
                    print "." if $DEBUG
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
                  puts if $DEBUG
         | 
| 64 | 
            +
                  return @shows
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
                
         | 
| 67 | 
            +
                def extract_shows doc
         | 
| 53 68 | 
             
                  if @options[:format] == 'search'
         | 
| 54 69 | 
             
                    daten = (doc/"div[@id='titel-uebersicht']")
         | 
| 55 70 | 
             
                    daten.each do |datum|
         | 
| @@ -57,11 +72,12 @@ module RTV | |
| 57 72 | 
             
                      unless zeiten.nil?
         | 
| 58 73 | 
             
                        zeiten = zeiten.search("span.tv-sendung-uhrzeit")
         | 
| 59 74 | 
             
                      else
         | 
| 75 | 
            +
                        puts "Keine Suchergebnisse!" if $DEBUG
         | 
| 60 76 | 
             
                        exit
         | 
| 61 77 | 
             
                      end
         | 
| 62 78 | 
             
                      zeiten.each do |zeit|
         | 
| 63 79 | 
             
                        show = Show.new
         | 
| 64 | 
            -
            	    show.options = @ | 
| 80 | 
            +
            	    show.options = @config
         | 
| 65 81 | 
             
                        show.time = zeit.innerText
         | 
| 66 82 | 
             
            	    show.desc, show.showview = time_to_desc_and_showview(zeit)
         | 
| 67 83 | 
             
                        show.name = time_to_name(zeit)
         | 
| @@ -74,7 +90,7 @@ module RTV | |
| 74 90 | 
             
                    zeiten = (doc/"span.tv-sendung-uhrzeit")
         | 
| 75 91 | 
             
                    zeiten.each do |zeit|
         | 
| 76 92 | 
             
                      show = Show.new
         | 
| 77 | 
            -
                      show.options = @ | 
| 93 | 
            +
                      show.options = @config
         | 
| 78 94 | 
             
                      show.time = zeit.innerText
         | 
| 79 95 | 
             
                      show.desc, show.showview = time_to_desc_and_showview(zeit)
         | 
| 80 96 | 
             
                      show.name = time_to_name(zeit)
         | 
| @@ -82,11 +98,19 @@ module RTV | |
| 82 98 | 
             
                      @shows << show
         | 
| 83 99 | 
             
                    end
         | 
| 84 100 | 
             
                  end
         | 
| 85 | 
            -
                  
         | 
| 86 | 
            -
                  @shows
         | 
| 87 101 | 
             
                end
         | 
| 88 102 |  | 
| 89 103 | 
             
                private
         | 
| 104 | 
            +
                def get_hdoc
         | 
| 105 | 
            +
                  uri = TVURL + '?' + hsh_to_rqst(@options)
         | 
| 106 | 
            +
                  puts "URL: #{uri}" if $DEBUG
         | 
| 107 | 
            +
                  doc = Hpricot(open(uri))
         | 
| 108 | 
            +
                end
         | 
| 109 | 
            +
                
         | 
| 110 | 
            +
                def search_results? doc
         | 
| 111 | 
            +
                  (doc/"td.noresult").empty?
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
                
         | 
| 90 114 | 
             
                def hsh_to_rqst hsh
         | 
| 91 115 | 
             
                  hsh.to_a.map{|x| x.map{|y| CGI.escape(y.to_s)}.join('=')}.join('&')
         | 
| 92 116 | 
             
                end
         | 
| @@ -96,7 +120,7 @@ module RTV | |
| 96 120 | 
             
                end
         | 
| 97 121 |  | 
| 98 122 | 
             
                def time_to_channel zeit
         | 
| 99 | 
            -
                  zeit.parent.parent.at("span.tv-sendung-info/a").attributes["href"][/channelId=([^&]+)/, 1]
         | 
| 123 | 
            +
                  zeit.parent.parent.at("span.tv-sendung-info/a").attributes["href"][/channelId=([^&]+)/, 1].downcase
         | 
| 100 124 | 
             
                end
         | 
| 101 125 |  | 
| 102 126 | 
             
                def time_to_desc_and_showview zeit
         | 
| @@ -110,16 +134,17 @@ module RTV | |
| 110 134 | 
             
              class Presenter
         | 
| 111 135 | 
             
                Source_charset = 'ISO-8859-1'
         | 
| 112 136 |  | 
| 113 | 
            -
                attr_accessor : | 
| 137 | 
            +
                attr_accessor :config
         | 
| 114 138 |  | 
| 115 139 | 
             
                def initialize charset='UTF-8'
         | 
| 116 140 | 
             
                  @target_charset = charset
         | 
| 117 141 | 
             
                end
         | 
| 118 142 |  | 
| 119 143 | 
             
                def show program
         | 
| 120 | 
            -
                  @ | 
| 144 | 
            +
                  @config[:senderfilter].each do |channel|
         | 
| 121 145 | 
             
                    lastshow = nil
         | 
| 122 146 | 
             
                    tmp = program.channel[channel]
         | 
| 147 | 
            +
             | 
| 123 148 | 
             
                    unless tmp.nil?
         | 
| 124 149 | 
             
                      tmp.each do  |show|
         | 
| 125 150 | 
             
                        puts Iconv.iconv(@target_charset, Source_charset, show.dont_repeat(lastshow))
         | 
| @@ -131,8 +156,35 @@ module RTV | |
| 131 156 | 
             
              end
         | 
| 132 157 |  | 
| 133 158 | 
             
              class Switcher
         | 
| 134 | 
            -
                attr_accessor : | 
| 135 | 
            -
                 | 
| 159 | 
            +
                attr_accessor :config
         | 
| 160 | 
            +
                
         | 
| 161 | 
            +
                Usage = 'RTV - a command line ruby tv guide
         | 
| 162 | 
            +
             | 
| 163 | 
            +
            USAGE
         | 
| 164 | 
            +
             | 
| 165 | 
            +
            	tv [ELEMENT] ...
         | 
| 166 | 
            +
             | 
| 167 | 
            +
            	ELEMENT kann folgende Werte enthalten:
         | 
| 168 | 
            +
             | 
| 169 | 
            +
            	a) TIME als Sendezeit im Format HH oder HH:MM (maximal eine TIME sinnvoll)
         | 
| 170 | 
            +
            	b) DATE als Datum im Format DD.MM
         | 
| 171 | 
            +
            	b) CHANNEL als Sender aus der Liste in doc/senderliste.txt
         | 
| 172 | 
            +
            	c) PATTERN als Suchbegriff (darf kein Sendername sein, siehe b))
         | 
| 173 | 
            +
            	d) DESCRIPTION als Beschreibung, feste Zeichenkette "-d"
         | 
| 174 | 
            +
            	e) HELP als Hilfe, feste Zeichenkette "help" (gibt diese Seite aus)
         | 
| 175 | 
            +
             | 
| 176 | 
            +
             | 
| 177 | 
            +
            EXAMPLES
         | 
| 178 | 
            +
             | 
| 179 | 
            +
            	tv           - Aktuelle Sendungen für ausgewählte Sender
         | 
| 180 | 
            +
            	tv 20        - Heute 20 Uhr alle Sendungen für ausgewählte Sender
         | 
| 181 | 
            +
            	tv 24.12.    - Alle Sendungen an Heilig Abend für ausgewählte Sender
         | 
| 182 | 
            +
            	tv pro7 sat1 - Aktuelle Sendungen von nur Pro7 und Sat.1
         | 
| 183 | 
            +
            	tv simpsons  - Alle Sendungen über Die Simpsons für alle Sender
         | 
| 184 | 
            +
            	tv -d        - Aktuelle Sendungen für ausgewählte Sender mit Beschreibung
         | 
| 185 | 
            +
             | 
| 186 | 
            +
            	Beliebige sinnvolle Kombinationen in beliebiger Reihenfolge sind möglich:
         | 
| 187 | 
            +
            	tv pro7 -d 20 11.07. sat1 - Alle Sendungen auf Pro7 und Sat.1 um 20 Uhr am 11.07. mit Beschreibung'
         | 
| 136 188 |  | 
| 137 189 | 
             
                def initialize
         | 
| 138 190 | 
             
                  @uri_options = {}
         | 
| @@ -141,41 +193,53 @@ module RTV | |
| 141 193 | 
             
                def uri_options args
         | 
| 142 194 | 
             
                  set_defaults
         | 
| 143 195 |  | 
| 144 | 
            -
                  tmp_channel = @ | 
| 145 | 
            -
                  @ | 
| 196 | 
            +
                  tmp_channel = @config[:senderfilter]
         | 
| 197 | 
            +
                  @config[:senderfilter] = []
         | 
| 146 198 |  | 
| 147 199 | 
             
                  args.each do |arg|
         | 
| 148 | 
            -
                     | 
| 149 | 
            -
                     | 
| 150 | 
            -
                      @ | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 200 | 
            +
                    case arg.downcase
         | 
| 201 | 
            +
                    when "all"
         | 
| 202 | 
            +
                      @uri_options = all
         | 
| 203 | 
            +
                      
         | 
| 204 | 
            +
                      # Hilfemodus
         | 
| 205 | 
            +
                    when "help"
         | 
| 206 | 
            +
                      puts Usage
         | 
| 207 | 
            +
                      exit
         | 
| 208 | 
            +
                      
         | 
| 209 | 
            +
                      # Beschreibungmodus
         | 
| 210 | 
            +
                    when "-d"
         | 
| 211 | 
            +
                      @config[:desc] = true
         | 
| 212 | 
            +
                      
         | 
| 213 | 
            +
                      # Datummodus
         | 
| 214 | 
            +
                    when /^\d{1,2}\.\d{1,2}\.$/
         | 
| 153 215 | 
             
                      @uri_options[:date] = arg + Time.now.year.to_s
         | 
| 154 216 |  | 
| 155 | 
            -
             | 
| 156 | 
            -
                     | 
| 217 | 
            +
                      # Stundenmodus
         | 
| 218 | 
            +
                    when /^\d{1,2}(?:\d{2})?$/
         | 
| 157 219 | 
             
                      @uri_options[:time] = arg
         | 
| 158 220 |  | 
| 159 221 | 
             
                      # Channelname oder -alias
         | 
| 160 | 
            -
                     | 
| 161 | 
            -
                      @ | 
| 222 | 
            +
                    when *Channel
         | 
| 223 | 
            +
                      @config[:senderfilter] << arg.downcase
         | 
| 162 224 |  | 
| 163 225 | 
             
                      # Suchmodus
         | 
| 164 226 | 
             
                    else
         | 
| 165 227 | 
             
                      @uri_options.update({:search => arg, :format => 'search', :time => 'all', :date => 'all', :slotIndex => 'all'})
         | 
| 166 | 
            -
                      @ | 
| 228 | 
            +
                      @config[:senderfilter] = Channel
         | 
| 167 229 | 
             
                    end
         | 
| 168 230 | 
             
                  end
         | 
| 169 231 |  | 
| 170 | 
            -
                   | 
| 232 | 
            +
                  # when channels are specified, use them only
         | 
| 233 | 
            +
                  @config[:senderfilter] = tmp_channel if @config[:senderfilter].empty?
         | 
| 171 234 |  | 
| 172 235 | 
             
                  @uri_options
         | 
| 173 236 | 
             
                end
         | 
| 174 237 |  | 
| 175 238 | 
             
                private
         | 
| 176 239 | 
             
                def set_defaults
         | 
| 177 | 
            -
                  #  | 
| 178 | 
            -
                  @uri_options = {:date => 'now', :time => 'now', :format => 'genre', :channel =>  | 
| 240 | 
            +
                  # Haupt- und Regionalsender
         | 
| 241 | 
            +
                  @uri_options = {:date => 'now', :time => 'now', :format => 'genre', :channel => @config[:senderressource], :order => 'time', :offset => 0}
         | 
| 179 242 | 
             
                end
         | 
| 180 243 | 
             
              end
         | 
| 181 | 
            -
            end
         | 
| 244 | 
            +
            end
         | 
| 245 | 
            +
             | 
    
        metadata
    CHANGED
    
    | @@ -3,13 +3,13 @@ rubygems_version: 0.9.4 | |
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: rtv
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0. | 
| 7 | 
            -
            date: 2007-07- | 
| 6 | 
            +
              version: 0.1.1
         | 
| 7 | 
            +
            date: 2007-07-14 00:00:00 +02:00
         | 
| 8 8 | 
             
            summary: RTV is a command line tv guide for german television. It features a flexible argument parsing for quick usage in your favorite shell so you don't have to remember the syntax. Query shows by name, date, time or channel! Get it now!
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib
         | 
| 11 11 | 
             
            email: rretzbach@gmail.com
         | 
| 12 | 
            -
            homepage: 
         | 
| 12 | 
            +
            homepage: http://rtv.rubyforge.org/
         | 
| 13 13 | 
             
            rubyforge_project: 
         | 
| 14 14 | 
             
            description: 
         | 
| 15 15 | 
             
            autorequire: rtv
         |