bathyscaphe 0.1.4 → 0.1.5

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 CHANGED
@@ -31,6 +31,9 @@ or just
31
31
 
32
32
  ### Changelog
33
33
 
34
+ #### 0.1.4
35
+ - Ability to get season, name and episode based on folder, so we can parse something like this «Grey's anatomy - Season 1 Full - ENG/01-A hard day's night.srt»
36
+
34
37
  #### 0.1.3
35
38
  - RDoc + Refactoring
36
39
 
@@ -8,4 +8,10 @@ module Bathyscaphe
8
8
  end
9
9
  end
10
10
 
11
- Bathyscaphe.require_all_libs_relative_to(__FILE__)
11
+ Bathyscaphe.require_all_libs_relative_to(__FILE__)
12
+
13
+ class Object
14
+ def blank?
15
+ respond_to?(:empty?) ? empty? : !self
16
+ end
17
+ end
@@ -5,7 +5,11 @@ require 'yaml'
5
5
  CONFIG_FILENAME = File.expand_path("~/.config/bathyscaphe/bathyscaphe.conf")
6
6
 
7
7
  CONFIG_DEFAULTS = {
8
- :source => 'http://addic7ed.com'
8
+ :consumer_key => "",
9
+ :consumer_secret => "",
10
+ :oauth_token => "",
11
+ :oauth_token_secret => "",
12
+ :username => ""
9
13
  }
10
14
 
11
15
  module Bathyscaphe
@@ -16,12 +20,16 @@ module Bathyscaphe
16
20
  }
17
21
 
18
22
  def self.parse_options
23
+ options = {}
19
24
  optparser = OptionParser.new do |opts|
20
25
  opts.set_summary_indent(' ')
21
26
  opts.banner = "Usage: #{File.basename($0)} [OPTIONS] TV_SHOW"
22
27
  # opts.on( "-s", "--source SOURCE", String, "Set source to download subtitles from","Current: #{self.source}" ) { |o| self.source = o ; self.save }
23
28
  opts.on( "-d", "--dry-run", "Parse filename but do not download anything") { |o| OPTIONS[:dry_run] = o}
24
-
29
+ opts.on( "-v", "--version", "Show version") do
30
+ options[:version] = true
31
+ puts Bathyscaphe::VERSION
32
+ end
25
33
  opts.on_tail( "-h", "--help", "Show usage") do
26
34
  puts opts
27
35
  exit
@@ -31,7 +39,7 @@ module Bathyscaphe
31
39
  begin
32
40
  optparser.parse!
33
41
  if ARGV.empty?
34
- puts optparser
42
+ puts optparser unless options[:version]
35
43
  exit
36
44
  else
37
45
  tv_show = ARGV[0]
@@ -3,27 +3,45 @@ module Bathyscaphe
3
3
 
4
4
  TVREGEXP1 = /(.*)S([0-9]{2})E([0-9]{2}).*/i
5
5
  TVREGEXP2 = /(.*).([0-9]{1,2})x([0-9]{1,2}).*/i
6
+ TVREGEXP3 = /(.*)Season\s*([0-9]{1,2})\s*Episode\s*([0-9]{1,2}).*/i
7
+
8
+ TVREGEXP4 = /.*\/(.*)\/Season\s*([0-9]{1,2})\/([0-9]{1,2}).*/i
9
+ TVREGEXP5 = /.*\/(.*)\/Season\s*([0-9]{1,2})\/.*S(?:[0-9]{2})E([0-9]{2}).*/i
6
10
 
7
11
  attr_accessor :name, :season, :episode
8
12
 
9
13
  def initialize filename, filedir
10
- if md = filename.match(TVREGEXP1) || md = filename.match(TVREGEXP2)
11
- @name = md[1].gsub(".", " ").strip
12
- @name = "Castle" if @name =~ /Castle 2009/i
13
- @name = "Missing (2012)" if @name =~ /Missing 2012/i
14
- @season = md[2].to_i.to_s
15
- @episode = md[3].to_i.to_s
16
- elsif md = filedir.split("/").last.match(/(.*)Season(.*)/i)
14
+
15
+ wholefile = File.join(filedir, filename)
16
+ @name = @season = @episode = nil
17
+
18
+ if md = filename.match(TVREGEXP1) || md = filename.match(TVREGEXP2) || md = filename.match(TVREGEXP3)
19
+ @name, @season, @episode = get_from_md(md)
20
+ end
21
+ return unless [@name, @season, @episode].collect(&:blank?).any?
22
+
23
+ if md = wholefile.match(TVREGEXP4) || md = wholefile.match(TVREGEXP5)
24
+ @name, @season, @episode = get_from_md(md)
25
+ end
26
+ return unless [@name, @season, @episode].collect(&:blank?).any?
27
+
28
+ if md = filedir.split("/").last.match(/(.*)Season(.*)/i)
17
29
  @name = md[1].gsub(/[-.]+/i, ' ').gsub("'", '').strip
18
30
  @season = md[2].strip.scan(/^(\d+).*/).flatten.last.to_i.to_s
19
31
  if namemd = filename.match(/(\d*).*/)
20
32
  @episode = namemd[1].to_i.to_s
21
- else
22
- raise("Cant't parse filename")
23
33
  end
24
- else
25
- raise("Cant't parse filename")
26
34
  end
35
+
36
+ end
37
+
38
+ def get_from_md(md)
39
+ name = md[1].gsub(/[-.]+/i, " ").strip
40
+ name = "Castle" if name =~ /Castle 2009/i
41
+ name = "Missing (2012)" if name =~ /Missing 2012/i
42
+ season = md[2].to_i.to_s
43
+ episode = md[3].to_i.to_s
44
+ return name, season, episode
27
45
  end
28
46
  end
29
47
  end
@@ -1,3 +1,3 @@
1
1
  module Bathyscaphe
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bathyscaphe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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-05-25 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri