showfeature 0.1.1 → 0.1.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/README.md +60 -5
- data/lib/showfeature/processor.rb +19 -4
- data/lib/showfeature/version.rb +1 -1
- data/showfeature.gemspec +1 -0
- data/spec/showfeature_spec.rb +15 -3
- metadata +4 -3
data/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
# ShowFeature
|
|
2
2
|
|
|
3
|
-
A library to find
|
|
4
|
-
was downloaded
|
|
3
|
+
A library to find the relevant features in a tv show filename
|
|
5
4
|
(e.g. [name].S[season]E[episode].hdtv-[team].avi)
|
|
6
5
|
|
|
7
6
|
# Usage
|
|
8
7
|
|
|
8
|
+
### Example 1
|
|
9
|
+
|
|
9
10
|
```ruby
|
|
10
11
|
require 'showfeature'
|
|
11
12
|
sf = ShowFeature::Processor.new('foo.125.x264-bar.mkv')
|
|
@@ -13,8 +14,62 @@ sf.parse
|
|
|
13
14
|
puts sf.to_hsh # prints {:name=>"foo", :season=>"01", :episode=>"05", :team=>"bar"}
|
|
14
15
|
```
|
|
15
16
|
|
|
17
|
+
### Example 2
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require 'showfeature'
|
|
21
|
+
require 'fileutils'
|
|
22
|
+
include ShowFeature
|
|
23
|
+
def file_elements in_directory, to_directory = File.expand_path(".")
|
|
24
|
+
FileUtils.chdir in_directory do
|
|
25
|
+
Dir.glob('*').each do |file|
|
|
26
|
+
# if file is a video or a subtitles file
|
|
27
|
+
if [:video_file_type?,:subtitles_file_type?].any?{|mth| Processor.send(mth,file)}
|
|
28
|
+
sf = Processor.new (file)
|
|
29
|
+
sf.parse
|
|
30
|
+
unless sf.to_hsh.empty?
|
|
31
|
+
# create a directory whose name is built with the name of the tv show
|
|
32
|
+
show_dir = File.join to_directory, sf.name.gsub(' ','_'), sf.season
|
|
33
|
+
FileUtils.mkdir_p show_dir unless Dir.exists? show_dir
|
|
34
|
+
# mv
|
|
35
|
+
FileUtils.mv sf.raw_name, File.join(show_dir,sf.raw_name), :verbose => true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
system "tree"
|
|
43
|
+
|
|
44
|
+
# Produces:
|
|
45
|
+
# .
|
|
46
|
+
# |-- foobar.101.x264-raboof.avi
|
|
47
|
+
# |-- foo.s01e01.hdtv-bar.mp4
|
|
48
|
+
# |-- foo.s01e02.hdtv-bar.mp4
|
|
49
|
+
# `-- foo.s01e02.hdtv-bar.srt
|
|
50
|
+
#
|
|
51
|
+
# 0 directories, 4 files
|
|
52
|
+
|
|
53
|
+
file_elements File.expand_path('~/Vidéos'), File.expand_path('~/Vidéos')
|
|
54
|
+
|
|
55
|
+
system "tree"
|
|
56
|
+
|
|
57
|
+
# Produces:
|
|
58
|
+
# .
|
|
59
|
+
# |-- foo
|
|
60
|
+
# | `-- 01
|
|
61
|
+
# | |-- foo.s01e01.hdtv-bar.mp4
|
|
62
|
+
# | |-- foo.s01e02.hdtv-bar.mp4
|
|
63
|
+
# | `-- foo.s01e02.hdtv-bar.srt
|
|
64
|
+
# `-- foobar
|
|
65
|
+
# `-- 01
|
|
66
|
+
# `-- foobar.101.x264-raboof.avi
|
|
67
|
+
|
|
68
|
+
# 4 directories, 4 files
|
|
69
|
+
```
|
|
70
|
+
|
|
16
71
|
**Author :** Allan Seymour
|
|
17
|
-
**Version :** 0.1.
|
|
18
|
-
**Release Date :** December
|
|
72
|
+
**Version :** 0.1.2
|
|
73
|
+
**Release Date :** December 06, 2012
|
|
19
74
|
**Copyright :** MIT License
|
|
20
75
|
|
|
@@ -18,8 +18,8 @@ module ShowFeature
|
|
|
18
18
|
# An ArgumentError is raised if +raw_name+'s mime type does not
|
|
19
19
|
# match the type of a video file
|
|
20
20
|
def initialize(raw_name)
|
|
21
|
-
raise ShowFeature::ArgumentError,
|
|
22
|
-
ShowFeature::Processor.
|
|
21
|
+
raise ShowFeature::ArgumentError, "#{raw_name} does not match a video or subtitle file type" unless
|
|
22
|
+
[:video_file_type?, :subtitles_file_type?].any? {|f| ShowFeature::Processor.send f,raw_name }
|
|
23
23
|
@raw_name = raw_name
|
|
24
24
|
@parsed = false
|
|
25
25
|
end
|
|
@@ -31,7 +31,7 @@ module ShowFeature
|
|
|
31
31
|
tmp = @raw_name[PATTERN,position]
|
|
32
32
|
tmp.nil? ? nil : proc.call(tmp)
|
|
33
33
|
end
|
|
34
|
-
@name = proc.call(1, lambda{|x| x.downcase.
|
|
34
|
+
@name = proc.call(1, lambda{|x| x.downcase.gsub('.',' ')})
|
|
35
35
|
@season = proc.call(2, lambda{|x| "%02d" % x[/(\d+).?(\d{2}$)/,1].to_i})
|
|
36
36
|
@episode = proc.call(2, lambda{|x| "%02d" % x[/(\d+).?(\d{2}$)/,2].to_i})
|
|
37
37
|
@team = proc.call(3, lambda{|x| x.downcase})
|
|
@@ -67,13 +67,28 @@ module ShowFeature
|
|
|
67
67
|
MIME::Types.of(@raw_name).any? do |x| x.to_s =~/^video/ end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
##
|
|
71
|
+
# Checks if +str+'s mime type matches a subtitles file type
|
|
72
|
+
def self.subtitles_file_type?(str)
|
|
73
|
+
(str =~ /\.(srt|sub)$/) ? true : false
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
##
|
|
77
|
+
# Checks if the mime type of the current processed show matches a subtitles file type
|
|
78
|
+
def subtitles_file_type?
|
|
79
|
+
(@raw_name =~ /\.(srt|sub)$/) ? true : false
|
|
80
|
+
end
|
|
70
81
|
|
|
71
82
|
def replace(arg)
|
|
72
83
|
raise ShowFeature::TypeError, 'argument must be of type String or Hash' unless
|
|
73
84
|
[String, Hash].any?{|type| arg.kind_of? type}
|
|
74
85
|
raise ShowFeature::NotParsedError, 'showfeature cannot complete replace if show is not parsed' unless parsed?
|
|
75
86
|
if arg.kind_of? String
|
|
76
|
-
|
|
87
|
+
if video_file_type?
|
|
88
|
+
@raw_name = arg if ShowFeature::Processor.video_file_type?(arg)
|
|
89
|
+
elsif subtitle_file_type?
|
|
90
|
+
@raw_name = arg if ShowFeature::Processor.subtitles_file_type?(arg)
|
|
91
|
+
end
|
|
77
92
|
else
|
|
78
93
|
hash = {
|
|
79
94
|
:name =>@name,
|
data/lib/showfeature/version.rb
CHANGED
data/showfeature.gemspec
CHANGED
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.test_files = `git ls-files -- spec `.split("\n")
|
|
15
15
|
spec.license = 'MIT'
|
|
16
16
|
spec.has_rdoc = true
|
|
17
|
+
spec.extra_rdoc_files = ['README.md']
|
|
17
18
|
spec.add_dependency('mime-types', '>=1.19')
|
|
18
19
|
spec.add_development_dependency('bundler')
|
|
19
20
|
end
|
data/spec/showfeature_spec.rb
CHANGED
|
@@ -37,7 +37,7 @@ describe ShowFeature::Processor do
|
|
|
37
37
|
result = lambda{ ShowFeature::Processor.new('show')}
|
|
38
38
|
result.must_raise ShowFeature::ArgumentError
|
|
39
39
|
error = result.call rescue $!
|
|
40
|
-
error.message.must_equal '
|
|
40
|
+
error.message.must_equal 'show does not match a video or subtitle file type'
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
|
|
@@ -52,8 +52,8 @@ describe ShowFeature::Processor do
|
|
|
52
52
|
it "must filled the hash correctly " do
|
|
53
53
|
@sf.parse
|
|
54
54
|
@sf.to_hsh.must_equal({ :name => @output.name.gsub('.', ' '),
|
|
55
|
-
:season => @output.season,
|
|
56
|
-
:episode => @output.episode,
|
|
55
|
+
:season => "%02d" % @output.season,
|
|
56
|
+
:episode => "%02d" % @output.episode,
|
|
57
57
|
:team => @output.team })
|
|
58
58
|
end
|
|
59
59
|
it "must return an empty hash if showfeature is not parsed yet" do
|
|
@@ -131,6 +131,18 @@ describe ShowFeature::Processor do
|
|
|
131
131
|
[TrueClass,FalseClass].any? {|elt| @sf.video_file_type?.instance_of? elt}
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
|
+
it "must be true" do
|
|
135
|
+
@sf.video_file_type?.must_equal true
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "when asked if it is a subtitles file" do
|
|
140
|
+
before do
|
|
141
|
+
@sf = ShowFeature::Processor.new("foo.s01e05.x264-bar.srt")
|
|
142
|
+
end
|
|
143
|
+
it "must be true" do
|
|
144
|
+
@sf.subtitles_file_type?.must_equal true
|
|
145
|
+
end
|
|
134
146
|
end
|
|
135
147
|
|
|
136
148
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: showfeature
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-12-
|
|
12
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: mime-types
|
|
@@ -48,7 +48,8 @@ description: This library allows to find the relevant features in a tv show file
|
|
|
48
48
|
email: banks.the.megalithic.stone@gmail.com
|
|
49
49
|
executables: []
|
|
50
50
|
extensions: []
|
|
51
|
-
extra_rdoc_files:
|
|
51
|
+
extra_rdoc_files:
|
|
52
|
+
- README.md
|
|
52
53
|
files:
|
|
53
54
|
- .gitignore
|
|
54
55
|
- Gemfile
|