etvnet_seek 0.1.0 → 0.2.0
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/CHANGES +4 -0
- data/bin/etvnet_seek +13 -17
- data/etvnet_seek.gemspec +1 -1
- data/lib/cookie_helper.rb +1 -1
- data/lib/main.rb +94 -0
- data/lib/runglish.rb +44 -0
- data/lib/{etvnet_seek.rb → url_seeker.rb} +8 -57
- data/spec/etvnet_seek_spec.rb +16 -6
- metadata +4 -2
data/CHANGES
CHANGED
data/bin/etvnet_seek
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
2
3
|
|
|
3
4
|
require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
|
|
4
5
|
|
|
5
6
|
$:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
$KCODE='u'
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
require 'main'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
client = Main.new
|
|
12
13
|
|
|
13
|
-
client.
|
|
14
|
+
movie_link = client.search_and_grab_link ARGV.join(' ')
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
if movie_link
|
|
17
|
+
puts "Link: #{movie_link}"
|
|
18
|
+
|
|
19
|
+
if RUBY_PLATFORM =~ /(win|w)32$/
|
|
20
|
+
`wmplayer #{movie_link}`
|
|
21
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
|
22
|
+
`open #{movie_link}`
|
|
23
|
+
end
|
|
16
24
|
|
|
17
|
-
dot_index = title_number.index('.')
|
|
18
|
-
|
|
19
|
-
if not dot_index.nil?
|
|
20
|
-
pos1 = title_number[0..dot_index-1].to_i
|
|
21
|
-
pos2 = title_number[dot_index+1..-1].to_i
|
|
22
|
-
|
|
23
|
-
movie_link = client.grab_movie_link items[pos1-1][:container][pos2-1][:link]
|
|
24
|
-
else
|
|
25
|
-
movie_link = client.grab_movie_link items[title_number.to_i-1][:link]
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
puts "Link: #{movie_link}"
|
|
29
|
-
|
|
30
|
-
`open #{movie_link}`
|
data/etvnet_seek.gemspec
CHANGED
data/lib/cookie_helper.rb
CHANGED
|
@@ -7,7 +7,7 @@ module CookieHelper
|
|
|
7
7
|
conn = Net::HTTP.new(uri.host, uri.port)
|
|
8
8
|
|
|
9
9
|
headers = { "Content-Type" => "application/x-www-form-urlencoded" }
|
|
10
|
-
resp, data = conn.post(
|
|
10
|
+
resp, data = conn.post(uri.path,
|
|
11
11
|
"action=login&username=#{username}&pwd=#{password}&skip_notice=&redirect=", headers)
|
|
12
12
|
|
|
13
13
|
cookie = resp.response['set-cookie']
|
data/lib/main.rb
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
|
|
9
|
+
class Main
|
|
10
|
+
include CookieHelper
|
|
11
|
+
|
|
12
|
+
BASE_URL = "http://www.etvnet.ca"
|
|
13
|
+
SEARCH_URL = BASE_URL + "/cgi-bin/video/eitv_browse.fcgi?action=search"
|
|
14
|
+
ACCESS_URL = BASE_URL + "/cgi-bin/video/access.fcgi"
|
|
15
|
+
LOGIN_URL = BASE_URL + "/cgi-bin/video/login.fcgi"
|
|
16
|
+
|
|
17
|
+
attr_reader :cookie
|
|
18
|
+
|
|
19
|
+
def initialize
|
|
20
|
+
@cookie = get_cookie
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.search_url keywords, order_direction='-'
|
|
24
|
+
SEARCH_URL + "&keywords=#{CGI.escape(keywords)}&order_direction=#{order_direction}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def search_and_grab_link keywords
|
|
28
|
+
if(keywords.strip.size == 0)
|
|
29
|
+
while keywords.strip.size == 0
|
|
30
|
+
keywords = ask("Keywords: ")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
url_seeker = UrlSeeker.new
|
|
35
|
+
|
|
36
|
+
items = url_seeker.search Main.search_url(keywords)
|
|
37
|
+
|
|
38
|
+
if items.size == 0
|
|
39
|
+
say "Empty search result."
|
|
40
|
+
link = nil
|
|
41
|
+
else
|
|
42
|
+
url_seeker.display_results items
|
|
43
|
+
|
|
44
|
+
title_number = ask("Select title number: ")
|
|
45
|
+
while not title_number =~ /(\d+)(\.?)(\d*)/
|
|
46
|
+
title_number = ask("Select title number: ")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
dot_index = title_number.index('.')
|
|
50
|
+
|
|
51
|
+
if not dot_index.nil?
|
|
52
|
+
pos1 = title_number[0..dot_index-1].to_i
|
|
53
|
+
pos2 = title_number[dot_index+1..-1].to_i
|
|
54
|
+
|
|
55
|
+
link = url_seeker.grab_movie_link items[pos1-1][:container][pos2-1][:link], cookie, ACCESS_URL
|
|
56
|
+
else
|
|
57
|
+
link = url_seeker.grab_movie_link items[title_number.to_i-1][:link], cookie, ACCESS_URL
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
link
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def get_cookie
|
|
67
|
+
file_name = ENV['HOME'] + "/.etvnet-seek"
|
|
68
|
+
|
|
69
|
+
if File.exist? file_name
|
|
70
|
+
cookie = read_user_file file_name
|
|
71
|
+
else
|
|
72
|
+
username = ask("Enter username : " )
|
|
73
|
+
password = ask("Enter password : " ) { |q| q.echo = '*' }
|
|
74
|
+
|
|
75
|
+
cookie = retrieve_cookie LOGIN_URL, username, password
|
|
76
|
+
|
|
77
|
+
write_user_file file_name, cookie
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
cookie
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def read_user_file file_name
|
|
84
|
+
File.open(file_name, 'r') do |file|
|
|
85
|
+
return file.gets
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def write_user_file file_name, cookie
|
|
90
|
+
File.open(file_name, 'w') do |file|
|
|
91
|
+
file.puts cookie
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/lib/runglish.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Converts file names in directory recursively from Russian to Runglish.
|
|
2
|
+
#
|
|
3
|
+
# Runglish stands for Russian text in Latin letters.
|
|
4
|
+
|
|
5
|
+
class Runglish
|
|
6
|
+
RUSSIAN_TABLE = [
|
|
7
|
+
'\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0436', '\u0437',
|
|
8
|
+
'\u0438', '\u0439', '\u043a', '\u043b', '\u043c', '\u043d', '\u043e', '\u043f',
|
|
9
|
+
'\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447',
|
|
10
|
+
'\u0448', '\u0449', '\u044a', '\u044b', '\u044c', '\u044d', '\u044e', '\u044f',
|
|
11
|
+
'\u0451',
|
|
12
|
+
'\u0401',
|
|
13
|
+
'\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', '\u0417',
|
|
14
|
+
'\u0418', '\u0419', '\u041a', '\u041b', '\u041c', '\u041d', '\u041e', '\u041f',
|
|
15
|
+
'\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427',
|
|
16
|
+
'\u0428', '\u0429', '\u042a', '\u042b', '\u042c', '\u042d', '\u042e', '\u042f'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
ENGLISH_TABLE = [
|
|
21
|
+
"a", "b", "v", "g", "d", "e", "zh", "z", "i", "y", "k", "l", "m", "n", "o", "p", "r",
|
|
22
|
+
"s", "t", "u", "f", "h", "c", "ch", "sh", "s'h", "''", "yi", "'", "ye", "yu", "ya",
|
|
23
|
+
"yo",
|
|
24
|
+
"YO",
|
|
25
|
+
"A", "B", "V", "G", "D", "E", "Zh", "Z", "I", "Y", "K", "L", "M", "N", "O", "P", "R",
|
|
26
|
+
"S", "T", "U", "F", "H", "C", "Ch", "Sh", "S'h", "''", "Yi", "'", "Ye", "Yu", "Ya"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
ENGLISH_RUSSIAN_MAP = Hash[*ENGLISH_TABLE.zip(RUSSIAN_TABLE).flatten]
|
|
30
|
+
|
|
31
|
+
def translate(old_text)
|
|
32
|
+
new_text = ""
|
|
33
|
+
|
|
34
|
+
old_text.each_char do |ch|
|
|
35
|
+
new_ch = ENGLISH_RUSSIAN_MAP[ch].nil? ? ch : ENGLISH_RUSSIAN_MAP[ch]
|
|
36
|
+
|
|
37
|
+
new_text += new_ch
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
new_text
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
|
|
2
|
-
|
|
3
1
|
require 'nokogiri'
|
|
4
2
|
require 'open-uri'
|
|
5
|
-
#require "readline"
|
|
6
|
-
require "highline/import"
|
|
7
3
|
require 'cgi'
|
|
8
4
|
require 'json'
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class EtvnetSeek
|
|
13
|
-
include CookieHelper
|
|
14
|
-
|
|
15
|
-
BASE_URL = "http://www.etvnet.ca"
|
|
16
|
-
SEARCH_URL = BASE_URL + "/cgi-bin/video/eitv_browse.fcgi?action=search"
|
|
17
|
-
ACCESS_URL = BASE_URL + "/cgi-bin/video/access.fcgi"
|
|
18
|
-
LOGIN_URL = BASE_URL + "/cgi-bin/video/login.fcgi"
|
|
19
|
-
|
|
20
|
-
def cookie
|
|
21
|
-
@cookie ||= get_cookie
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def search keywords, order_direction = '-'
|
|
25
|
-
search_items SEARCH_URL + "&keywords=#{CGI.escape(keywords)}&order_direction=#{order_direction}"
|
|
26
|
-
end
|
|
6
|
+
class UrlSeeker
|
|
27
7
|
|
|
28
|
-
def
|
|
8
|
+
def search url
|
|
29
9
|
doc = Nokogiri::HTML(open(url))
|
|
30
10
|
|
|
31
11
|
list = []
|
|
@@ -48,7 +28,7 @@ class EtvnetSeek
|
|
|
48
28
|
}
|
|
49
29
|
|
|
50
30
|
if href =~ /action=browse_container/
|
|
51
|
-
record[:container] =
|
|
31
|
+
record[:container] = search(href)
|
|
52
32
|
else
|
|
53
33
|
result = href.match(/(\w*)\/(\w*)\/(\w*)\/([\w|-]*)/)
|
|
54
34
|
|
|
@@ -65,7 +45,7 @@ class EtvnetSeek
|
|
|
65
45
|
list
|
|
66
46
|
end
|
|
67
47
|
|
|
68
|
-
def
|
|
48
|
+
def display_results items
|
|
69
49
|
items.each_with_index do |item1, index1|
|
|
70
50
|
|
|
71
51
|
if item1[:container].nil?
|
|
@@ -80,49 +60,20 @@ class EtvnetSeek
|
|
|
80
60
|
end
|
|
81
61
|
end
|
|
82
62
|
|
|
83
|
-
def grab_movie_link link
|
|
63
|
+
def grab_movie_link link, cookie, url
|
|
84
64
|
result = link.match(/(\w*)\/(\w*)\/(\w*)\/([\w|-]*)/)
|
|
85
65
|
|
|
86
66
|
media_file = (not result.nil? and result.size > 2) ? result[3] : ""
|
|
87
67
|
|
|
88
|
-
media_info = request_media_info media_file, cookie
|
|
68
|
+
media_info = request_media_info media_file, cookie, url
|
|
89
69
|
|
|
90
70
|
mms_link(media_info)
|
|
91
71
|
end
|
|
92
72
|
|
|
93
73
|
private
|
|
94
74
|
|
|
95
|
-
def
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if File.exist? file_name
|
|
99
|
-
cookie = read_user_file file_name
|
|
100
|
-
else
|
|
101
|
-
username = ask("Enter username : " )
|
|
102
|
-
password = ask("Enter password : " ) { |q| q.echo = '*' }
|
|
103
|
-
|
|
104
|
-
cookie = retrieve_cookie LOGIN_URL, username, password
|
|
105
|
-
|
|
106
|
-
write_user_file file_name, cookie
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
cookie
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def read_user_file file_name
|
|
113
|
-
File.open(file_name, 'r') do |file|
|
|
114
|
-
return file.gets
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def write_user_file file_name, cookie
|
|
119
|
-
File.open(file_name, 'w') do |file|
|
|
120
|
-
file.puts cookie
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def request_media_info media_file, cookie
|
|
125
|
-
url = URI.parse(ACCESS_URL)
|
|
75
|
+
def request_media_info media_file, cookie, url
|
|
76
|
+
url = URI.parse(url)
|
|
126
77
|
conn = Net::HTTP.new(url.host, url.port)
|
|
127
78
|
|
|
128
79
|
headers = { 'Cookie' => cookie }
|
data/spec/etvnet_seek_spec.rb
CHANGED
|
@@ -4,20 +4,30 @@ require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
|
|
|
4
4
|
|
|
5
5
|
#require 'spec'
|
|
6
6
|
|
|
7
|
-
require '
|
|
7
|
+
require 'main'
|
|
8
|
+
require 'url_seeker'
|
|
9
|
+
require 'runglish'
|
|
8
10
|
|
|
9
|
-
describe
|
|
11
|
+
describe UrlSeeker do
|
|
10
12
|
|
|
11
13
|
before :each do
|
|
12
|
-
@client =
|
|
14
|
+
@client = UrlSeeker.new
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it "should return search menu items" do
|
|
16
18
|
keywords = "красная шапочка"
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@client.
|
|
20
|
+
#@client.search(keywords).size.should > 0
|
|
21
|
+
|
|
22
|
+
items = @client.search(Main.search_url(keywords))
|
|
23
|
+
@client.display_results items
|
|
21
24
|
end
|
|
22
25
|
|
|
23
26
|
end
|
|
27
|
+
|
|
28
|
+
describe Runglish do
|
|
29
|
+
it "should return translation" do
|
|
30
|
+
Runglish.new.translate("kak dela?").size.should > 0
|
|
31
|
+
p Runglish.new.translate("kak dela?")
|
|
32
|
+
end
|
|
33
|
+
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.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Shvets
|
|
@@ -74,7 +74,9 @@ files:
|
|
|
74
74
|
- bin/etvnet_seek
|
|
75
75
|
- bin/etvnet_seek.bat
|
|
76
76
|
- lib/cookie_helper.rb
|
|
77
|
-
- lib/
|
|
77
|
+
- lib/main.rb
|
|
78
|
+
- lib/runglish.rb
|
|
79
|
+
- lib/url_seeker.rb
|
|
78
80
|
- spec/etvnet_seek_spec.rb
|
|
79
81
|
- spec/spec.opts
|
|
80
82
|
- CHANGES
|