where_to 0.9.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWI4YjlkZjYzNGRjNjEyNGYyNzhjMGVlYjE0Y2RkZmYyMWUzZDk4ZQ==
4
+ NmY0ZmI3NzkxOWZmZjVmYzg3MGZkN2U1NjlhZTU1MjBlNGU2NGU1Zg==
5
5
  data.tar.gz: !binary |-
6
- OTQ3OTY3YzZjMzQ5OTJjNTBjNDIyYzk0M2JmMWMzNGFmZTY2NjlhYQ==
6
+ ODgwMTY4YjM1ZmIwOTJkZTVhYWQ0ZjE3NmY4YzYwNDBhZDcxMjk4ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTRjMDA0YWM2MDYyMzk3MDhhOTA2ZTNjODk2ZDA3Njk2ZGU2NWViYzkyMzc5
10
- MDdkMTk3Y2Q1NDFhZjA0MDNmNDAyODJlNWU2MGNjODA4OWE0MzA4Nzc0MTlk
11
- ZTBlYjU0ODhkM2FhYjg2M2NhNDk3NTI2NGJjNWJkMmY1NmFmYmU=
9
+ MGRmNzZkYjY2NTlmMDY1MmE1NmJlNWVkMDVmYTZiMWNmMTdkODcwNmJjNzkw
10
+ OTA2NTA2MzJiMDExZTE4YzA4Y2QyYTY4ZWZlMzI1NjRlZGI1YTM0NTEzMWY5
11
+ MjJmMDE1ZWNlNzIwYzE4ZjVlMzM3MGZhOTE0NmNmMzljYzQ5YTk=
12
12
  data.tar.gz: !binary |-
13
- MDYxMTcxOTc0ZDM0MzRmZDM1NzU0M2Q3ZjNjZDI4NWQ4NWZjM2E2OTVhMDc4
14
- NjkzYjBiZjliYTM0OGZkZDFhYTc3NTMyYzFjM2Q0MmE4NmM2YTc0MTU1ZmZl
15
- NTc4YTNkOGE3MzFkMTU0Y2I1NTY5ZTZjMzY0NTBjMDQ1Nzk4Y2Y=
13
+ MGEyMDJhZTY0MzhkYmFhNGQwZGJlZWZmYWViMjhjNGE5Njg1ODI3MWQxNjk3
14
+ YmQwMmNiMmNmYmJlZDRkOWM0Yjg1ZDVkYWRiMjM4YzJlNjcyNDlkMWFkNmQw
15
+ YjI2YjcwZmY5ZTE3MDEzM2M0YTczMzJjMWVmYzQ0YmNmZTEwYjU=
data/Rakefile CHANGED
@@ -5,6 +5,12 @@ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task default: :spec
7
7
 
8
+ namespace :parallel do
9
+ task :spec do
10
+ sh "parallel_rspec spec/"
11
+ end
12
+ end
13
+
8
14
  task :watch do
9
15
  folders_to_watch = 'bin lib spec'
10
16
  action_on_change = 'bundle exec rake'
@@ -15,4 +21,4 @@ task :watch do
15
21
  puts 'You need to have the filewatcher gem installed to perform this task.'
16
22
  puts 'Install with \'gem install filewatcher\''
17
23
  end
18
- end
24
+ end
data/bin/whereto ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require_relative '../lib/where_to'
4
+
5
+ include GLI::App
6
+
7
+ PROMPT_DESCRIPTORS = Hash.new do |hash, key|
8
+ hash[key] = "a #{key}"
9
+ end
10
+
11
+ PROMPT_DESCRIPTORS[:episode_number] = 'an episode number'
12
+ PROMPT_DESCRIPTORS[:episode_title] = 'an episode title'
13
+
14
+ # PROMPT_DESCRIPTORS.freeze
15
+
16
+ program_desc 'Helps you organize your media library by enforcing a consistent directory structure.'
17
+
18
+ version WhereTo::VERSION
19
+
20
+ subcommand_option_handling :normal
21
+ arguments :strict
22
+
23
+ desc 'Enforce a file structure on the specified file or directory'
24
+ arg_name 'location'
25
+ command :organize do |cmd|
26
+
27
+ cmd.desc 'Set the name of the series (will otherwise be prompted to enter)'
28
+ cmd.arg_name 'series_title'
29
+ cmd.default_value nil
30
+ cmd.flag [:s, :series]
31
+
32
+ cmd.desc 'Set the season number'
33
+ cmd.arg_name 'season_number'
34
+ cmd.default_value nil
35
+ cmd.flag [:n, :season]
36
+
37
+ cmd.desc 'Set the TVDB season id'
38
+ cmd.arg_name 'series_id'
39
+ cmd.default_value nil
40
+ cmd.flag [:i, :series_id]
41
+
42
+ # cmd.desc 'Set the series airdate'
43
+ # cmd.arg_name 'season_airdate'
44
+ # cmd.default_value nil
45
+ # cmd.flag [:a, :airdate]
46
+
47
+ cmd.desc 'Only look for files with the given extension'
48
+ cmd.arg_name 'extname'
49
+ cmd.default_value '.mkv'
50
+ cmd.flag [:e, :ext]
51
+
52
+ cmd.desc "Run normally, but don't actually perform renames"
53
+ cmd.default_value false
54
+ cmd.switch :dryrun, negatable: false
55
+
56
+ cmd.action do |global_options, options, args|
57
+ puts ''
58
+ location = args[0]
59
+ raise "The location '#{location}' does not exist" unless File.exist? location
60
+
61
+ @options = options
62
+
63
+ Dir.chdir location
64
+ files = Dir.glob "*#{options[:ext]}"
65
+ puts "I found the following files:"
66
+ files.each { |file| puts file }
67
+ puts ''
68
+
69
+ WhereTo.configure do |config|
70
+ config.tvdb_api_key = ENV['TVDB_API_KEY']
71
+ end
72
+
73
+ process files
74
+
75
+ end
76
+
77
+ end
78
+
79
+ def process(files)
80
+ locator = WhereTo::Locator.new series_id: @options[:series_id]
81
+ locator.episode_number = 0
82
+ locator.series_title = prompt_for :series_title, default: locator.series_title
83
+
84
+ files.sort.each do |file|
85
+ puts ''
86
+ puts "For file #{file}:"
87
+
88
+ %i{season episode_number group}.each do |field|
89
+ locator.send("#{field}=", prompt_for(field, default: locator.send(field)))
90
+ end
91
+
92
+ locator.lookup!
93
+ locator.episode_title = prompt_for :episode_title, default: locator.episode_title
94
+
95
+ new_file = locator.locate.filename
96
+ puts "New filename: #{new_file}"
97
+
98
+ if not @options[:dryrun]
99
+ rename file, to: new_file
100
+ else
101
+ puts 'Skipping rename because of dryrun flag'
102
+ end
103
+
104
+ end
105
+ end
106
+
107
+ def rename(from, to:)
108
+ print 'Renaming...'
109
+ FileUtils.mv from, to unless from == to
110
+ puts 'success!'
111
+ end
112
+
113
+ def prompt_for(option, default: nil)
114
+ prompt = "Enter #{PROMPT_DESCRIPTORS[option]}"
115
+ prompt += " (or press enter for #{default})" unless default.nil?
116
+ prompt += ': '
117
+ print prompt
118
+ input = STDIN.gets.chomp
119
+ input.empty? ? default : input
120
+ end
121
+
122
+ pre do |global,command,options,args|
123
+ # Pre logic here
124
+ # Return true to proceed; false to abort and not call the
125
+ # chosen command
126
+ # Use skips_pre before a command to skip this block
127
+ # on that command only
128
+ true
129
+ end
130
+
131
+ post do |global,command,options,args|
132
+ # Post logic here
133
+ # Use skips_post before a command to skip this
134
+ # block on that command only
135
+ end
136
+
137
+ on_error do |exception|
138
+ # Error logic here
139
+ # return false to skip default error handling
140
+ true
141
+ end
142
+
143
+ exit run(ARGV)
@@ -4,7 +4,7 @@ module WhereTo
4
4
  attr_accessor :quality, :extension, :group
5
5
  DEFAULT_EXTENSION = '.mkv'
6
6
 
7
- def initialize(hash = {}, series_title: hash[:series_title], season_number: hash[:season_number], episode_title: hash[:episode_title], episode_number: hash[:episode_number], extension: hash[:extension], quality: hash[:quality], group: hash[:group])
7
+ def initialize(hash = {}, series_title: hash[:series_title], season_number: hash[:season_number], episode_title: hash[:episode_title], episode_number: hash[:episode_number], extension: hash[:extension], quality: hash[:quality], group: hash[:group], series_id: hash[:series_id])
8
8
  set_unless_nil :series_title, series_title
9
9
  set_unless_nil :season_number, season_number
10
10
  set_unless_nil :episode_title, episode_title
@@ -48,4 +48,4 @@ module WhereTo
48
48
  end
49
49
 
50
50
  end
51
- end
51
+ end
@@ -1,14 +1,17 @@
1
- require 'where_to/location'
2
- require 'where_to/configuration'
1
+ require_relative 'location'
2
+ require_relative 'configuration'
3
3
  require 'yaml'
4
4
 
5
5
  module WhereTo
6
6
  class Locator
7
7
  attr_accessor :series_title, :airdate, :season, :season_airdate
8
- attr_accessor :episode_title, :episode_number, :episode_quality, :episode_extension, :group
8
+ attr_accessor :episode_title, :episode_number, :episode_quality, :episode_extension, :group, :series_id
9
9
 
10
10
  def initialize(hash = {})
11
11
  load_values_from hash
12
+ if series_id
13
+ @series_title = WhereTo::TVDB.new(params).lookup_series(series_id).name
14
+ end
12
15
  end
13
16
 
14
17
  def locate(hash = {})
@@ -48,6 +51,7 @@ module WhereTo
48
51
  _params[:quality] = episode_quality
49
52
  _params[:extension] = episode_extension
50
53
  _params[:group] = group
54
+ _params[:series_id] = series_id
51
55
  _params
52
56
  end
53
57
 
@@ -58,15 +62,16 @@ module WhereTo
58
62
  end
59
63
 
60
64
  def load_values_from(hash = {})
61
- set_unless_nil :series_title, hash[:series_title]
62
- set_unless_nil :airdate, hash[:airdate]
63
- set_unless_nil :season, hash[:season]
64
- set_unless_nil :season_airdate, hash[:season_airdate]
65
- set_unless_nil :episode_title, hash[:episode_title]
66
- set_unless_nil :episode_number, hash[:episode_number]
67
- set_unless_nil :episode_quality, hash[:episode_quality]
65
+ set_unless_nil :series_title, hash[:series_title]
66
+ set_unless_nil :airdate, hash[:airdate]
67
+ set_unless_nil :season, hash[:season]
68
+ set_unless_nil :season_airdate, hash[:season_airdate]
69
+ set_unless_nil :episode_title, hash[:episode_title]
70
+ set_unless_nil :episode_number, hash[:episode_number]
71
+ set_unless_nil :episode_quality, hash[:episode_quality]
68
72
  set_unless_nil :episode_extension, hash[:episode_extension]
69
- set_unless_nil :group, hash[:group]
73
+ set_unless_nil :group, hash[:group]
74
+ set_unless_nil :series_id, hash[:series_id]
70
75
  end
71
76
  end
72
- end
77
+ end
data/lib/where_to/tvdb.rb CHANGED
@@ -11,11 +11,14 @@ module WhereTo
11
11
  @db = TvdbParty::Search.new api_key
12
12
  end
13
13
 
14
+ # Probably split into lookup_season, lookup_episode (which lazy instantiate)
15
+ # and lookup_season!, lookup_episode! (which force db hit):w
14
16
  def lookup!
15
17
  validate!
16
18
  results = @db.search(series_title).first unless series_id
17
19
  series = @db.get_series_by_id (series_id || results['seriesid'])
18
20
  episode = series.get_episode season, episode_number
21
+ raise "It doesn't look like the series #{series.name} has an episode #{episode_number} for season #{season}" unless episode
19
22
  @episode_title = episode.name
20
23
  @season_airdate = episode.air_date.year
21
24
 
@@ -27,8 +30,12 @@ module WhereTo
27
30
  raise 'You need to configure your TVDB API key before looking up episode information'
28
31
  end
29
32
 
33
+ def lookup_series(series_id)
34
+ @db.get_series_by_id series_id
35
+ end
36
+
30
37
  def validate!
31
- raise 'A series title is required to lookup episode information' if series_title.nil?
38
+ raise 'A series title is required to lookup episode information' if series_title.nil? && series_id.nil?
32
39
  raise 'An episode number is required to lookup episode information' if episode_number.nil?
33
40
  raise 'A season number is required to lookup episode information' if season.nil?
34
41
  true
@@ -50,6 +57,7 @@ module WhereTo
50
57
  set_unless_nil :episode_number, hash[:episode_number]
51
58
  set_unless_nil :episode_quality, hash[:episode_quality]
52
59
  set_unless_nil :episode_extension, hash[:episode_extension]
60
+ set_unless_nil :series_id, hash[:series_id]
53
61
  end
54
62
  end
55
- end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module WhereTo
2
- VERSION = "0.9.6"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/where_to.rb CHANGED
@@ -1,9 +1,7 @@
1
- require 'where_to/version'
2
- require 'where_to/locator'
3
- require 'where_to/location'
4
- require 'where_to/configuration'
5
- require 'where_to/episode_formatter'
6
- require 'where_to/tvdb'
1
+ require 'date'
2
+
3
+ # Require all the libraries!
4
+ Dir[File.dirname(__FILE__) + "/where_to/**/*.rb"].each { |f| require_relative f }
7
5
 
8
6
  module WhereTo
9
7
  class << self
data/where_to.gemspec CHANGED
@@ -14,16 +14,20 @@ Gem::Specification.new do |spec|
14
14
  spec.summary = "Helps preserve a folder structure for mediafiles"
15
15
  spec.homepage = "https://github.com/jutonz/where_to"
16
16
 
17
+ spec.platform = Gem::Platform::RUBY
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
19
  spec.require_paths = ["lib"]
20
+ spec.bindir = "bin"
21
+ spec.executables << "whereto"
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.9"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
25
  spec.add_development_dependency "simplecov", "~> 0.10.0"
25
26
  spec.add_development_dependency "coveralls", "~> 0.8.1"
26
27
  spec.add_development_dependency "rspec", "~> 3.2"
28
+ spec.add_development_dependency "parallel_tests", "~> 1.5"
27
29
 
28
30
  spec.add_dependency "tvdb_party", "~> 0.8.0"
31
+
32
+ spec.add_runtime_dependency "gli", "2.13.1"
29
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: where_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Toniazzo
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-20 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: parallel_tests
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.5'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: tvdb_party
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,10 +108,25 @@ dependencies:
94
108
  - - ~>
95
109
  - !ruby/object:Gem::Version
96
110
  version: 0.8.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: gli
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.13.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.13.1
97
125
  description:
98
126
  email:
99
127
  - jutonz42@gmail.com
100
- executables: []
128
+ executables:
129
+ - whereto
101
130
  extensions: []
102
131
  extra_rdoc_files: []
103
132
  files:
@@ -109,6 +138,7 @@ files:
109
138
  - Rakefile
110
139
  - bin/console
111
140
  - bin/setup
141
+ - bin/whereto
112
142
  - lib/where_to.rb
113
143
  - lib/where_to/configuration.rb
114
144
  - lib/where_to/episode_formatter.rb