rtv 0.0.2

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.
Files changed (5) hide show
  1. data/README +39 -0
  2. data/bin/tv.rb +20 -0
  3. data/doc/senderliste.txt +114 -0
  4. data/lib/rtv.rb +181 -0
  5. metadata +57 -0
data/README ADDED
@@ -0,0 +1,39 @@
1
+ RTV - a command line ruby tv guide
2
+
3
+ REQUIREMENTS
4
+
5
+ Hpricot ab Version 0.6 wird für das Parsen des HTML Inhaltes verwendet und muss installiert sein.
6
+ Es kann als Source .gz von http://code.whytheluckystiff.net/hpricot/ oder als gem "hpricot" bezogen werden.
7
+
8
+ INSTALLATION
9
+
10
+ Ich empfehle einen symbolischen Link namens tv zu erstellen:
11
+
12
+ 1. chmod +x rtv.rb
13
+ 2. ln -s /bin/tv.rb ~/bin/tv
14
+
15
+
16
+ USAGE
17
+
18
+ tv [ELEMENT] ...
19
+
20
+ ELEMENT kann folgende Werte enthalten:
21
+
22
+ a) TIME als Sendezeit im Format HH oder HH:MM (maximal eine TIME sinnvoll)
23
+ b) DATE als Datum im Format DD.MM
24
+ b) CHANNEL als Sender aus der Liste in doc/senderliste.txt
25
+ c) PATTERN als Suchbegriff (darf kein Sendername sein, siehe b))
26
+ d) DESCRIPTION als Beschreibung (feste Zeichenkette "-d")
27
+
28
+
29
+ EXAMPLES
30
+
31
+ tv - Aktuelle Sendungen für ausgewählte Sender
32
+ tv 20 - Heute 20 Uhr alle Sendungen für ausgewählte Sender
33
+ tv 24.12. - Alle Sendungen an Heilig Abend für ausgewählte Sender
34
+ tv pro7 sat1 - Aktuelle Sendungen von nur Pro7 und Sat.1
35
+ tv simpsons - Alle Sendungen über Die Simpsons für alle Sender
36
+ tv -d - Aktuelle Sendungen für ausgewählte Sender mit Beschreibung
37
+
38
+ Beliebige sinnvolle Kombinationen in beliebiger Reihenfolge sind möglich:
39
+ 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 ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'rtv'
3
+
4
+ if __FILE__ == $0
5
+ poptions = {}
6
+ poptions[:channel] = %w{ PRO7 ARTE 3SAT RTL2 SAT1 VOX RTL K1 }
7
+
8
+ swtch = RTV::Switcher.new
9
+ swtch.options = poptions
10
+
11
+ rtv = RTV::Fetcher.new
12
+ rtv.poptions = poptions
13
+ rtv.options = swtch.uri_options(ARGV.dup)
14
+ program = rtv.fetch
15
+
16
+ prtr = RTV::Presenter.new 'UTF-8'
17
+
18
+ prtr.options = swtch.options
19
+ prtr.show program
20
+ end
@@ -0,0 +1,114 @@
1
+ alle => all
2
+ Free TV => hauptgruppeId:1,3
3
+ Pay TV => hauptgruppeId:2
4
+ Digital TV => hauptgruppeId:3
5
+ Haupt- und Regionalsender => sendergruppeId:1,3
6
+ Hauptsender und Dritte => sendergruppeId:1,2
7
+ Haupt => sendergruppeId:1
8
+ ZDF => ZDF
9
+ RTL => RTL
10
+ SAT.1 => SAT1
11
+ PRO SIEBEN => PRO7
12
+ KABEL 1 => K1
13
+ RTL II => RTL2
14
+ SUPER RTL => SUPER
15
+ VOX => VOX
16
+ ARTE => ARTE
17
+ Tele 5 => TELE5
18
+ 3SAT => 3SAT
19
+ Das Vierte => DVIER
20
+ BAYERN => BR
21
+ HESSEN => HR
22
+ MDR => MDR
23
+ NDR => N3
24
+ RBB => RBB
25
+ SÜDWEST => SWR
26
+ WDR => WDR
27
+ Regional => sendergruppeId:3
28
+ BRalpha => BRALP
29
+ TV Berlin => TVB
30
+ HH 1 => H1
31
+ Ausland (deutschspr.) => sendergruppeId:4
32
+ ORF 1 => ORF1
33
+ ORF 2 => ORF2
34
+ ATVplus => ATV
35
+ SF 1 => SF1
36
+ SF2 => SF2
37
+ Premiere => sendergruppeId:5
38
+ Premiere Start => PRS
39
+ Digital => sendergruppeId:7
40
+ DW TV => DWTV
41
+ EinsExtra => EXTRA
42
+ EinsFestival => FES
43
+ EinsPlus => MUX
44
+ Theaterkanal => ZTK
45
+ ZDF doku => ZDOKU
46
+ ZDF info => ZINFO
47
+ Sport => sendergruppeId:8
48
+ DSF => DSF
49
+ EUROSPORT => EURO
50
+ Musik => sendergruppeId:9
51
+ MTV => MTV
52
+ VIVA => VIVA
53
+ Sparten => sendergruppeId:10
54
+ NICKELODEON => NICK
55
+ Kinderkanal => KIKA
56
+ QVC => QVC
57
+ TW1 => TW1
58
+ TERRA NOVA => TENO
59
+ Comedy Central => CC
60
+ News => sendergruppeId:11
61
+ BBC WORLD => BBC
62
+ CNN => CNN
63
+ Euronews => EURON
64
+ N 24 => N24
65
+ N-TV => NTV
66
+ Bloomberg TV => BLM
67
+ DMAX => DMAX
68
+ Ausland => sendergruppeId:12
69
+ NL 1 => NL1
70
+ NL 2 => NL2
71
+ NL 3 => NL3
72
+ Premiere Sport => sendergruppeId:13
73
+ Premiere Sport Portal => PSPO1
74
+ Premiere Direkt => sendergruppeId:15
75
+ Premiere Direkt => DIR1
76
+ Premiere Thema => sendergruppeId:16
77
+ Goldstar TV => GOLD
78
+ Heimatkanal => HEIMA
79
+ Animal Planet => APLAN
80
+ Beate Uhse TV => BUTV
81
+ Discovery Channel => DISCO
82
+ Junior => JUNIO
83
+ MGM => MGM
84
+ Planet => PLANE
85
+ Premiere Sci-Fi => SCIFI
86
+ 13th Street => 13TH
87
+ hit24 => HIT24
88
+ Discovery Geschichte => DISGE
89
+ Focus Gesundheit => FOGE
90
+ Blue Movie => sendergruppeId:17
91
+ Blue Movie => BLUM
92
+ Blue Movie Extra => BLUME
93
+ Arena => sendergruppeId:18
94
+ Arena => ARENA
95
+ Kabel/Satellit => sendergruppeId:19
96
+ AXN => AXN
97
+ Kinowelt => KINOW
98
+ SAT.1 omedy => SAT1C
99
+ Silverline => SILVE
100
+ History Channel => HISTO
101
+ NASN => NASN
102
+ Toon Disney => TOON
103
+ Premiere Blockbuster => sendergruppeId:20
104
+ Premiere 1 => PR1
105
+ Premiere 2 => PR2
106
+ Premiere 3 => PR3
107
+ Premiere 4 => PR4
108
+ Disney Chanel => DISNE
109
+ Premiere Entertainment => sendergruppeId:21
110
+ Premiere Filmclassics => PRFC
111
+ Premiere Filmfest => PRFF
112
+ Premiere Nostalgie => PRN
113
+ Premiere Serie => PRSER
114
+ Premiere Krimi => KRIMI
data/lib/rtv.rb ADDED
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'hpricot'
5
+ require 'open-uri'
6
+ require 'cgi'
7
+ require 'iconv'
8
+ require 'time'
9
+
10
+ $KCODE = 'u'
11
+
12
+ CHANNEL = ["all", "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
+
14
+ module RTV
15
+ class Program
16
+ attr_reader :channel
17
+
18
+ def initialize
19
+ @channel = {}
20
+ end
21
+ def << show
22
+ @channel[show.channel] ||= []
23
+ @channel[show.channel] << show
24
+ end
25
+ end
26
+ class Show
27
+ attr_accessor :channel, :name, :time, :date, :desc, :showview, :options
28
+ Filler = "\t"
29
+
30
+ def dont_repeat lastshow = ['', '', '', '']
31
+ self.to_a.zip(lastshow.to_a).map{|x,y| (x == y) ? (' ' * x.to_s.size) : x}.compact.join(Filler)
32
+ end
33
+ def to_a
34
+ tmp = [@channel, @date, @time, @name]
35
+ tmp << @desc if @options[:desc]
36
+ tmp
37
+ end
38
+ end
39
+ class Fetcher
40
+ TVURL = 'http://www.tvtoday.de/program2007'
41
+
42
+ attr_accessor :options, :poptions
43
+
44
+ def initialize
45
+ @options = {}
46
+ @shows = Program.new
47
+ end
48
+
49
+ def fetch
50
+ uri = TVURL + '?' + hsh_to_rqst(options)
51
+ doc = Hpricot(open(uri))
52
+
53
+ if @options[:format] == 'search'
54
+ daten = (doc/"div[@id='titel-uebersicht']")
55
+ daten.each do |datum|
56
+ zeiten = datum.parent.parent.parent.next_sibling
57
+ unless zeiten.nil?
58
+ zeiten = zeiten.search("span.tv-sendung-uhrzeit")
59
+ else
60
+ exit
61
+ end
62
+ zeiten.each do |zeit|
63
+ show = Show.new
64
+ show.options = @poptions
65
+ show.time = zeit.innerText
66
+ show.desc, show.showview = time_to_desc_and_showview(zeit)
67
+ show.name = time_to_name(zeit)
68
+ show.channel = time_to_channel(zeit)
69
+ show.date = datum.innerText[/^\D*(.+) Suchergebnis/, 1]
70
+ @shows << show
71
+ end
72
+ end
73
+ else
74
+ zeiten = (doc/"span.tv-sendung-uhrzeit")
75
+ zeiten.each do |zeit|
76
+ show = Show.new
77
+ show.options = @poptions
78
+ show.time = zeit.innerText
79
+ show.desc, show.showview = time_to_desc_and_showview(zeit)
80
+ show.name = time_to_name(zeit)
81
+ show.channel = time_to_channel(zeit)
82
+ @shows << show
83
+ end
84
+ end
85
+
86
+ @shows
87
+ end
88
+
89
+ private
90
+ def hsh_to_rqst hsh
91
+ hsh.to_a.map{|x| x.map{|y| CGI.escape(y.to_s)}.join('=')}.join('&')
92
+ end
93
+
94
+ def time_to_name zeit
95
+ zeit.parent.next_sibling.next_sibling.at("a.tv-sendung-titel").innerText
96
+ end
97
+
98
+ def time_to_channel zeit
99
+ zeit.parent.parent.at("span.tv-sendung-info/a").attributes["href"][/channelId=([^&]+)/, 1]
100
+ end
101
+
102
+ def time_to_desc_and_showview zeit
103
+ desc_showv = zeit.parent.parent.at("span.tv-sendung-info").innerText.strip.gsub(/[\t\r\n]+/, "\t")
104
+ desc = desc_showv.sub(/^\([^()]+\)\s+/, '').sub(/\s+Showview [0-9-]+/, '')
105
+ showview = desc_showv[/\s+Showview ([0-9-]+)/, 1]
106
+ [desc, showview]
107
+ end
108
+ end
109
+
110
+ class Presenter
111
+ Source_charset = 'ISO-8859-1'
112
+
113
+ attr_accessor :options
114
+
115
+ def initialize charset='UTF-8'
116
+ @target_charset = charset
117
+ end
118
+
119
+ def show program
120
+ @options[:channel].each do |channel|
121
+ lastshow = nil
122
+ tmp = program.channel[channel]
123
+ unless tmp.nil?
124
+ tmp.each do |show|
125
+ puts Iconv.iconv(@target_charset, Source_charset, show.dont_repeat(lastshow))
126
+ lastshow = show
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ class Switcher
134
+ attr_accessor :options
135
+ attr_reader :uri_options
136
+
137
+ def initialize
138
+ @uri_options = {}
139
+ end
140
+
141
+ def uri_options args
142
+ set_defaults
143
+
144
+ tmp_channel = @options[:channel]
145
+ @options[:channel] = []
146
+
147
+ args.each do |arg|
148
+ # Beschreibungmodus
149
+ if arg == "-d"
150
+ @options[:desc] = true
151
+ # Datummodus
152
+ elsif arg =~ /^\d{1,2}\.\d{1,2}\.$/
153
+ @uri_options[:date] = arg + Time.now.year.to_s
154
+
155
+ # Stundenmodus
156
+ elsif arg =~ /^\d{1,2}(?:\d{2})?$/
157
+ @uri_options[:time] = arg
158
+
159
+ # Channelname oder -alias
160
+ elsif CHANNEL.include? arg.upcase
161
+ @options[:channel] << arg.upcase
162
+
163
+ # Suchmodus
164
+ else
165
+ @uri_options.update({:search => arg, :format => 'search', :time => 'all', :date => 'all', :slotIndex => 'all'})
166
+ @options[:channel] = CHANNEL
167
+ end
168
+ end
169
+
170
+ @options[:channel] = tmp_channel if @options[:channel].empty?
171
+
172
+ @uri_options
173
+ end
174
+
175
+ private
176
+ def set_defaults
177
+ # FreeTV
178
+ @uri_options = {:date => 'now', :time => 'now', :format => 'genre', :channel => 'sendergruppeId:1,3', :order => 'time'}
179
+ end
180
+ end
181
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: rtv
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.2
7
+ date: 2007-07-13 00:00:00 +02:00
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
+ require_paths:
10
+ - lib
11
+ email: rretzbach@gmail.com
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: rtv
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Robert Retzbach
31
+ files:
32
+ - bin/tv.rb
33
+ - lib/rtv.rb
34
+ - doc/senderliste.txt
35
+ - README
36
+ test_files: []
37
+
38
+ rdoc_options: []
39
+
40
+ extra_rdoc_files:
41
+ - README
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ requirements: []
47
+
48
+ dependencies:
49
+ - !ruby/object:Gem::Dependency
50
+ name: hpricot
51
+ version_requirement:
52
+ version_requirements: !ruby/object:Gem::Version::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0.6"
57
+ version: