propre 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/bin/propre +57 -0
- data/lib/propre/prompt.rb +16 -0
- data/lib/propre/settings.rb +22 -0
- data/lib/propre/version.rb +3 -0
- data/lib/propre.rb +78 -0
- data/propre.gemspec +21 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d25a4e7bff95f3610260dbcd5425afaf660be986
|
4
|
+
data.tar.gz: 22cfa6385791d1be18b6aacb9a33466ec659e4e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00c7a34190609af81d96d3bfe3d610d62cf82837e59624f8169bc850b1c6d7c289d78c4f111820970eb77a18acef2e7cf17c8df81577e3cd2b8bd6d7ab6c11a4
|
7
|
+
data.tar.gz: 18caf7baa369ba3755c4fb0d36ff9b88a42634717f54a45a0dd9c6d31c932609fab16804a52060adee06ccb6383bc6201dc8f68bc521af13c41b22d53d4a3e90
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Propre
|
2
|
+
======
|
3
|
+
|
4
|
+
Introduction
|
5
|
+
------------
|
6
|
+
|
7
|
+
Propre is a handy tool written in Ruby to bulk rename your movies using TheMovieDB API.
|
8
|
+
|
9
|
+
Usage
|
10
|
+
-----
|
11
|
+
|
12
|
+
```
|
13
|
+
Usage: propre [OPTION]... SOURCE...
|
14
|
+
-R, --recursive Run recursively
|
15
|
+
-i, --interactive Run interactively
|
16
|
+
-V, --video-only Search for video files only
|
17
|
+
-s, --sanitize Sanitize filename before search
|
18
|
+
-d, --dotfile Don't ignore .dotfile
|
19
|
+
```
|
20
|
+
|
21
|
+
Changelog
|
22
|
+
---------
|
23
|
+
|
24
|
+
### 0.0.5
|
25
|
+
|
26
|
+
- Update directory structure to work with RubyGems
|
27
|
+
|
28
|
+
### 0.0.4
|
29
|
+
|
30
|
+
- Add params to consider .dotfile
|
31
|
+
- Add params to sanitize file before search
|
32
|
+
- Bugfix
|
33
|
+
|
34
|
+
Disclaimer
|
35
|
+
----------
|
36
|
+
|
37
|
+
This tool was made on my spare time, i'm not responsable of any damages caused to your files
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/propre
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'propre'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opt|
|
11
|
+
opt.banner = "Usage: #{ File.basename($0) } [OPTION]... SOURCE..."
|
12
|
+
|
13
|
+
opt.on('-R', '--recursive', 'Run recursively') do |v|
|
14
|
+
options[:recursive] = v
|
15
|
+
end
|
16
|
+
|
17
|
+
opt.on('-i', '--interactive', 'Run interactively') do |v|
|
18
|
+
options[:interactive] = v
|
19
|
+
end
|
20
|
+
|
21
|
+
opt.on('-V', '--video-only', 'Search for video files only') do |v|
|
22
|
+
options[:videonly] = v
|
23
|
+
end
|
24
|
+
|
25
|
+
opt.on('-s', '--sanitize', 'Sanitize filename before search') do |v|
|
26
|
+
options[:sanitize] = v
|
27
|
+
end
|
28
|
+
|
29
|
+
opt.on('-d', '--dotfile', 'Don\'t ignore .dotfile') do |v|
|
30
|
+
options[:dotfile] = v
|
31
|
+
end
|
32
|
+
|
33
|
+
options[:help] = opt.help
|
34
|
+
end.parse!
|
35
|
+
|
36
|
+
def main(options)
|
37
|
+
if ARGV.size < 1
|
38
|
+
puts options[:help]
|
39
|
+
else
|
40
|
+
propre = Propre.new(options)
|
41
|
+
if File.directory?(ARGV[0])
|
42
|
+
propre.crawlDirectory(ARGV[0])
|
43
|
+
end
|
44
|
+
|
45
|
+
if File.file?(ARGV[0])
|
46
|
+
propre.searchMovieFromFile(ARGV[0])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
main(options)
|
53
|
+
rescue Interrupt
|
54
|
+
puts "\nExiting..."
|
55
|
+
rescue StandardError => e
|
56
|
+
puts e
|
57
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'highline/import'
|
2
|
+
|
3
|
+
module Prompt
|
4
|
+
|
5
|
+
def Prompt.yesno(prompt = 'Continue?', default = false)
|
6
|
+
a = ''
|
7
|
+
s = default ? '[Y/n/s]' : '[y/N/s]'
|
8
|
+
d = default ? 'y' : 'n'
|
9
|
+
until %w[y n s].include? a
|
10
|
+
a = ask("#{prompt} #{s} ") { |q| q.limit = 1; q.case = :downcase }
|
11
|
+
a = d if a.length == 0
|
12
|
+
end
|
13
|
+
if a == 'y'; true elsif a == 's'; 'skip' else false end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'parseconfig'
|
3
|
+
|
4
|
+
class Settings
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
if !File.exist?(path) then FileUtils.touch(path) end
|
9
|
+
conf = YAML.load_file(path)
|
10
|
+
@settings = conf ? conf : Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(key)
|
14
|
+
@settings[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def set(key, value)
|
18
|
+
@settings[key] = value
|
19
|
+
File.open(@path, 'w') { |f| YAML.dump(@settings, f) }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/propre.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'propre/prompt'
|
2
|
+
require 'propre/settings'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'themoviedb'
|
6
|
+
require 'mime/types'
|
7
|
+
|
8
|
+
class Propre
|
9
|
+
include Prompt
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@options = options
|
13
|
+
@settings = Settings.new("#{Dir.home}/.config/Propre/settings.yaml")
|
14
|
+
if @settings.get('apikey').nil?
|
15
|
+
puts "It's seem you did not set your TMDB API Key, please tell me:"
|
16
|
+
@settings.set('apikey', STDIN.gets.chomp())
|
17
|
+
end
|
18
|
+
Tmdb::Api.key(@settings.get('apikey'))
|
19
|
+
Tmdb::Api.language(@settings.get('locale') ? @settings.get('locale') : 'en')
|
20
|
+
end
|
21
|
+
|
22
|
+
def crawlDirectory(path)
|
23
|
+
Dir.foreach(path) do |item|
|
24
|
+
next if item == '.' or item == '..'
|
25
|
+
if File.directory?(File.join(path, item))
|
26
|
+
if @options[:recursive] then self.crawlDirectory(File.join(path, item)) end
|
27
|
+
else
|
28
|
+
self.searchMovieFromFile(File.join(path, item))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def searchMovieFromFile(file)
|
34
|
+
@file = file
|
35
|
+
filename = File.basename(file,File.extname(file))
|
36
|
+
if @options[:videonly] && !video?(file)
|
37
|
+
return
|
38
|
+
end
|
39
|
+
if !@options[:dotfile] && filename.start_with?('.')
|
40
|
+
return
|
41
|
+
end
|
42
|
+
if @options[:sanitize] then filename = self.sanitize(filename) end
|
43
|
+
@movies = Tmdb::Movie.find(filename)
|
44
|
+
if self.confirm
|
45
|
+
File.rename(file, File.join(File.dirname(file), self.format(@selected)))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def confirm()
|
50
|
+
@selected = false
|
51
|
+
@movies.each do |movie|
|
52
|
+
answer = Prompt.yesno("#{File.basename(@file)} -> #{self.format(movie)}")
|
53
|
+
if answer === false; next ; elsif answer === 'skip'; puts "Skipping..."; return end
|
54
|
+
@selected = movie
|
55
|
+
break
|
56
|
+
end
|
57
|
+
if @selected then @selected end
|
58
|
+
end
|
59
|
+
|
60
|
+
def format(movie)
|
61
|
+
year = !movie.release_date.empty? ? Date.strptime(movie.release_date, "%Y-%m-%d").year : false
|
62
|
+
title = year ? "#{movie.title} (#{year})" : "#{movie.title}"
|
63
|
+
title.gsub! ':','-'
|
64
|
+
return "#{title}#{File.extname(@file)}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def sanitize(filename)
|
68
|
+
filename.downcase!
|
69
|
+
filename.gsub!(/\(.*\)/, '').gsub!("_", ' ').gsub!(".", ' ').strip!
|
70
|
+
warez = ["truefrench","fansub","bluray","720", "720p", "x264","french", "fr", "divx","hdcam","xvid","appz","bdrip","board","cam","dvd","dvd-r","dvdrip","dupecheck","fake","fs","gamez","hddvd","hddvdrip","hdrip","hdtv","pdtv","internal","int","keygen","leecher","limited","nuke","proper","repack","retail","rip","rip","screener","serial","subforced","hardsub","stv","telecine","telesync","tvrip","unrated","vhsrip","vo","vost","vostfr","workprint","french","wp","subbed","unsubbed", "r5", "r6", "md"]
|
71
|
+
(filename.split - warez).join(' ')
|
72
|
+
end
|
73
|
+
|
74
|
+
def video?(file)
|
75
|
+
MIME::Types[/^video/].include? MIME::Types.of(file)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/propre.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'propre/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.authors = ["Felix Yadomi"]
|
8
|
+
spec.email = ["dev.yadomi@gmail.com"]
|
9
|
+
|
10
|
+
spec.name = "propre"
|
11
|
+
spec.version = Propre::VERSION
|
12
|
+
spec.summary = %q{CLI tool to rename movies using TheMovieDB API }
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($\)
|
15
|
+
spec.executables = ['propre']
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
19
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: propre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felix Yadomi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-31 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
description:
|
42
|
+
email:
|
43
|
+
- dev.yadomi@gmail.com
|
44
|
+
executables:
|
45
|
+
- propre
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/propre
|
54
|
+
- lib/propre.rb
|
55
|
+
- lib/propre/prompt.rb
|
56
|
+
- lib/propre/settings.rb
|
57
|
+
- lib/propre/version.rb
|
58
|
+
- propre.gemspec
|
59
|
+
homepage:
|
60
|
+
licenses: []
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: CLI tool to rename movies using TheMovieDB API
|
82
|
+
test_files: []
|