myshows 0.2.1 → 0.2.2

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.tar.gz.sig CHANGED
Binary file
@@ -30,11 +30,16 @@ And use
30
30
  pilot = tbbt.episode "the pilot episode"
31
31
  # or by season and episode number
32
32
  pilot = tbbt.episode 1, 1
33
+ # or by filename
34
+ pilot = search.episodes_by_filename('The.Big.Bang.Theory.S01E01.HDTV.XviD-(Kuraj-Bambey).avi')[0]
33
35
  pilot.title # => "Pilot"
34
36
  pilot.show # => tbbt
35
37
  pilot.air_date # => "24.09.2007" (fields parsing would be done later)
36
38
  # and many other fields provided by API
37
39
 
40
+ # note that more than one episode could correspond to one filename
41
+ two_episodes = search.episodes_by_filename 'Star.Wars.The.Clone.Wars.s02e01e02.rus.LostFilm.TV.avi'
42
+
38
43
  # if you are authorized:
39
44
  pilot.uncheck! # => this episode would be marked as 'unwatched'
40
45
  pilot.check! # => this episode would be marked as 'watched'
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('myshows', '0.2.1') do |p|
5
+ Echoe.new('myshows', '0.2.2') do |p|
6
6
  p.summary = "MyShows API"
7
7
  p.description = "Object-oriented wrapper over API of http://myshows.ru"
8
8
  p.url = "http://github.com/cypok/myshows"
@@ -30,22 +30,6 @@ module MyShows
30
30
  self.class.cookies.add_cookies res.headers["set-cookie"]
31
31
  end
32
32
 
33
- # Returns checked episode
34
- #def check(name, season_number, episode_number)
35
- #shows = search name, :only_user => true
36
- #error "could not find show \"#{name}\" or it is not marked as 'watching'" if shows.count == 0
37
- #error "ambiguous name \"#{name}\", looks like #{shows.take(2) * ', '}" if shows.count > 1
38
-
39
- #show = shows.first
40
- #episodes = show_episodes show
41
- #episode = episodes.detect { |e| e.season_number == season_number && e.episode_number == episode_number }
42
- #error "could not find episode #{season_number}x#{episode_number} of show #{show}" if episode.nil?
43
-
44
- #check_episode episode
45
-
46
- #episode
47
- #end
48
-
49
33
  # Returns all user shows
50
34
  def user_shows
51
35
  res = get '/profile/shows/'
@@ -64,6 +48,15 @@ module MyShows
64
48
  found_shows = json2shows res.body
65
49
  end
66
50
 
51
+ # Returns array of episodes
52
+ def search_episode_by_filename(filename)
53
+ res = get '/shows/search/file/', :q => filename
54
+ return [] if res.code == 404
55
+ error "unknown error while searching by filename \"#{filename}\"" if res.code != 200
56
+
57
+ json2episode_with_show res.body
58
+ end
59
+
67
60
  # Returns episodes of given show
68
61
  def show_episodes(show)
69
62
  res = get "/shows/#{show.id}"
@@ -101,6 +94,14 @@ module MyShows
101
94
  JSON.parse(json)['episodes'].map {|id, data| MyShows::Episode.new id, data, show }
102
95
  end
103
96
 
97
+ def json2episode_with_show(json)
98
+ data = JSON.parse(json)
99
+ # TODO: process data['match']
100
+ episodes = data['show'].delete 'episodes'
101
+ show = MyShows::Show.new data['show']['id'], data['show']
102
+ episodes.map {|id, ep_data| MyShows::Episode.new id, ep_data, show }
103
+ end
104
+
104
105
  def error(msg)
105
106
  raise MyShows::Error.new msg
106
107
  end
@@ -12,5 +12,10 @@ module MyShows
12
12
  def show(name)
13
13
  @api.search_show name
14
14
  end
15
+
16
+ # Returns array of episodes that corresponds to the filename
17
+ def episodes_by_filename(filename)
18
+ @api.search_episode_by_filename filename
19
+ end
15
20
  end
16
21
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{myshows}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Vladimir Parfinenko"]
9
9
  s.cert_chain = ["/Users/cypok/.gem/gem-public_cert.pem"]
10
- s.date = %q{2011-01-29}
10
+ s.date = %q{2011-01-30}
11
11
  s.description = %q{Object-oriented wrapper over API of http://myshows.ru}
12
12
  s.email = %q{vladimir.parfinenko@gmail.com}
13
13
  s.extra_rdoc_files = ["README.rdoc", "lib/myshows.rb", "lib/myshows/api.rb", "lib/myshows/episode.rb", "lib/myshows/item.rb", "lib/myshows/profile.rb", "lib/myshows/search.rb", "lib/myshows/show.rb", "lib/myshows/title_matcher.rb"]
@@ -45,6 +45,22 @@ describe MyShows do
45
45
  found = @search.show 'Some unkown show'
46
46
  found.should == []
47
47
  end
48
+
49
+ it "should find episode by filename" do
50
+ found = @search.episodes_by_filename 'House.M.D.s07e10.rus.720p.LostFilm.TV.mkv'
51
+ e = found.first
52
+ e.show.title.should == 'House'
53
+ e.season_number.should == 7
54
+ e.episode_number.should == 10
55
+ end
56
+
57
+ it "should find two episodes by filename" do
58
+ found = @search.episodes_by_filename 'Star.Wars.The.Clone.Wars.s02e01e02.rus.LostFilm.TV.avi'
59
+ found.each {|e| e.show.title.should == 'Star Wars: The Clone Wars (2008)' }
60
+ found.each {|e| e.season_number.should == 2 }
61
+ found[0].episode_number.should == 1
62
+ found[1].episode_number.should == 2
63
+ end
48
64
  end
49
65
 
50
66
  describe MyShows::Show do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myshows
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Vladimir Parfinenko
@@ -36,7 +36,7 @@ cert_chain:
36
36
  78F0qvtLjR0DAnN6uYs98PR+jHE+0ckLX3D9sw==
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-01-29 00:00:00 +06:00
39
+ date: 2011-01-30 00:00:00 +06:00
40
40
  default_executable:
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file