rtv 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/tv.rb +11 -5
  2. data/lib/rtv.rb +36 -18
  3. metadata +2 -2
data/bin/tv.rb CHANGED
@@ -5,16 +5,22 @@ require 'rtv'
5
5
  require 'yaml'
6
6
 
7
7
  if __FILE__ == $0
8
- config =
9
- begin
8
+ config = {:senderfilter=>["pro7", "arte", "3sat", "rtl2", "sat1", "vox", "rtl", "k1"],
9
+ :senderressource=>"sendergruppeId:1,3",
10
+ :charset=>"UTF-8",
11
+ :senderlimit=>15,
12
+ :eine_pro_sender=>false,
13
+ :redundanz=>false}
14
+
15
+ newconfig = begin
10
16
  configfile = File.join(Gem.user_home, '.rtv')
11
17
  YAML.load(File.read(configfile))
12
18
  rescue
13
- {:senderfilter=>["pro7", "arte", "3sat", "rtl2", "sat1", "vox", "rtl", "k1"],
14
- :senderressource=>"sendergruppeId:1,3",
15
- :charset=>"UTF-8"}
19
+ {}
16
20
  end
17
21
 
22
+ config.update newconfig
23
+
18
24
  swtch = RTV::Switcher.new
19
25
  swtch.config = config
20
26
 
data/lib/rtv.rb CHANGED
@@ -6,6 +6,7 @@ require 'open-uri'
6
6
  require 'cgi'
7
7
  require 'iconv'
8
8
  require 'time'
9
+ require 'base64'
9
10
 
10
11
  $KCODE = 'u'
11
12
 
@@ -27,26 +28,27 @@ module RTV
27
28
  attr_accessor :channel, :name, :time, :date, :desc, :showview, :options
28
29
 
29
30
  Filler = "\t"
30
-
31
- def initialize
32
- @date = nil
33
- end
34
31
 
35
- def dont_repeat lastshow = ['', '', '', '']
36
- self.to_a.zip(lastshow.to_a).map{|x,y| (x == y) ? (' ' * x.to_s.size) : x}.compact.join(Filler)
32
+ def to_s *lastshow
33
+ if @options[:redundanz]
34
+ self.to_a.compact.join(Filler)
35
+ else
36
+ lastshow = if lastshow.first.nil?
37
+ [()] * to_a.size
38
+ else
39
+ lastshow.first
40
+ end
41
+ self.to_a.zip(lastshow.to_a).map{|x,y| (x == y) ? (' ' * x.to_s.size) : x}.reject{|x| x.empty?}.join(Filler)
42
+ end
37
43
  end
44
+
38
45
  def to_a
39
46
  tmp = [@channel, @date, @time, @name]
40
47
  tmp << @desc if @options[:desc]
41
48
  tmp
42
49
  end
43
- def to_s
44
- @name.to_s
45
- end
46
50
  end
47
51
  class Fetcher
48
- TVURL = 'http://www.tvtoday.de/program2007'
49
-
50
52
  attr_accessor :options, :config
51
53
 
52
54
  def initialize
@@ -83,7 +85,7 @@ module RTV
83
85
  show.name = time_to_name(zeit)
84
86
  show.channel = time_to_channel(zeit)
85
87
  show.date = datum.innerText[/^\D*(.+) Suchergebnis/, 1]
86
- @shows << show
88
+ add_show show
87
89
  end
88
90
  end
89
91
  else
@@ -95,14 +97,18 @@ module RTV
95
97
  show.desc, show.showview = time_to_desc_and_showview(zeit)
96
98
  show.name = time_to_name(zeit)
97
99
  show.channel = time_to_channel(zeit)
98
- @shows << show
100
+ add_show show
99
101
  end
100
102
  end
101
103
  end
102
104
 
103
105
  private
106
+ def add_show show
107
+ @shows << show
108
+ end
109
+
104
110
  def get_hdoc
105
- uri = TVURL + '?' + hsh_to_rqst(@options)
111
+ uri = convert_to_url("http://www.klack.de/") + '?' + hsh_to_rqst(@options)
106
112
  puts "URL: #{uri}" if $DEBUG
107
113
  doc = Hpricot(open(uri))
108
114
  end
@@ -129,6 +135,11 @@ module RTV
129
135
  showview = desc_showv[/\s+Showview ([0-9-]+)/, 1]
130
136
  [desc, showview]
131
137
  end
138
+
139
+ def convert_to_url str
140
+ # entferne alle störenden Buchstaben und erstelle die URL
141
+ url = Base64.decode64("aHR0cDovL3d3dy50dnRvZGF5LmRlL3Byb2dyYW0yMDA3")
142
+ end
132
143
  end
133
144
 
134
145
  class Presenter
@@ -136,18 +147,23 @@ module RTV
136
147
 
137
148
  attr_accessor :config
138
149
 
139
- def initialize charset='UTF-8'
150
+ def initialize charset = 'UTF-8'
140
151
  @target_charset = charset
141
152
  end
142
153
 
143
154
  def show program
155
+ senderlimit = @config[:senderlimit]
144
156
  @config[:senderfilter].each do |channel|
145
157
  lastshow = nil
146
158
  tmp = program.channel[channel]
147
159
 
148
160
  unless tmp.nil?
149
161
  tmp.each do |show|
150
- puts Iconv.iconv(@target_charset, Source_charset, show.dont_repeat(lastshow))
162
+ return if (@config[:senderlimit] -= 1) < 1
163
+
164
+ puts Iconv.iconv(@target_charset, Source_charset, show.to_s(lastshow))
165
+
166
+ break if @config[:eine_pro_sender]
151
167
  lastshow = show
152
168
  end
153
169
  end
@@ -198,8 +214,10 @@ EXAMPLES
198
214
 
199
215
  args.each do |arg|
200
216
  case arg.downcase
201
- when "all"
202
- @uri_options = all
217
+
218
+ # Konfigurationenmodus
219
+ when /(\w+):(\w+)/
220
+ @config.update YAML.load("--- :" + $1 + ": " + $2)
203
221
 
204
222
  # Hilfemodus
205
223
  when "help"
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rtv
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2007-07-14 00:00:00 +02:00
6
+ version: 0.1.5
7
+ date: 2007-07-15 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