etvnet_seek 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/runglish.rb CHANGED
@@ -1,133 +1,131 @@
1
- # Converts file names in directory recursively from Russian to Runglish.
1
+ # Converts file names in directory recursively from Russian to Runglish and vice versa.
2
2
  #
3
3
  # Runglish stands for Russian text in Latin letters.
4
4
 
5
5
  # -*- encoding: utf-8 -*-
6
6
 
7
- if RUBY_VERSION < "1.9"
8
- $KCODE = 'u'
9
- end
7
+ $KCODE = 'u' if RUBY_VERSION < "1.9"
10
8
 
11
- class Runglish
12
-
13
- LOWER_SINGLE = {
14
- "і"=>"i", "ґ"=>"g", "ё"=>"yo", "№"=>"#", "є"=>"e", "ї"=>"yi",
15
- "а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ж"=>"zh",
16
- "з"=>"z", "и"=>"i", "й"=>"y", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r",
17
- "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"h", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch",
18
- "ъ"=>"'", "ы"=>"y", "ь"=>"", "э"=>"e", "ю"=>"yu", "я"=>"ya",
19
- }
20
-
21
- LOWER_MULTI = {
22
- "ье"=>"ie",
23
- "ьё"=>"ie",
24
- }
25
-
26
- UPPER_SINGLE = {
27
- "Ґ"=>"G", "Ё"=>"YO", "Є"=>"E", "Ї"=>"YI", "І"=>"I",
28
- "А"=>"A", "Б"=>"B", "В"=>"V", "Г"=>"G", "Д"=>"D", "Е"=>"E", "Ж"=>"ZH",
29
- "З"=>"Z", "И"=>"I", "Й"=>"Y", "К"=>"K", "Л"=>"L", "М"=>"M", "Н"=>"N", "О"=>"O", "П"=>"P", "Р"=>"R",
30
- "С"=>"S", "Т"=>"T", "У"=>"U", "Ф"=>"F", "Х"=>"H", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", "Щ"=>"SCH",
31
- "Ъ"=>"'", "Ы"=>"Y", "Ь"=>"", "Э"=>"E", "Ю"=>"YU", "Я"=>"YA",
32
- }
33
-
34
- UPPER_MULTI = {
35
- "ЬЕ"=>"IE",
36
- "ЬЁ"=>"IE",
37
- }
38
-
39
- LOWER = (LOWER_SINGLE.merge(LOWER_MULTI)).freeze
40
- UPPER = (UPPER_SINGLE.merge(UPPER_MULTI)).freeze
41
- MULTI_KEYS = (LOWER_MULTI.merge(UPPER_MULTI)).keys.sort_by {|s| s.length}.reverse.freeze
42
-
43
-
44
- LOWER_SINGLE_2 = {
45
- "i"=>"і", "g"=>"ґ", "#"=>"№", "e"=>"є",
46
- "a"=>"а", "b"=>"б", "v"=>"в", "g"=>"г", "d"=>"д", "e"=>"е", "z"=>"з", "i"=>"и", "y"=>"й",
47
- "k"=>"к", "l"=>"л", "m"=>"м", "n"=>"н", "o"=>"о", "p"=>"п", "r"=>"р", "s"=>"с", "t"=>"т",
48
- "u"=>"у", "f"=>"ф", "h"=>"х", "'"=>"ъ", "y"=>"ы", "e"=>"э"
49
- }
50
- LOWER_MULTI_2 = {
51
- "yo"=>"ё",
52
- "yi"=>"ї",
53
- "zh"=>"ж",
54
- "ts"=>"ц",
55
- "ch"=>"ч",
56
- "sh"=>"ш",
57
- "sch"=>"щ",
58
- "yu"=>"ю",
59
- "ya"=>"я",
60
- "ie"=>"ье"
61
- }
62
-
63
- UPPER_SINGLE_2 = {
64
- "G"=>"Ґ", "Є"=>"E", "I"=>"І",
65
- "A"=>"А", "B"=>"Б", "V"=>"В", "G"=>"Г", "D"=>"Д", "E"=>"Е", "Z"=>"З", "I"=>"И",
66
- "Y"=>"Й", "K"=>"К", "L"=>"Л", "M"=>"М", "N"=>"Н", "O"=>"О", "P"=>"П", "R"=>"Р",
67
- "S"=>"С", "T"=>"Т", "U"=>"У", "F"=>"Ф", "H"=>"Х", "'"=>"Ъ", "Y"=>"Ы", "E"=>"Э"
68
- }
69
-
70
- UPPER_MULTI_2 = {
71
- "YO"=>"Ё",
72
- "YI"=>"Ї",
73
- "ZH"=>"Ж",
74
- "TS"=>"Ц",
75
- "CH"=>"Ч",
76
- "SH"=>"Ш",
77
- "SCH"=>"Щ",
78
- "YU"=>"Ю",
79
- "YA"=>"Я",
80
- "IE"=>"ЬЕ"
81
- }
82
-
83
- LOWER_2 = (LOWER_SINGLE_2.merge(LOWER_MULTI_2)).freeze
84
- UPPER_2 = (UPPER_SINGLE_2.merge(UPPER_MULTI_2)).freeze
85
- MULTI_KEYS_2 = (LOWER_MULTI_2.merge(UPPER_MULTI_2)).keys.sort_by {|s| s.length}.reverse.freeze
86
-
87
- # Transliterate a string with russian characters
88
- #
89
- # Возвращает строку, в которой все буквы русского алфавита заменены на похожую по звучанию латиницу
90
- def ru_to_lat(str)
91
- chars = str.scan(%r{#{MULTI_KEYS.join '|'}|\w|.})
92
-
93
- result = ""
94
-
95
- chars.each_with_index do |char, index|
96
- if UPPER.has_key?(char) && LOWER.has_key?(chars[index+1])
97
- # combined case
98
- result << UPPER[char].downcase.capitalize
99
- elsif UPPER.has_key?(char)
100
- result << UPPER[char]
101
- elsif LOWER.has_key?(char)
102
- result << LOWER[char]
103
- else
104
- result << char
105
- end
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
106
21
  end
107
22
 
108
- result
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
109
43
  end
110
44
 
111
- def lat_to_ru(str)
112
- chars = str.scan(%r{#{MULTI_KEYS_2.join '|'}|\w|.})
113
-
114
- result = ""
115
-
116
- chars.each_with_index do |char, index|
117
- if UPPER_2.has_key?(char) && LOWER_2.has_key?(chars[index+1])
118
- # combined case
119
- result << UPPER_2[char].downcase.capitalize
120
- elsif UPPER_2.has_key?(char)
121
- result << UPPER_2[char]
122
- elsif LOWER_2.has_key?(char)
123
- result << LOWER_2[char]
124
- else
125
- result << char
126
- end
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)
127
74
  end
75
+ end
128
76
 
129
- result
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
130
127
  end
128
+
131
129
  end
132
130
 
133
131
 
@@ -1,34 +1,28 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
2
2
 
3
3
  require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
4
4
 
5
- #require 'spec'
6
-
7
- require 'main'
8
- require 'url_seeker'
5
+ require 'etvnet/url_seeker'
9
6
  require 'runglish'
10
7
 
11
8
  describe UrlSeeker do
12
9
 
13
10
  before :each do
14
- @client = UrlSeeker.new
11
+ @client = Main.new
15
12
  end
16
13
 
17
14
  it "should return search menu items" do
18
15
  keywords = "красная шапочка"
19
16
 
20
- #@client.search(keywords).size.should > 0
21
-
22
- items = @client.search(Main.search_url(keywords))
23
- @client.display_results items
17
+ items = @client.seek(keywords)
18
+ @client.display_items items
24
19
  end
25
20
 
26
21
  end
27
22
 
28
23
  describe Runglish do
29
24
  it "should return translation" do
30
- #Runglish.new.translate("kak dela?").size.should > 0
31
- p Runglish.new.ru_to_lat("как дела?")
32
- p Runglish.new.lat_to_ru("krasnaya shapochka")
25
+ Runglish::RusToLatConverter.new.transliterate("как дела?").should == "kak dela?"
26
+ Runglish::LatToRusConverter.new.transliterate("krasnaya shapochka").should == "красная шапочка"
33
27
  end
34
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etvnet_seek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.5.1
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: libxml-ruby
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.3
44
+ version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: nokogiri
37
47
  type: :runtime
@@ -40,7 +50,7 @@ dependencies:
40
50
  requirements:
41
51
  - - ">="
42
52
  - !ruby/object:Gem::Version
43
- version: 1.3.3
53
+ version: 1.4.1
44
54
  version:
45
55
  - !ruby/object:Gem::Dependency
46
56
  name: rspec
@@ -50,7 +60,7 @@ dependencies:
50
60
  requirements:
51
61
  - - ">="
52
62
  - !ruby/object:Gem::Version
53
- version: 1.2.8
63
+ version: 1.2.9
54
64
  version:
55
65
  - !ruby/object:Gem::Dependency
56
66
  name: mocha
@@ -62,6 +72,46 @@ dependencies:
62
72
  - !ruby/object:Gem::Version
63
73
  version: 0.9.7
64
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: metric_fu
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: reek
87
+ type: :development
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ - !ruby/object:Gem::Dependency
96
+ name: roodi
97
+ type: :development
98
+ version_requirement:
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ - !ruby/object:Gem::Dependency
106
+ name: googlecharts
107
+ type: :development
108
+ version_requirement:
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
65
115
  description: Command line tool for getting mms urls from etvnet service.
66
116
  email: alexander.shvets@gmail.com
67
117
  executables:
@@ -73,10 +123,30 @@ extra_rdoc_files: []
73
123
  files:
74
124
  - bin/etvnet_seek
75
125
  - bin/etvnet_seek.bat
76
- - lib/cookie_helper.rb
77
- - lib/main.rb
126
+ - lib/etvnet_seek/commander.rb
127
+ - lib/etvnet_seek/cookie_helper.rb
128
+ - lib/etvnet_seek/core/access_page.rb
129
+ - lib/etvnet_seek/core/announces_page.rb
130
+ - lib/etvnet_seek/core/base_page.rb
131
+ - lib/etvnet_seek/core/browse_media_item.rb
132
+ - lib/etvnet_seek/core/channel_media_item.rb
133
+ - lib/etvnet_seek/core/channels_page.rb
134
+ - lib/etvnet_seek/core/freetv_page.rb
135
+ - lib/etvnet_seek/core/group_media_item.rb
136
+ - lib/etvnet_seek/core/group_page.rb
137
+ - lib/etvnet_seek/core/login_page.rb
138
+ - lib/etvnet_seek/core/main_page.rb
139
+ - lib/etvnet_seek/core/media_info.rb
140
+ - lib/etvnet_seek/core/media_item.rb
141
+ - lib/etvnet_seek/core/media_page.rb
142
+ - lib/etvnet_seek/core/page.rb
143
+ - lib/etvnet_seek/core/page_factory.rb
144
+ - lib/etvnet_seek/core/search_page.rb
145
+ - lib/etvnet_seek/core/service_call.rb
146
+ - lib/etvnet_seek/link_info.rb
147
+ - lib/etvnet_seek/main.rb
148
+ - lib/etvnet_seek/user_selection.rb
78
149
  - lib/runglish.rb
79
- - lib/url_seeker.rb
80
150
  - spec/etvnet_seek_spec.rb
81
151
  - spec/spec.opts
82
152
  - CHANGES
data/lib/main.rb DELETED
@@ -1,95 +0,0 @@
1
- require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
2
-
3
- #require "readline"
4
- require "highline/import"
5
-
6
- require 'cookie_helper'
7
- require 'url_seeker'
8
- require 'runglish'
9
-
10
- class Main
11
- include CookieHelper
12
-
13
- BASE_URL = "http://www.etvnet.ca"
14
- SEARCH_URL = BASE_URL + "/cgi-bin/video/eitv_browse.fcgi?action=search"
15
- ACCESS_URL = BASE_URL + "/cgi-bin/video/access.fcgi"
16
- LOGIN_URL = BASE_URL + "/cgi-bin/video/login.fcgi"
17
-
18
- attr_reader :cookie
19
-
20
- def initialize
21
- @cookie = get_cookie
22
- end
23
-
24
- def self.search_url keywords, order_direction='-'
25
- SEARCH_URL + "&keywords=#{CGI.escape(keywords)}&order_direction=#{order_direction}"
26
- end
27
-
28
- def search_and_grab_link keywords
29
- if(keywords.strip.size == 0)
30
- while keywords.strip.size == 0
31
- keywords = ask("Keywords: ")
32
- end
33
- end
34
-
35
- url_seeker = UrlSeeker.new
36
-
37
- items = url_seeker.search Main.search_url(keywords)
38
-
39
- if items.size == 0
40
- say "Empty search result."
41
- link = nil
42
- else
43
- url_seeker.display_results items
44
-
45
- title_number = ask("Select title number: ")
46
- while not title_number =~ /(\d+)(\.?)(\d*)/
47
- title_number = ask("Select title number: ")
48
- end
49
-
50
- dot_index = title_number.index('.')
51
-
52
- if not dot_index.nil?
53
- pos1 = title_number[0..dot_index-1].to_i
54
- pos2 = title_number[dot_index+1..-1].to_i
55
-
56
- link = url_seeker.grab_movie_link items[pos1-1][:container][pos2-1][:link], cookie, ACCESS_URL
57
- else
58
- link = url_seeker.grab_movie_link items[title_number.to_i-1][:link], cookie, ACCESS_URL
59
- end
60
- end
61
-
62
- link
63
- end
64
-
65
- private
66
-
67
- def get_cookie
68
- file_name = ENV['HOME'] + "/.etvnet-seek"
69
-
70
- if File.exist? file_name
71
- cookie = read_user_file file_name
72
- else
73
- username = ask("Enter username : " )
74
- password = ask("Enter password : " ) { |q| q.echo = '*' }
75
-
76
- cookie = retrieve_cookie LOGIN_URL, username, password
77
-
78
- write_user_file file_name, cookie
79
- end
80
-
81
- cookie
82
- end
83
-
84
- def read_user_file file_name
85
- File.open(file_name, 'r') do |file|
86
- return file.gets
87
- end
88
- end
89
-
90
- def write_user_file file_name, cookie
91
- File.open(file_name, 'w') do |file|
92
- file.puts cookie
93
- end
94
- end
95
- end
data/lib/url_seeker.rb DELETED
@@ -1,97 +0,0 @@
1
- require 'nokogiri'
2
- require 'open-uri'
3
- require 'cgi'
4
- require 'json'
5
-
6
- class UrlSeeker
7
-
8
- def search url
9
- doc = Nokogiri::HTML(open(url))
10
-
11
- list = []
12
-
13
- doc.css("table tr[2] td table").each do |item|
14
- links = item.css(".media_file")
15
-
16
- links.each_with_index do |link, index|
17
- if index % 2 != 0
18
- href = link.attributes['href'].value
19
-
20
- new_link = list.select {|l| l[:link] == href}.empty?
21
-
22
- if new_link
23
- record = {:link => href,
24
- :name => link.content.strip,
25
- # :first_time => link.parent.parent.previous.previous.previous.previous.content.strip,
26
- # :year => link.parent.parent.next.next.content.strip,
27
- # :how_long => link.parent.parent.next.next.next.next.content.strip
28
- }
29
-
30
- if href =~ /action=browse_container/
31
- record[:container] = search(href)
32
- else
33
- result = href.match(/(\w*)\/(\w*)\/(\w*)\/([\w|-]*)/)
34
-
35
- record[:media_file] = (result.size > 2) ? result[3] : ""
36
- record[:english_name] = (result.size > 3) ? result[4] : ""
37
- end
38
-
39
- list << record
40
- end
41
- end
42
- end
43
- end
44
-
45
- list
46
- end
47
-
48
- def display_results items
49
- items.each_with_index do |item1, index1|
50
-
51
- if item1[:container].nil?
52
- puts "#{index1+1}. #{item1[:english_name]} --- #{item1[:media_file]} --- #{item1[:name]}"
53
- else
54
- puts "#{index1+1}. #{item1[:name]}"
55
-
56
- item1[:container].each_with_index do |item2, index2|
57
- puts " #{index1+1}.#{index2+1}. #{item2[:english_name]} --- #{item2[:media_file]} --- #{item2[:name]}"
58
- end
59
- end
60
- end
61
- end
62
-
63
- def grab_movie_link link, cookie, url
64
- result = link.match(/(\w*)\/(\w*)\/(\w*)\/([\w|-]*)/)
65
-
66
- media_file = (not result.nil? and result.size > 2) ? result[3] : ""
67
-
68
- media_info = request_media_info media_file, cookie, url
69
-
70
- mms_link(media_info)
71
- end
72
-
73
- private
74
-
75
- def request_media_info media_file, cookie, url
76
- url = URI.parse(url)
77
- conn = Net::HTTP.new(url.host, url.port)
78
-
79
- headers = { 'Cookie' => cookie }
80
-
81
- request = Net::HTTP::Post.new(url.request_uri, headers)
82
-
83
- request.set_form_data(
84
- { 'action' => 'start_video', 'bitrate' => '600',
85
- 'media_file'=> media_file, 'replay' => '1', 'skin' => 'JSON'
86
- }
87
- )
88
-
89
- response = conn.request(request)
90
-
91
- response.body
92
- end
93
-
94
- def mms_link media_info
95
- JSON.parse(media_info)["PARAMETERS"]["REDIRECT_URL"]
96
- end
97
- end