etvnet-seek 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGES +26 -0
  2. data/Gemfile +14 -0
  3. data/README +20 -0
  4. data/Rakefile +59 -0
  5. data/VERSION +1 -0
  6. data/bin/etvnet-seek +27 -0
  7. data/bin/etvnet-seek.bat +6 -0
  8. data/etvnet-seek.gemspec +98 -0
  9. data/lib/etvnet_seek/commander.rb +105 -0
  10. data/lib/etvnet_seek/cookie_helper.rb +107 -0
  11. data/lib/etvnet_seek/core/access_page.rb +19 -0
  12. data/lib/etvnet_seek/core/base_page.rb +43 -0
  13. data/lib/etvnet_seek/core/browse_media_item.rb +41 -0
  14. data/lib/etvnet_seek/core/catalog_item.rb +38 -0
  15. data/lib/etvnet_seek/core/catalog_page.rb +29 -0
  16. data/lib/etvnet_seek/core/channel_media_item.rb +17 -0
  17. data/lib/etvnet_seek/core/channels_page.rb +29 -0
  18. data/lib/etvnet_seek/core/group_media_item.rb +7 -0
  19. data/lib/etvnet_seek/core/group_page.rb +42 -0
  20. data/lib/etvnet_seek/core/home_page.rb +18 -0
  21. data/lib/etvnet_seek/core/login_page.rb +49 -0
  22. data/lib/etvnet_seek/core/media_info.rb +31 -0
  23. data/lib/etvnet_seek/core/media_item.rb +52 -0
  24. data/lib/etvnet_seek/core/media_page.rb +41 -0
  25. data/lib/etvnet_seek/core/new_item.rb +9 -0
  26. data/lib/etvnet_seek/core/new_items_page.rb +20 -0
  27. data/lib/etvnet_seek/core/page.rb +19 -0
  28. data/lib/etvnet_seek/core/page_factory.rb +51 -0
  29. data/lib/etvnet_seek/core/search_page.rb +42 -0
  30. data/lib/etvnet_seek/core/service_call.rb +32 -0
  31. data/lib/etvnet_seek/easy_auth.rb +52 -0
  32. data/lib/etvnet_seek/etvnet_seek.rb +10 -0
  33. data/lib/etvnet_seek/link_info.rb +37 -0
  34. data/lib/etvnet_seek/main.rb +180 -0
  35. data/lib/etvnet_seek/user_selection.rb +26 -0
  36. data/lib/media_converter.rb +85 -0
  37. data/lib/progressbar.rb +237 -0
  38. data/lib/runglish.rb +131 -0
  39. data/spec/etvnet_seek_spec.rb +28 -0
  40. metadata +200 -0
@@ -0,0 +1,26 @@
1
+ class UserSelection
2
+ attr_reader :index
3
+
4
+ def parse text
5
+ @blank = text.strip.size == 0
6
+
7
+ result = text.split
8
+
9
+ @index = result[0].to_i-1
10
+ @quit = (result & ['q', 'Q']).empty? ? false : true
11
+ @catalog = (result & ['c', 'C']).empty? ? false : true
12
+ end
13
+
14
+ def quit?
15
+ @quit
16
+ end
17
+
18
+ def blank?
19
+ @blank
20
+ end
21
+
22
+ def catalog?
23
+ @catalog
24
+ end
25
+
26
+ end
@@ -0,0 +1,85 @@
1
+ require 'progressbar'
2
+
3
+ class MediaConverter
4
+
5
+ def genertate_mp3 input_file, output_file
6
+ command = "ffmpeg -y -i #{input_file} -vn -ar 44100 -ac 2 -ab 192 -f mp3 #{output_file} 2>&1"
7
+
8
+ execute("ffmpeg", command)
9
+ end
10
+
11
+ def generate_flv input_file, output_file
12
+ command = "ffmpeg -i #{input_file} -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv #{output_file} 2>&1"
13
+
14
+ execute("ffmpeg", command)
15
+ end
16
+
17
+ def dump_mms_stream url, name
18
+ command = "-dumpstream -dumpfile #{name}.wma #{url} 2>&1"
19
+
20
+ execute("mplayer", command)
21
+ end
22
+
23
+ def extract_wav name
24
+ command = "-vo null -vc dummy -ao pcm:file=#{name}.wav #{name}.wma"
25
+
26
+ execute("mplayer", command)
27
+ end
28
+
29
+ def convert_wav_to_mp3 name
30
+ command = "-ab 128 -i #{name}.wav #{name}.mp3"
31
+
32
+ execute("ffmpeg", command)
33
+ end
34
+
35
+ protected
36
+
37
+ def execute(tool, command)
38
+ progress_bar = ProgressBar.new("media converter", 100)
39
+
40
+ IO.popen("#{tool} #{command}") do |pipe|
41
+ duration = 0
42
+
43
+ pipe.each("\r") do |line|
44
+ p line
45
+
46
+ duration = next_position(duration, line) do |position|
47
+ progress_bar.set(position) if progress_bar.current != position
48
+ end
49
+ end
50
+ end
51
+
52
+ progress_bar.finish
53
+ end
54
+
55
+ def next_position duration, line
56
+ if line =~ /Duration: (\d{2}):(\d{2}):(\d{2}).(\d{1})/
57
+ duration = (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) * 10 + $4.to_i
58
+ end
59
+
60
+ if line =~ /time=(\d+).(\d+)/
61
+ if duration != 0
62
+ pos = ($1.to_i * 10 + $2.to_i) * 100 / duration
63
+ else
64
+ pos = 0
65
+ end
66
+
67
+ pos = 100 if pos > 100
68
+
69
+ yield(pos)
70
+ end
71
+
72
+ duration
73
+ end
74
+ end
75
+
76
+ converter = MediaConverter.new
77
+
78
+ #converter.genertate_mp3 "../stream.wmv", "stream.mp3"
79
+
80
+ #converter.dump_mms_stream "mms://208.100.43.199/MTVL_S0016/stream.wmv?t=PHJvb3QgYT0iaXRiXzQ4ZmIwNzZkNzY2OTVkNmE2MjI1OWQwMTZhMGFhZjFmIiBiPSIyNzczNyIgYz0iNzEuMjI1LjQ3LjQ2IiBkPSIxMzcwMjQiIGU9IjYwMCIgZj0iRzpcMDAwXDEzN1wwMjRcNjAwLndtdiIgZz0iNjAwIiBoPSItMSIgaT0iMSIgaj0iMCIgaz0iaHR0cDovLzE3NC4xNDIuMTg1LjgwL3N0YXQvd21zX3N0YXRpc3RpY3MuYXNteCIgbD0ibWF0dmlsXzUyNTMxYjRhMDEwYTM0ZDI3YzBjOWUzMjgxM2JjNzI0IiBtPSItMSIgLz4%3d", "test"
81
+
82
+ #converter.extract_wav("test")
83
+ #
84
+ converter.convert_wav_to_mp3("test")
85
+
@@ -0,0 +1,237 @@
1
+ #
2
+ # Ruby/ProgressBar - a text progress bar library
3
+ #
4
+ # Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
5
+ # All rights reserved.
6
+ # This is free software with ABSOLUTELY NO WARRANTY.
7
+ #
8
+ # You can redistribute it and/or modify it under the terms
9
+ # of Ruby's license.
10
+ #
11
+
12
+ class ProgressBar
13
+ VERSION = "0.9"
14
+
15
+ def initialize (title, total, out = STDERR)
16
+ @title = title
17
+ @total = total
18
+ @out = out
19
+ @terminal_width = 80
20
+ @bar_mark = "o"
21
+ @current = 0
22
+ @previous = 0
23
+ @finished_p = false
24
+ @start_time = Time.now
25
+ @previous_time = @start_time
26
+ @title_width = 14
27
+ @format = "%-#{@title_width}s %3d%% %s %s"
28
+ @format_arguments = [:title, :percentage, :bar, :stat]
29
+ clear
30
+ show
31
+ end
32
+ attr_reader :title
33
+ attr_reader :current
34
+ attr_reader :total
35
+ attr_accessor :start_time
36
+ attr_writer :bar_mark
37
+
38
+ private
39
+ def fmt_bar
40
+ bar_width = do_percentage * @terminal_width / 100
41
+ sprintf("|%s%s|",
42
+ @bar_mark * bar_width,
43
+ " " * (@terminal_width - bar_width))
44
+ end
45
+
46
+ def fmt_percentage
47
+ do_percentage
48
+ end
49
+
50
+ def fmt_stat
51
+ if @finished_p then elapsed else eta end
52
+ end
53
+
54
+ def fmt_stat_for_file_transfer
55
+ if @finished_p then
56
+ sprintf("%s %s %s", bytes, transfer_rate, elapsed)
57
+ else
58
+ sprintf("%s %s %s", bytes, transfer_rate, eta)
59
+ end
60
+ end
61
+
62
+ def fmt_title
63
+ @title[0,(@title_width - 1)] + ":"
64
+ end
65
+
66
+ def convert_bytes (bytes)
67
+ if bytes < 1024
68
+ sprintf("%6dB", bytes)
69
+ elsif bytes < 1024 * 1000 # 1000kb
70
+ sprintf("%5.1fKB", bytes.to_f / 1024)
71
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
72
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
73
+ else
74
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
75
+ end
76
+ end
77
+
78
+ def transfer_rate
79
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
80
+ sprintf("%s/s", convert_bytes(bytes_per_second))
81
+ end
82
+
83
+ def bytes
84
+ convert_bytes(@current)
85
+ end
86
+
87
+ def format_time (t)
88
+ t = t.to_i
89
+ sec = t % 60
90
+ min = (t / 60) % 60
91
+ hour = t / 3600
92
+ sprintf("%02d:%02d:%02d", hour, min, sec);
93
+ end
94
+
95
+ # ETA stands for Estimated Time of Arrival.
96
+ def eta
97
+ if @current == 0
98
+ "ETA: --:--:--"
99
+ else
100
+ elapsed = Time.now - @start_time
101
+ eta = elapsed * @total / @current - elapsed;
102
+ sprintf("ETA: %s", format_time(eta))
103
+ end
104
+ end
105
+
106
+ def elapsed
107
+ elapsed = Time.now - @start_time
108
+ sprintf("Time: %s", format_time(elapsed))
109
+ end
110
+
111
+ def eol
112
+ if @finished_p then "\n" else "\r" end
113
+ end
114
+
115
+ def do_percentage
116
+ if @total.zero?
117
+ 100
118
+ else
119
+ @current * 100 / @total
120
+ end
121
+ end
122
+
123
+ def get_width
124
+ # FIXME: I don't know how portable it is.
125
+ default_width = 80
126
+ begin
127
+ tiocgwinsz = 0x5413
128
+ data = [0, 0, 0, 0].pack("SSSS")
129
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
130
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
131
+ if cols >= 0 then cols else default_width end
132
+ else
133
+ default_width
134
+ end
135
+ rescue Exception
136
+ default_width
137
+ end
138
+ end
139
+
140
+ def show
141
+ arguments = @format_arguments.map {|method|
142
+ method = sprintf("fmt_%s", method)
143
+ send(method)
144
+ }
145
+ line = sprintf(@format, *arguments)
146
+
147
+ width = get_width
148
+ if line.length == width - 1
149
+ @out.print(line + eol)
150
+ @out.flush
151
+ elsif line.length >= width
152
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
153
+ if @terminal_width == 0 then @out.print(line + eol) else show end
154
+ else # line.length < width - 1
155
+ @terminal_width += width - line.length + 1
156
+ show
157
+ end
158
+ @previous_time = Time.now
159
+ end
160
+
161
+ def show_if_needed
162
+ if @total.zero?
163
+ cur_percentage = 100
164
+ prev_percentage = 0
165
+ else
166
+ cur_percentage = (@current * 100 / @total).to_i
167
+ prev_percentage = (@previous * 100 / @total).to_i
168
+ end
169
+
170
+ # Use "!=" instead of ">" to support negative changes
171
+ if cur_percentage != prev_percentage ||
172
+ Time.now - @previous_time >= 1 || @finished_p
173
+ show
174
+ end
175
+ end
176
+
177
+ public
178
+ def clear
179
+ @out.print "\r"
180
+ @out.print(" " * (get_width - 1))
181
+ @out.print "\r"
182
+ end
183
+
184
+ def finish
185
+ @current = @total
186
+ @finished_p = true
187
+ show
188
+ end
189
+
190
+ def finished?
191
+ @finished_p
192
+ end
193
+
194
+ def file_transfer_mode
195
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
196
+ end
197
+
198
+ def format= (format)
199
+ @format = format
200
+ end
201
+
202
+ def format_arguments= (arguments)
203
+ @format_arguments = arguments
204
+ end
205
+
206
+ def halt
207
+ @finished_p = true
208
+ show
209
+ end
210
+
211
+ def inc (step = 1)
212
+ @current += step
213
+ @current = @total if @current > @total
214
+ show_if_needed
215
+ @previous = @current
216
+ end
217
+
218
+ def set (count)
219
+ if count < 0 || count > @total
220
+ raise "invalid count: #{count} (total: #{@total})"
221
+ end
222
+ @current = count
223
+ show_if_needed
224
+ @previous = @current
225
+ end
226
+
227
+ def inspect
228
+ "#<ProgressBar:#{@current}/#{@total}>"
229
+ end
230
+ end
231
+
232
+ class ReversedProgressBar < ProgressBar
233
+ def do_percentage
234
+ 100 - super
235
+ end
236
+ end
237
+
@@ -0,0 +1,131 @@
1
+ # Converts file names in directory recursively from Russian to Runglish and vice versa.
2
+ #
3
+ # Runglish stands for Russian text in Latin letters.
4
+
5
+ # -*- encoding: utf-8 -*-
6
+
7
+ $KCODE = 'u' if RUBY_VERSION < "1.9"
8
+
9
+ module Runglish
10
+
11
+ class Converter
12
+ def initialize(lower_single, lower_multi, upper_single, upper_multi)
13
+ @lower_single = lower_single
14
+ @lower_multi = lower_multi
15
+ @upper_single = upper_single
16
+ @upper_multi = upper_multi
17
+
18
+ @lower = (@lower_single.merge(@lower_multi)).freeze
19
+ @upper = (@upper_single.merge(@upper_multi)).freeze
20
+ @multi_keys = (@lower_multi.merge(@upper_multi)).keys.sort_by {|s| s.length}.reverse.freeze
21
+ end
22
+
23
+ # Transliterate a string
24
+ def transliterate(str)
25
+ chars = str.scan(%r{#{@multi_keys.join '|'}|\w|.})
26
+
27
+ result = ""
28
+
29
+ chars.each_with_index do |char, index|
30
+ if @upper.has_key?(char) && @lower.has_key?(chars[index+1]) # combined case
31
+ result << @upper[char].downcase.capitalize
32
+ elsif @upper.has_key?(char)
33
+ result << @upper[char]
34
+ elsif @lower.has_key?(char)
35
+ result << @lower[char]
36
+ else
37
+ result << char
38
+ end
39
+ end
40
+
41
+ result
42
+ end
43
+ end
44
+
45
+ class RusToLatConverter < Converter
46
+ def initialize
47
+ lower_single = {
48
+ "і"=>"i", "ґ"=>"g", "ё"=>"yo", "№"=>"#", "є"=>"e", "ї"=>"yi",
49
+ "а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ж"=>"zh",
50
+ "з"=>"z", "и"=>"i", "й"=>"y", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r",
51
+ "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"h", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch",
52
+ "ъ"=>"'", "ы"=>"y", "ь"=>"", "э"=>"e", "ю"=>"yu", "я"=>"ya"
53
+ }
54
+
55
+ lower_multi = {
56
+ "ье"=>"ie",
57
+ "ьё"=>"ie"
58
+ }
59
+
60
+ upper_single = {
61
+ "Ґ"=>"G", "Ё"=>"YO", "Є"=>"E", "Ї"=>"YI", "І"=>"I",
62
+ "А"=>"A", "Б"=>"B", "В"=>"V", "Г"=>"G", "Д"=>"D", "Е"=>"E", "Ж"=>"ZH",
63
+ "З"=>"Z", "И"=>"I", "Й"=>"Y", "К"=>"K", "Л"=>"L", "М"=>"M", "Н"=>"N", "О"=>"O", "П"=>"P", "Р"=>"R",
64
+ "С"=>"S", "Т"=>"T", "У"=>"U", "Ф"=>"F", "Х"=>"H", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", "Щ"=>"SCH",
65
+ "Ъ"=>"'", "Ы"=>"Y", "Ь"=>"", "Э"=>"E", "Ю"=>"YU", "Я"=>"YA"
66
+ }
67
+
68
+ upper_multi = {
69
+ "ЬЕ"=>"IE",
70
+ "ЬЁ"=>"IE"
71
+ }
72
+
73
+ super(lower_single, lower_multi, upper_single, upper_multi)
74
+ end
75
+ end
76
+
77
+ class LatToRusConverter < Converter
78
+ def initialize
79
+ lower_single = {
80
+ "i"=>"і", "g"=>"ґ", "#"=>"№", "e"=>"є",
81
+ "a"=>"а", "b"=>"б", "v"=>"в", "g"=>"г", "d"=>"д", "e"=>"е", "z"=>"з", "i"=>"и",
82
+ "k"=>"к", "l"=>"л", "m"=>"м", "n"=>"н", "o"=>"о", "p"=>"п", "r"=>"р", "s"=>"с", "t"=>"т",
83
+ "u"=>"у", "f"=>"ф", "h"=>"х", "y"=>"ъ", "y"=>"ы",
84
+ "c"=>"к", "w"=> "в"
85
+ }
86
+
87
+ lower_multi = {
88
+ "yo"=>"ё",
89
+ "yi"=>"ї",
90
+ "ii"=>"й",
91
+ "zh"=>"ж",
92
+ "ts"=>"ц",
93
+ "ch"=>"ч",
94
+ "sh"=>"ш",
95
+ "sch"=>"щ",
96
+ "ye"=>"э",
97
+ "yu"=>"ю",
98
+ "ya"=>"я",
99
+ "ie"=>"ье"
100
+ }
101
+
102
+ upper_single = {
103
+ "G"=>"Ґ", "Є"=>"E", "I"=>"І",
104
+ "A"=>"А", "B"=>"Б", "V"=>"В", "G"=>"Г", "D"=>"Д", "E"=>"Е", "Z"=>"З", "I"=>"И",
105
+ "K"=>"К", "L"=>"Л", "M"=>"М", "N"=>"Н", "O"=>"О", "P"=>"П", "R"=>"Р",
106
+ "S"=>"С", "T"=>"Т", "U"=>"У", "F"=>"Ф", "H"=>"Х", "'"=>"Ъ", "Y"=>"Ы",
107
+ "C"=>"К", "W"=> "В"
108
+ }
109
+
110
+ upper_multi = {
111
+ "YO"=>"Ё",
112
+ "YI"=>"Ї",
113
+ "II"=>"Й",
114
+ "ZH"=>"Ж",
115
+ "TS"=>"Ц",
116
+ "CH"=>"Ч",
117
+ "SH"=>"Ш",
118
+ "SCH"=>"Щ",
119
+ "YE"=>"Э",
120
+ "YU"=>"Ю",
121
+ "YA"=>"Я",
122
+ "IE"=>"ЬЕ"
123
+ }
124
+
125
+ super(lower_single, lower_multi, upper_single, upper_multi)
126
+ end
127
+ end
128
+
129
+ end
130
+
131
+