mediaman 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mediaman/media_filename.rb +23 -68
- data/lib/mediaman/trakt.rb +10 -2
- data/lib/mediaman/version.rb +1 -1
- data/mediaman.gemspec +1 -0
- data/spec/mediaman/media_filename_spec.rb +29 -0
- metadata +15 -4
@@ -1,13 +1,26 @@
|
|
1
1
|
module Mediaman
|
2
2
|
|
3
|
+
require "to_name"
|
4
|
+
|
3
5
|
class MediaFilename
|
4
|
-
|
6
|
+
|
5
7
|
attr_accessor :filename
|
6
8
|
|
7
9
|
def initialize(filename)
|
8
10
|
self.filename = filename
|
9
|
-
|
10
|
-
|
11
|
+
@parsed_name = self.to_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_name
|
15
|
+
fn = ToName.to_name(filename)
|
16
|
+
{
|
17
|
+
name: fn.name,
|
18
|
+
year: fn.year,
|
19
|
+
raw_name: fn.raw_name,
|
20
|
+
location: fn.location,
|
21
|
+
season_number: fn.series,
|
22
|
+
episode_number: fn.episode
|
23
|
+
}
|
11
24
|
end
|
12
25
|
|
13
26
|
def to_hash
|
@@ -25,69 +38,15 @@ module Mediaman
|
|
25
38
|
}
|
26
39
|
end
|
27
40
|
|
28
|
-
def parse_name!
|
29
|
-
name = self.filename + ".mov"
|
30
|
-
|
31
|
-
# Normal matching
|
32
|
-
normal_matches = name.match(/^([a-zA-Z0-9.]*)\.S([0-9]{1,2})E([0-9]{1,2}).*$/i)
|
33
|
-
if normal_matches
|
34
|
-
@item_name = normal_matches[1]
|
35
|
-
@season = normal_matches[2].to_i
|
36
|
-
@episode = normal_matches[3].to_i
|
37
|
-
end
|
38
|
-
|
39
|
-
unless @item_name && @season && @episode
|
40
|
-
# Mythbusters hack
|
41
|
-
mythbusters_matches = name.match(/(myth.*)([0-9][0-9])([0-9][0-9])/i)
|
42
|
-
if mythbusters_matches && mythbusters_matches[1].downcase.include?("myth")
|
43
|
-
@item_name = "Mythbusters"
|
44
|
-
@season = mythbusters_matches[2].to_i
|
45
|
-
@episode = mythbusters_matches[3].to_i
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
41
|
def raw_name
|
52
|
-
|
42
|
+
self.filename
|
53
43
|
end
|
54
44
|
|
55
45
|
def formatted_name
|
56
|
-
|
57
|
-
|
58
|
-
name =
|
59
|
-
|
60
|
-
name_string = raw_name.gsub("'", "")
|
61
|
-
name_string = raw_name.gsub(";", "")
|
62
|
-
|
63
|
-
splitsies = name_string.split(/[ -.\[\]]/)
|
64
|
-
splitsies.each_index do |i|
|
65
|
-
x = splitsies[i].split(" ")
|
66
|
-
x = x.split("+")
|
67
|
-
x = x.split("_")
|
68
|
-
x = x.split("[")
|
69
|
-
x = x.split("]")
|
70
|
-
splitsies[i] = x
|
71
|
-
end
|
72
|
-
|
73
|
-
name_done = false
|
74
|
-
i = 0
|
75
|
-
for item in splitsies.flatten
|
76
|
-
int = item.to_i
|
77
|
-
if (1900..Time.now.year + 3).cover?(int) && i > 0
|
78
|
-
@year = int
|
79
|
-
name_done = true
|
80
|
-
elsif item == "720p"
|
81
|
-
name_done = true
|
82
|
-
else
|
83
|
-
perioded_name << item unless name_done
|
84
|
-
end
|
85
|
-
i += 1
|
86
|
-
end
|
87
|
-
name = perioded_name.join(" ")
|
46
|
+
name = @parsed_name[:name]
|
88
47
|
|
89
48
|
# Hacks
|
90
|
-
name.gsub! /Extended( Version)/i, ""
|
49
|
+
name.gsub! /Extended( Version)( Edition)/i, ""
|
91
50
|
|
92
51
|
name
|
93
52
|
end
|
@@ -102,11 +61,11 @@ module Mediaman
|
|
102
61
|
end
|
103
62
|
|
104
63
|
def season
|
105
|
-
@
|
64
|
+
@parsed_name[:season_number]
|
106
65
|
end
|
107
66
|
|
108
67
|
def episode
|
109
|
-
@
|
68
|
+
@parsed_name[:episode_number]
|
110
69
|
end
|
111
70
|
|
112
71
|
def tv?
|
@@ -114,7 +73,7 @@ module Mediaman
|
|
114
73
|
end
|
115
74
|
|
116
75
|
def year
|
117
|
-
@year
|
76
|
+
@parsed_name[:year]
|
118
77
|
end
|
119
78
|
|
120
79
|
def movie?
|
@@ -143,10 +102,6 @@ module Mediaman
|
|
143
102
|
def to_s
|
144
103
|
formatted_name
|
145
104
|
end
|
146
|
-
|
147
|
-
def debug
|
148
|
-
"name: #{name}, formatted_name: #{formatted_name}, slug: #{slug}, season: #{season}, episode: #{episode}, hd?: #{hd?}, tv?: #{tv?}, string: #{string}"
|
149
|
-
end
|
150
|
-
|
105
|
+
|
151
106
|
end
|
152
107
|
end
|
data/lib/mediaman/trakt.rb
CHANGED
@@ -35,7 +35,7 @@ module Mediaman
|
|
35
35
|
class Movie < Fetcher
|
36
36
|
|
37
37
|
def slug
|
38
|
-
"#{options[:title].parameterize}-#{options[:year].to_s.parameterize}"
|
38
|
+
options[:slug].presence || "#{options[:title].parameterize}-#{options[:year].to_s.parameterize}"
|
39
39
|
end
|
40
40
|
|
41
41
|
def fetch!
|
@@ -49,12 +49,20 @@ module Mediaman
|
|
49
49
|
attr_accessor :show
|
50
50
|
|
51
51
|
def fetch!
|
52
|
-
url = "http://api.trakt.tv/show/episode/summary.json/#{Trakt.api_key}/#{
|
52
|
+
url = "http://api.trakt.tv/show/episode/summary.json/#{Trakt.api_key}/#{slug}"
|
53
53
|
self.response = r = self.class.get(url)
|
54
54
|
self.show = Trakt::TVShow.from_hash self.response['show']
|
55
55
|
self.response['episode']
|
56
56
|
end
|
57
|
+
|
58
|
+
def slug
|
59
|
+
options[:slug].presence || "#{name_slug}/#{options[:season_number]}/#{options[:episode_number]}"
|
60
|
+
end
|
57
61
|
|
62
|
+
def name_slug
|
63
|
+
options[:name_slug].presence || "#{options[:show_title].parameterize}"
|
64
|
+
end
|
65
|
+
|
58
66
|
end
|
59
67
|
|
60
68
|
class TVShow < Fetcher
|
data/lib/mediaman/version.rb
CHANGED
data/mediaman.gemspec
CHANGED
@@ -29,6 +29,35 @@ describe Mediaman::MediaFilename do
|
|
29
29
|
h = parse("John Adams.S01E01.720p.HDTV.x264")
|
30
30
|
h[:name].should == "John Adams"
|
31
31
|
end
|
32
|
+
|
33
|
+
it "Breaking Bad S01E04" do
|
34
|
+
h = parse("Breaking Bad S01E04")
|
35
|
+
h[:name].should == "Breaking Bad"
|
36
|
+
h[:season_number].should == 1
|
37
|
+
h[:episode_number].should == 4
|
38
|
+
end
|
39
|
+
|
40
|
+
it "My Best Friend 6x03" do
|
41
|
+
h = parse("My Best Friend 6x03")
|
42
|
+
h[:name].should == "My Best Friend"
|
43
|
+
h[:season_number].should == 6
|
44
|
+
h[:episode_number].should == 3
|
45
|
+
end
|
46
|
+
|
47
|
+
it "extended editions" do
|
48
|
+
h = parse("The Fall Extended Edition")
|
49
|
+
h[:name].should == "The Fall"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "extended editions" do
|
53
|
+
h = parse("The Fall Extended Version")
|
54
|
+
h[:name].should == "The Fall"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "extended editions" do
|
58
|
+
h = parse("The Fall Extended")
|
59
|
+
h[:name].should == "The Fall"
|
60
|
+
end
|
32
61
|
|
33
62
|
end
|
34
63
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mediaman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Wil Gieseler
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
type: :runtime
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: toname
|
72
72
|
prerelease: false
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: "0"
|
79
|
-
type: :
|
79
|
+
type: :runtime
|
80
80
|
version_requirements: *id006
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: rake
|
83
83
|
prerelease: false
|
84
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
@@ -89,6 +89,17 @@ dependencies:
|
|
89
89
|
version: "0"
|
90
90
|
type: :development
|
91
91
|
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rspec
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id008
|
92
103
|
description: Mediaman manages your media, man.
|
93
104
|
email:
|
94
105
|
- supapuerco@gmail.com
|