etvnet-seek 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/Gemfile +18 -8
  2. data/README +1 -1
  3. data/Rakefile +27 -5
  4. data/VERSION +1 -1
  5. data/bin/etvnet-seek +8 -3
  6. data/etvnet-seek.gemspec +79 -42
  7. data/lib/etvnet_seek/accessor.rb +64 -0
  8. data/lib/etvnet_seek/commander.rb +37 -21
  9. data/lib/etvnet_seek/core/access_page.rb +23 -6
  10. data/lib/etvnet_seek/core/audio_page.rb +26 -0
  11. data/lib/etvnet_seek/core/best_hundred_page.rb +20 -0
  12. data/lib/etvnet_seek/core/browse_media_item.rb +1 -0
  13. data/lib/etvnet_seek/core/catalog_page.rb +26 -14
  14. data/lib/etvnet_seek/core/channels_page.rb +6 -2
  15. data/lib/etvnet_seek/core/group_media_item.rb +2 -0
  16. data/lib/etvnet_seek/core/group_page.rb +9 -23
  17. data/lib/etvnet_seek/core/home_page.rb +5 -2
  18. data/lib/etvnet_seek/core/items_page.rb +140 -0
  19. data/lib/etvnet_seek/core/items_page_factory.rb +47 -0
  20. data/lib/etvnet_seek/core/login_page.rb +3 -1
  21. data/lib/etvnet_seek/core/media_info.rb +3 -18
  22. data/lib/etvnet_seek/core/media_item.rb +10 -2
  23. data/lib/etvnet_seek/core/media_page.rb +54 -27
  24. data/lib/etvnet_seek/core/new_item.rb +2 -0
  25. data/lib/etvnet_seek/core/new_items_page.rb +4 -1
  26. data/lib/etvnet_seek/core/page.rb +2 -0
  27. data/lib/etvnet_seek/core/premiere_page.rb +7 -0
  28. data/lib/etvnet_seek/core/radio_page.rb +23 -0
  29. data/lib/etvnet_seek/core/search_page.rb +3 -33
  30. data/lib/etvnet_seek/core/service_call.rb +34 -6
  31. data/lib/etvnet_seek/core/top_this_week_page.rb +20 -0
  32. data/lib/etvnet_seek/etvnet_seek.rb +1 -4
  33. data/lib/etvnet_seek/main.rb +113 -84
  34. data/spec/etvnet_seek_spec.rb +10 -8
  35. data/spec/spec_helper.rb +3 -0
  36. data/spec/unit/pages_spec.rb +77 -0
  37. metadata +182 -32
  38. data/lib/etvnet_seek/core/base_page.rb +0 -43
  39. data/lib/etvnet_seek/core/page_factory.rb +0 -51
data/Gemfile CHANGED
@@ -1,14 +1,24 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "gemcutter"
4
- gem "jeweler"
5
- gem "sinatra"
6
3
  gem "nokogiri"
7
4
  gem "libxml-ruby"
8
- gem "zipit"
9
- gem "highline"
10
5
  gem "json_pure"
11
- gem "rake"
12
6
 
13
- gem "rspec", :require => "spec"
14
- gem "mocha"
7
+ group :development do
8
+ gem "jeweler"
9
+ gem "gemcutter"
10
+ gem "rake"
11
+ gem "highline"
12
+ gem "zipit"
13
+
14
+ gem 'ruby-debug-base19' if RUBY_VERSION.include? "1.9"
15
+ gem 'ruby-debug-base' if RUBY_VERSION.include? "1.8"
16
+ gem "ruby-debug-ide"
17
+ end
18
+
19
+ group :test do
20
+ gem "mocha"
21
+ gem "rspec", "2.2.0"
22
+ gem "rcov"
23
+ end
24
+
data/README CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  Usage: etvnet-seek [options] keywords
12
12
  -s, --search Display Search Menu
13
- -r, --runglish Enter russian keywords in translit
13
+ -t, --translit Enter russian keywords in translit
14
14
  -b, --best-hunred Display Best 100 Menu
15
15
  -n, --new_items Display New Items Menu
16
16
  -p, --premier Display Premier of the Week Menu
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
2
2
 
3
3
  require 'rake'
4
- require 'spec/rake/spectask'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  begin
7
7
  require 'zipit'
@@ -40,6 +40,29 @@ task :zip do
40
40
  zip :archive => "etvnet-seek.zip", :dir => "."
41
41
  end
42
42
 
43
+ desc "Release the gem"
44
+ task :"release:gem" do
45
+ %x(
46
+ rm -rf pkg
47
+ rake gemspec
48
+ rake build
49
+ rake install
50
+ git add .
51
+ )
52
+ puts "Commit message:"
53
+ message = STDIN.gets
54
+
55
+ version = "#{File.open(File::dirname(__FILE__) + "/VERSION").readlines().first}"
56
+
57
+ %x(
58
+ git commit -m "#{message}"
59
+
60
+ git push origin master
61
+
62
+ gem push pkg/#{File.basename(File.expand_path("."))}-#{version}.gem
63
+ )
64
+ end
65
+
43
66
  desc "Run gem code locally"
44
67
  task :"run:gem" do
45
68
  command = "bin/etvnet-seek"
@@ -47,10 +70,9 @@ task :"run:gem" do
47
70
  end
48
71
 
49
72
  # configure rspec
50
- Spec::Rake::SpecTask.new do |spec|
51
- spec.spec_files = FileList["spec/**/*_spec.rb"]
52
- spec.spec_opts << "--color"
53
- spec.libs += ["lib", "spec"]
73
+ RSpec::Core::RakeTask.new do |task|
74
+ task.pattern = 'spec/**/*_spec.rb'
75
+ task.verbose = false
54
76
  end
55
77
 
56
78
  task :default => :zip
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.8.0
@@ -8,16 +8,21 @@ $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
8
8
  $KCODE='u'
9
9
 
10
10
  require 'etvnet_seek/etvnet_seek'
11
- require 'etvnet_seek/main'
12
11
 
13
12
  trap('INT') { puts "Program was interrupted..."; exit }
14
13
 
15
14
  client = Main.new
16
15
 
17
- link_info = client.seek ARGV.join(' ')
16
+ link_info = nil
17
+
18
+ begin
19
+ link_info = client.process ARGV.join(' ')
20
+ rescue Exception => e
21
+ puts e.message
22
+ end
18
23
 
19
24
  if not link_info.nil? and link_info.resolved?
20
- puts "Link #{link_info.text} [#{link_info.name} (#{link_info.media_file})]: #{link_info.link}"
25
+ puts "Link #{link_info.text} [(#{link_info.media_file})]: #{link_info.link}"
21
26
  #puts "#{link_info.rtsp_link}"
22
27
 
23
28
  launch = ask("Launch link (y/n)?")
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{etvnet-seek}
8
- s.version = "0.7.2"
8
+ s.version = "0.8.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Shvets"]
12
- s.date = %q{2010-07-11}
12
+ s.date = %q{2010-12-04}
13
13
  s.default_executable = %q{etvnet-seek}
14
14
  s.description = %q{Command line tool for getting mms urls from etvnet service.}
15
15
  s.email = %q{alexander.shvets@gmail.com}
@@ -19,52 +19,59 @@ Gem::Specification.new do |s|
19
19
  ]
20
20
  s.files = [
21
21
  "CHANGES",
22
- "Gemfile",
23
- "README",
24
- "Rakefile",
25
- "VERSION",
26
- "bin/etvnet-seek",
27
- "bin/etvnet-seek.bat",
28
- "etvnet-seek.gemspec",
29
- "lib/etvnet_seek/commander.rb",
30
- "lib/etvnet_seek/cookie_helper.rb",
31
- "lib/etvnet_seek/core/access_page.rb",
32
- "lib/etvnet_seek/core/base_page.rb",
33
- "lib/etvnet_seek/core/browse_media_item.rb",
34
- "lib/etvnet_seek/core/catalog_item.rb",
35
- "lib/etvnet_seek/core/catalog_page.rb",
36
- "lib/etvnet_seek/core/channel_media_item.rb",
37
- "lib/etvnet_seek/core/channels_page.rb",
38
- "lib/etvnet_seek/core/group_media_item.rb",
39
- "lib/etvnet_seek/core/group_page.rb",
40
- "lib/etvnet_seek/core/home_page.rb",
41
- "lib/etvnet_seek/core/login_page.rb",
42
- "lib/etvnet_seek/core/media_info.rb",
43
- "lib/etvnet_seek/core/media_item.rb",
44
- "lib/etvnet_seek/core/media_page.rb",
45
- "lib/etvnet_seek/core/new_item.rb",
46
- "lib/etvnet_seek/core/new_items_page.rb",
47
- "lib/etvnet_seek/core/page.rb",
48
- "lib/etvnet_seek/core/page_factory.rb",
49
- "lib/etvnet_seek/core/search_page.rb",
50
- "lib/etvnet_seek/core/service_call.rb",
51
- "lib/etvnet_seek/easy_auth.rb",
52
- "lib/etvnet_seek/etvnet_seek.rb",
53
- "lib/etvnet_seek/link_info.rb",
54
- "lib/etvnet_seek/main.rb",
55
- "lib/etvnet_seek/user_selection.rb",
56
- "lib/media_converter.rb",
57
- "lib/progressbar.rb",
58
- "lib/runglish.rb"
22
+ "Gemfile",
23
+ "README",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/etvnet-seek",
27
+ "bin/etvnet-seek.bat",
28
+ "etvnet-seek.gemspec",
29
+ "lib/etvnet_seek/accessor.rb",
30
+ "lib/etvnet_seek/commander.rb",
31
+ "lib/etvnet_seek/cookie_helper.rb",
32
+ "lib/etvnet_seek/core/access_page.rb",
33
+ "lib/etvnet_seek/core/audio_page.rb",
34
+ "lib/etvnet_seek/core/best_hundred_page.rb",
35
+ "lib/etvnet_seek/core/browse_media_item.rb",
36
+ "lib/etvnet_seek/core/catalog_item.rb",
37
+ "lib/etvnet_seek/core/catalog_page.rb",
38
+ "lib/etvnet_seek/core/channel_media_item.rb",
39
+ "lib/etvnet_seek/core/channels_page.rb",
40
+ "lib/etvnet_seek/core/group_media_item.rb",
41
+ "lib/etvnet_seek/core/group_page.rb",
42
+ "lib/etvnet_seek/core/home_page.rb",
43
+ "lib/etvnet_seek/core/items_page.rb",
44
+ "lib/etvnet_seek/core/items_page_factory.rb",
45
+ "lib/etvnet_seek/core/login_page.rb",
46
+ "lib/etvnet_seek/core/media_info.rb",
47
+ "lib/etvnet_seek/core/media_item.rb",
48
+ "lib/etvnet_seek/core/media_page.rb",
49
+ "lib/etvnet_seek/core/new_item.rb",
50
+ "lib/etvnet_seek/core/new_items_page.rb",
51
+ "lib/etvnet_seek/core/page.rb",
52
+ "lib/etvnet_seek/core/premiere_page.rb",
53
+ "lib/etvnet_seek/core/radio_page.rb",
54
+ "lib/etvnet_seek/core/search_page.rb",
55
+ "lib/etvnet_seek/core/service_call.rb",
56
+ "lib/etvnet_seek/core/top_this_week_page.rb",
57
+ "lib/etvnet_seek/easy_auth.rb",
58
+ "lib/etvnet_seek/etvnet_seek.rb",
59
+ "lib/etvnet_seek/link_info.rb",
60
+ "lib/etvnet_seek/main.rb",
61
+ "lib/etvnet_seek/user_selection.rb",
62
+ "lib/media_converter.rb",
63
+ "lib/progressbar.rb",
64
+ "lib/runglish.rb"
59
65
  ]
60
66
  s.homepage = %q{http://github.com/shvets/etvnet-seek}
61
- s.rdoc_options = ["--charset=UTF-8"]
62
67
  s.require_paths = ["lib"]
63
68
  s.requirements = ["none"]
64
69
  s.rubygems_version = %q{1.3.7}
65
70
  s.summary = %q{Accessing etvnet service from command line.}
66
71
  s.test_files = [
67
- "spec/etvnet_seek_spec.rb"
72
+ "spec/etvnet_seek_spec.rb",
73
+ "spec/spec_helper.rb",
74
+ "spec/unit/pages_spec.rb"
68
75
  ]
69
76
 
70
77
  if s.respond_to? :specification_version then
@@ -72,6 +79,16 @@ Gem::Specification.new do |s|
72
79
  s.specification_version = 3
73
80
 
74
81
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
83
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 0"])
84
+ s.add_runtime_dependency(%q<json_pure>, [">= 0"])
85
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
86
+ s.add_development_dependency(%q<gemcutter>, [">= 0"])
87
+ s.add_development_dependency(%q<rake>, [">= 0"])
88
+ s.add_development_dependency(%q<highline>, [">= 0"])
89
+ s.add_development_dependency(%q<zipit>, [">= 0"])
90
+ s.add_development_dependency(%q<ruby-debug-base>, [">= 0"])
91
+ s.add_development_dependency(%q<ruby-debug-ide>, [">= 0"])
75
92
  s.add_runtime_dependency(%q<json_pure>, [">= 1.2.0"])
76
93
  s.add_runtime_dependency(%q<highline>, [">= 1.5.1"])
77
94
  s.add_runtime_dependency(%q<libxml-ruby>, [">= 1.1.3"])
@@ -79,6 +96,16 @@ Gem::Specification.new do |s|
79
96
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
80
97
  s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
81
98
  else
99
+ s.add_dependency(%q<nokogiri>, [">= 0"])
100
+ s.add_dependency(%q<libxml-ruby>, [">= 0"])
101
+ s.add_dependency(%q<json_pure>, [">= 0"])
102
+ s.add_dependency(%q<jeweler>, [">= 0"])
103
+ s.add_dependency(%q<gemcutter>, [">= 0"])
104
+ s.add_dependency(%q<rake>, [">= 0"])
105
+ s.add_dependency(%q<highline>, [">= 0"])
106
+ s.add_dependency(%q<zipit>, [">= 0"])
107
+ s.add_dependency(%q<ruby-debug-base>, [">= 0"])
108
+ s.add_dependency(%q<ruby-debug-ide>, [">= 0"])
82
109
  s.add_dependency(%q<json_pure>, [">= 1.2.0"])
83
110
  s.add_dependency(%q<highline>, [">= 1.5.1"])
84
111
  s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
@@ -87,6 +114,16 @@ Gem::Specification.new do |s|
87
114
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
88
115
  end
89
116
  else
117
+ s.add_dependency(%q<nokogiri>, [">= 0"])
118
+ s.add_dependency(%q<libxml-ruby>, [">= 0"])
119
+ s.add_dependency(%q<json_pure>, [">= 0"])
120
+ s.add_dependency(%q<jeweler>, [">= 0"])
121
+ s.add_dependency(%q<gemcutter>, [">= 0"])
122
+ s.add_dependency(%q<rake>, [">= 0"])
123
+ s.add_dependency(%q<highline>, [">= 0"])
124
+ s.add_dependency(%q<zipit>, [">= 0"])
125
+ s.add_dependency(%q<ruby-debug-base>, [">= 0"])
126
+ s.add_dependency(%q<ruby-debug-ide>, [">= 0"])
90
127
  s.add_dependency(%q<json_pure>, [">= 1.2.0"])
91
128
  s.add_dependency(%q<highline>, [">= 1.5.1"])
92
129
  s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
@@ -0,0 +1,64 @@
1
+ require 'etvnet_seek/cookie_helper'
2
+ require 'etvnet_seek/core/access_page'
3
+ require 'etvnet_seek/core/login_page'
4
+ require 'etvnet_seek/link_info'
5
+
6
+ class Accessor
7
+ def initialize cookie_file_name, credentials_collector
8
+ @cookie_helper = CookieHelper.new cookie_file_name
9
+ @credentials_collector = credentials_collector
10
+
11
+ @access_page = AccessPage.new
12
+ @login_page = LoginPage.new
13
+ end
14
+
15
+ def access item, *params
16
+ @try_again = false
17
+
18
+ cookie = @cookie_helper.load_cookie
19
+
20
+ if cookie.nil?
21
+ username, password = *@credentials_collector.call(*params)
22
+
23
+ @try_again = login(username, password)
24
+
25
+ nil
26
+ #access item
27
+ else
28
+ cookie.gsub!("\"", "\"\"")
29
+
30
+ result1 = cookie.scan(/.*sessid=([\d|\w]*);.*/)
31
+ result2 = cookie.scan(/.*_lc=([\d|\w]*);.*/)
32
+
33
+ short_cookie = "sessid=#{result1[0][0]};_lc=#{result2[0][0]}"
34
+ media_info = @access_page.request_media_info(item.link.scan(/.*\/(\d*)\//)[0][0], short_cookie)
35
+
36
+ if media_info.session_expired?
37
+ @cookie_helper.delete_cookie
38
+
39
+ username, password = *@credentials_collector.call(*params)
40
+
41
+ @try_again = login(username, password)
42
+
43
+ nil
44
+
45
+ #access item
46
+ else
47
+ LinkInfo.new(item, media_info)
48
+ end
49
+ end
50
+ end
51
+
52
+ def try_again?
53
+ @try_again
54
+ end
55
+
56
+ def login username, password
57
+ cookie = @login_page.login(username, password)
58
+
59
+ @cookie_helper.save_cookie cookie
60
+
61
+ cookie.nil?
62
+ end
63
+
64
+ end
@@ -9,22 +9,24 @@ class Commander
9
9
  @options[:search]
10
10
  end
11
11
 
12
- def runglish_mode?
13
- @options[:runglish]
12
+ def translit_mode?
13
+ @options[:translit]
14
14
  end
15
15
 
16
16
  def get_initial_mode
17
- if @options[:search] == true
17
+ if @options[:search] or @options[:translit]
18
18
  'search'
19
- elsif @options[:best_hundred] == true
19
+ elsif @options[:best_hundred]
20
20
  'best_hundred'
21
- elsif @options[:channels] == true
21
+ elsif @options[:top_this_week]
22
+ 'top_this_week'
23
+ elsif @options[:channels]
22
24
  'channels'
23
- elsif @options[:catalog] == true
25
+ elsif @options[:catalog]
24
26
  'catalog'
25
- elsif @options[:new_items] == true
27
+ elsif @options[:new_items]
26
28
  'new_items'
27
- elsif @options[:premiere] == true
29
+ elsif @options[:premiere]
28
30
  'premiere'
29
31
  else
30
32
  'main'
@@ -45,32 +47,37 @@ class Commander
45
47
  opts.banner = "Usage: etvnet-seek [options] keywords"
46
48
 
47
49
  options[:search] = false
48
- opts.on('-s', '--search', 'Display Search Menu') do
50
+ opts.on('-s', '--search', 'Search programs') do
49
51
  options[:search] = true
50
52
  end
51
53
 
52
- options[:runglish] = false
53
- opts.on('-r', '--runglish', 'Enter russian keywords in translit') do
54
- options[:runglish] = true
54
+ options[:translit] = false
55
+ opts.on('-t', '--translit', 'Search programs in translit') do
56
+ options[:translit] = true
55
57
  end
56
58
 
57
59
  options[:best_hundred] = false
58
- opts.on('-b', '--best-hundred', 'Display Best 100 Menu') do
60
+ opts.on('-b', '--best-hundred', 'Best 100 Menu') do
59
61
  options[:best_hundred] = true
60
62
  end
61
63
 
64
+ options[:top_this_week] = false
65
+ opts.on('-w', '--top_this_week', 'Top This Week') do
66
+ options[:top_this_week] = true
67
+ end
68
+
62
69
  options[:channels] = false
63
- opts.on('-c', '--channels', 'Display Channels Menu') do
70
+ opts.on('-c', '--channels', 'Channels Menu') do
64
71
  options[:channels] = true
65
72
  end
66
73
 
67
74
  options[:catalog] = false
68
- opts.on('-a', '--catalog', 'Display Catalog Menu') do
75
+ opts.on('-a', '--catalog', 'Catalog Menu') do
69
76
  options[:catalog] = true
70
77
  end
71
78
 
72
79
  options[:main] = false
73
- opts.on('-m', '--main', 'Display Main Menu') do
80
+ opts.on('-m', '--main', 'Main Menu') do
74
81
  options[:main] = true
75
82
  end
76
83
 
@@ -90,16 +97,25 @@ class Commander
90
97
  puts opts
91
98
  exit
92
99
  end
100
+
101
+ # opts.on('-r', '--require', '') do
102
+ # end
103
+ #
104
+ # opts.on('-f', '--format', '') do
105
+ # end
106
+ #
107
+ # opts.on('-e', '--example', '') do
108
+ # end
93
109
  end
94
110
 
95
111
  optparse.parse!
96
112
 
97
- if options[:runglish] && !options[:search]
98
- puts "Please use -r option together with -s option."
99
- exit
100
- end
113
+ # if options[:runglish] && !options[:search]
114
+ # puts "Please use -r option together with -s option."
115
+ # exit
116
+ # end
101
117
 
102
118
  options
103
119
  end
104
120
 
105
- end
121
+ end