where_to 0.8.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12bf21fc687263650e4128a20f20d66f58ff71a6
4
+ data.tar.gz: b6db02bb8a8946a39f91bee3372af3af4cc9c074
5
+ SHA512:
6
+ metadata.gz: b6a190544c2af1b93c48274e739cce60b7187f873f6546468919960b965208577e9baa713273959d6c238d6d9234eaa80ee1a966782d51781510847d8a89367c
7
+ data.tar.gz: 8cc37a1067116060f6fff99faa84ea807c0021c77870ceb5a58ea8e5bf1ef8f0920754948aa581f9d8f3706b99677ee3745b753bed621515cdd74202c7d4f16a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /coverage/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install:
5
+ gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in where_to.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # WhereTo
2
+ [![Build Status](https://travis-ci.org/jutonz/where_to.svg)](https://travis-ci.org/jutonz/where_to)
3
+ [![Coverage Status](https://coveralls.io/repos/jutonz/where_to/badge.svg?branch=master)](https://coveralls.io/r/jutonz/where_to?branch=master)
4
+
5
+ This gem helps you maintain a directory sturucture for your mediafiles. For example, if you specify the following about a set of video files:
6
+ * Series title: Game of Thrones
7
+ * Season: 5
8
+ * Season airdate: 2015
9
+
10
+ This program tells you that they should be located in a folder called `Game of Thrones/Season 5 (2015)/`. Of course you can customize this to match whatever file structure you prefer.
11
+
12
+ If you specify some more data:
13
+ * Episode title: What a great episode
14
+ * Episode number: 3
15
+
16
+ The program will also tell you that the episode should be called `game.of.thrones.S05E03.what.a.great.episode.mkv`
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem where_to, git: 'https://github.com/jutonz/where_to'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ require 'where_to'
34
+
35
+ # Specify data one at a time
36
+ locator = WhereTo::Locator.new
37
+ locator.series_title = 'Game of Thrones'
38
+ locator.season = 5
39
+ locator.season_airdate = 2015
40
+ locator.locate # WhereTo::Location object with 'Game of Thrones/Season 5 (2015)/'
41
+
42
+ # Specify data in a batch
43
+ data = {}
44
+ data[:series_title] = 'Game of Thrones'
45
+ data[:season] = 5
46
+ data[:season_airdate] = 2015
47
+ locator = WhereTo::Locator.new data
48
+ locator.locate
49
+
50
+ # Specify episode info
51
+ data = {}
52
+ data[:series_title] = 'Game of Thrones'
53
+ data[:season] = 5
54
+ data[:season_airdate] = 2015
55
+ data[:episode_title] = 'best episode ever'
56
+ data[:episode_number] = 3
57
+ locator = WhereTo::Locator.new data
58
+ location = locator.locate
59
+ location.folder # => Game of Thrones/Season 5 (2015)
60
+ location.filename # => game.of.thrones.S05E02.best.episode.ever.mkv
61
+
62
+ # You can specify custom file extensions
63
+ locator.episode_extension = '.mp4'
64
+ locator.locate.filename # => game.of.thrones.S05E02.best.episode.ever.mp4
65
+
66
+ # And if you like you can specify a video quality
67
+ locator.episode_quality = '720p'
68
+ locator.locate.filename # => game.of.thrones.S05E02.best.episode.ever.720p.mkv
69
+ ```
70
+
71
+ ## Custom Formats
72
+ Specify custom formats by modifying `format.yml`.
73
+ The default is `"%series_title/Season %season_number (%season_airdate)/"`, but in theory any combination works.
74
+
75
+ Right now you can't change the episode filename format, but we're working on it!
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+
83
+ ## Contributing
84
+
85
+ 1. Fork it ( https://github.com/jutonz/where_to/fork )
86
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
87
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
88
+ 4. Push to the branch (`git push origin my-new-feature`)
89
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :watch do
9
+ folders_to_watch = 'bin lib spec'
10
+ action_on_change = 'bundle exec rake'
11
+ begin
12
+ gem 'filewatcher'
13
+ sh "filewatcher '#{folders_to_watch}' '#{action_on_change}'"
14
+ rescue Gem::LoadError
15
+ puts 'You need to have the filewatcher gem installed to perform this task.'
16
+ puts 'Install with \'gem install filewatcher\''
17
+ end
18
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "where_to"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ module WhereTo
2
+ class EpisodeFormatter
3
+ attr_accessor :series_title, :season_number, :episode_title, :episode_number
4
+ attr_accessor :quality, :extension
5
+ DEFAULT_EXTENSION = '.mkv'
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])
8
+ set_unless_nil :series_title, series_title
9
+ set_unless_nil :season_number, season_number
10
+ set_unless_nil :episode_title, episode_title
11
+ set_unless_nil :episode_number, episode_number
12
+ set_unless_nil :quality, quality
13
+ set_unless_nil :extension, extension, default: DEFAULT_EXTENSION
14
+ end
15
+
16
+ def format!
17
+ validate!
18
+ formatted = []
19
+ formatted << series_title.downcase.gsub(' ', '.')
20
+ formatted << "SxxEyy".gsub('xx', season_number.to_s.rjust(2, '0')).gsub('yy', episode_number.to_s.rjust(2, '0'))
21
+ formatted << episode_title.downcase.gsub(' ', '.')
22
+ formatted << quality.downcase if quality
23
+ formatted << extension.gsub('.', '') # remove . so the join is easier
24
+ formatted.join('.')
25
+ end
26
+
27
+ def validate!
28
+ raise 'A series title is required to format an episode title.' unless series_title
29
+ raise 'A season number is required to format an episode title.' unless season_number
30
+ raise 'An episode title is required to format an episode title.' unless episode_title
31
+ raise 'An episode number is required to format an episode title.' unless episode_number
32
+ true
33
+ end
34
+
35
+ private
36
+
37
+ def set_unless_nil(key, value, default: nil)
38
+ if value
39
+ send("#{key}=".to_sym, value)
40
+ elsif default
41
+ send("#{key}=".to_sym, default)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ folder_format: "%series_title/Season %season_number (%season_airdate)/"
@@ -0,0 +1,30 @@
1
+ module WhereTo
2
+ class Location
3
+ include Comparable
4
+ attr_accessor :folder, :filename, :location
5
+
6
+ def initialize(from_location)
7
+ @location = from_location
8
+ set_filename_folder_from_location
9
+ end
10
+
11
+ def <=>(other)
12
+ location <=> other
13
+ end
14
+
15
+ private
16
+
17
+ def set_filename_folder_from_location
18
+ split = location.split '/'
19
+ last = split[-1]
20
+ if File.extname(last) == '' # No extension; is a directory
21
+ @folder = location + '/'
22
+ @filename = ''
23
+ else
24
+ @filename = split.pop
25
+ @folder = split.join('/') + '/'
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ require 'where_to/location'
2
+ require 'yaml'
3
+
4
+ module WhereTo
5
+ class Locator
6
+ attr_accessor :series_title, :airdate, :season, :season_airdate
7
+ attr_accessor :episode_title, :episode_number, :episode_quality, :episode_extension
8
+ FORMAT_FILE = 'lib/where_to/format.yml'
9
+
10
+ def initialize(hash = {})
11
+ load_values_from hash
12
+ @format_file = YAML.load_file FORMAT_FILE
13
+ end
14
+
15
+ def locate(hash = {})
16
+ load_values_from hash
17
+ validate!
18
+
19
+ output = @format_file['folder_format']
20
+ output.gsub! '%series_title', series_title
21
+ output.gsub! '%season_number', season.to_s
22
+ output.gsub! '%season_airdate', season_airdate.to_s
23
+
24
+ if episode_title and episode_number
25
+ formatter = WhereTo::EpisodeFormatter.new params
26
+ output << formatter.format!
27
+ end
28
+
29
+ WhereTo::Location.new output
30
+ end
31
+
32
+ def validate!
33
+ raise 'A season airdate is required to locate an episode' if season_airdate == nil
34
+ raise 'A season number is required to locate an episode' if season.nil?
35
+ true
36
+ end
37
+
38
+ def params
39
+ _params = {}
40
+ _params[:series_title] = series_title
41
+ _params[:season_number] = season
42
+ _params[:episode_title] = episode_title
43
+ _params[:episode_number] = episode_number
44
+ _params[:quality] = episode_quality
45
+ _params[:extension] = episode_extension
46
+ _params
47
+ end
48
+
49
+ private
50
+
51
+ def set_unless_nil(key, value)
52
+ send("#{key}=".to_sym, value) unless value.nil?
53
+ end
54
+
55
+ def load_values_from(hash = {})
56
+ set_unless_nil :series_title, hash[:series_title]
57
+ set_unless_nil :airdate, hash[:airdate]
58
+ set_unless_nil :season, hash[:season]
59
+ set_unless_nil :season_airdate, hash[:season_airdate]
60
+ set_unless_nil :episode_title, hash[:episode_title]
61
+ set_unless_nil :episode_number, hash[:episode_number]
62
+ set_unless_nil :episode_quality, hash[:episode_quality]
63
+ set_unless_nil :episode_extension, hash[:episode_extension]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module WhereTo
2
+ VERSION = "0.8.0"
3
+ end
data/lib/where_to.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'where_to/version'
2
+ require 'where_to/location'
3
+
4
+ module WhereTo
5
+
6
+ end
data/where_to.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'where_to/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "where_to"
8
+ spec.version = WhereTo::VERSION
9
+ spec.authors = ["Justin Toniazzo"]
10
+ spec.email = ["jutonz42@gmail.com"]
11
+
12
+ spec.license = 'MIT'
13
+
14
+ spec.summary = "Helps preserve a folder structure for mediafiles"
15
+ spec.homepage = "https://github.com/jutonz/where_to"
16
+
17
+ 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
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "simplecov", "~> 0.10.0"
25
+ spec.add_development_dependency "coveralls", "~> 0.8.1"
26
+ spec.add_development_dependency "rspec", "~> 3.2"
27
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: where_to
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Toniazzo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ description:
84
+ email:
85
+ - jutonz42@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/where_to.rb
99
+ - lib/where_to/episode_formatter.rb
100
+ - lib/where_to/format.yml
101
+ - lib/where_to/location.rb
102
+ - lib/where_to/locator.rb
103
+ - lib/where_to/version.rb
104
+ - where_to.gemspec
105
+ homepage: https://github.com/jutonz/where_to
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Helps preserve a folder structure for mediafiles
129
+ test_files: []