legendario 0.1.13 → 0.2.1
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 +4 -4
- data/Gemfile +5 -5
- data/README.md +26 -7
- data/bin/console +3 -2
- data/bin/crawl4subs +32 -0
- data/bin/lang4subs +32 -0
- data/bin/watch4subs +38 -0
- data/legendario.gemspec +1 -1
- data/lib/crawler.rb +43 -0
- data/lib/language.rb +39 -0
- data/lib/legendario/version.rb +1 -1
- data/lib/os.rb +55 -0
- data/lib/settings.rb +8 -0
- data/lib/watcher.rb +35 -0
- metadata +14 -11
- data/bin/crawl4subtitles +0 -55
- data/bin/legendario +0 -6
- data/bin/subtitle_language_switch +0 -82
- data/lib/legendario.rb +0 -118
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd8a9975ec2beda2be1d17c4173b2ffe7148d4f1
|
4
|
+
data.tar.gz: 915b0d8dfba973c58d5260d52de8b393c04e9686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c517199f9babe93ff4fe77643474793061a36690efd57a5ba480365e8774868789479cac11de78be4a04070a56cdfdb63bfdb9a8a786d6c22694b749963601a3
|
7
|
+
data.tar.gz: 5e293f9b35567dc7be510025a15dcafed486141046469916e7b06ba4cabca0627ad3be8daa42041f6124914a1bfe7ef6ab72dc71b69e1a9f6d3ab61d300b28d8
|
data/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gem "file-monitor", "~> 0.1"
|
3
|
+
gem "awesome_print", "~> 1.6"
|
4
|
+
gem "logging", "~> 2.0"
|
5
|
+
#Specify your gem's dependencies in legendario.gemspec
|
data/README.md
CHANGED
@@ -11,23 +11,43 @@ Install it yourself as:
|
|
11
11
|
|
12
12
|
$ gem install legendario
|
13
13
|
|
14
|
-
## Usage
|
15
14
|
|
15
|
+
## Tools
|
16
|
+
|
17
|
+
There are 3 tools at the moment:
|
18
|
+
|
19
|
+
crawl4subs: Will download the subtitles of the movies inside a parent folder recursively.
|
20
|
+
|
21
|
+
watch4subs: Watches a folder for new movies and downloads the subtitles as soon as the movie finishes downloading.
|
22
|
+
|
23
|
+
lang4subs: Change the default language of all the movies in a parent folder recursively.
|
24
|
+
|
25
|
+
|
26
|
+
In case you are a polyglot you can pass as many languages as you like as parameters. The first language available for the movie will be set as the default language for the movie.
|
16
27
|
|
17
|
-
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Download subtitles in English and Portuguese for all the movies
|
18
31
|
|
19
|
-
$
|
32
|
+
$ crawl4subs "folder-with-movies" eng por
|
20
33
|
|
21
34
|
for example.
|
22
35
|
|
23
36
|
Default languages are: eng por spa ger on this sequence of priority. [Sub language ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) code like fre or eng.
|
24
37
|
|
25
|
-
|
38
|
+
### Lay back and let watch4subs do all the work for you. As soon a new movie arrives it will download the subtitles for it.
|
26
39
|
|
27
|
-
|
40
|
+
Edit your rc.local file to start watch4subs after boot
|
41
|
+
|
42
|
+
su (username) -lc "watch4subs folder-with-movies subs-langs"
|
28
43
|
|
29
44
|
Example
|
30
|
-
`su evandro -lc "
|
45
|
+
`su evandro -lc "watch4subs /home/evandro/Downloads por spa"`
|
46
|
+
|
47
|
+
|
48
|
+
### Change the languages of the subtitles
|
49
|
+
|
50
|
+
$ lang4subs "folder-with-movies" spa por
|
31
51
|
|
32
52
|
|
33
53
|
Bug reports and pull requests are welcome on GitHub at https://github.com/evandrojr/legendario. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
@@ -36,4 +56,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/evandr
|
|
36
56
|
## License
|
37
57
|
|
38
58
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
-
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require "bundler/setup"
|
4
|
-
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
require 'legendario'
|
5
|
+
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
data/bin/crawl4subs
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
require 'crawler'
|
5
|
+
require 'settings'
|
6
|
+
|
7
|
+
if ARGV.size == 0
|
8
|
+
Sl.error 'The parent folder that will have the language changed is mandatory'
|
9
|
+
puts ''
|
10
|
+
puts 'Please, try something like: '
|
11
|
+
puts ''
|
12
|
+
puts 'crawl4subs "foldername" eng por '
|
13
|
+
puts ''
|
14
|
+
puts 'for example.'
|
15
|
+
puts ''
|
16
|
+
puts 'Default languages are: eng por spa ger on this sequence of priority'
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
Settings.dir = ARGV[0]
|
21
|
+
langs = ["eng", "por", "spa", "ger"]
|
22
|
+
langs = [] if ARGV.size > 1
|
23
|
+
c = 0
|
24
|
+
ARGV.each do|lang|
|
25
|
+
langs << lang if c > 0
|
26
|
+
c+=1
|
27
|
+
end
|
28
|
+
Settings.langs = langs
|
29
|
+
Sl.info "The first language found will be set to the subtitle file"
|
30
|
+
Sl.info Settings.langs.join(" ")
|
31
|
+
|
32
|
+
Legendario::Crawler.new.crawl
|
data/bin/lang4subs
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
require 'language'
|
5
|
+
require 'settings'
|
6
|
+
|
7
|
+
if ARGV.size == 0
|
8
|
+
Sl.error 'The parent folder that will have the language changed is mandatory'
|
9
|
+
puts ''
|
10
|
+
puts 'Please, try something like: '
|
11
|
+
puts ''
|
12
|
+
puts 'lang4subs "foldername" eng por '
|
13
|
+
puts ''
|
14
|
+
puts 'for example.'
|
15
|
+
puts ''
|
16
|
+
puts 'Default languages are: eng por spa ger on this sequence of priority'
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
Settings.dir = ARGV[0]
|
21
|
+
langs = ["eng", "por", "spa", "ger"]
|
22
|
+
langs = [] if ARGV.size > 1
|
23
|
+
c = 0
|
24
|
+
ARGV.each do|lang|
|
25
|
+
langs << lang if c > 0
|
26
|
+
c+=1
|
27
|
+
end
|
28
|
+
Settings.langs = langs
|
29
|
+
Sl.info "The first language found will be set as Language for the movie"
|
30
|
+
Sl.info Settings.langs.join(" ")
|
31
|
+
|
32
|
+
Legendario::Language.new.set_lang
|
data/bin/watch4subs
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
require 'watcher'
|
5
|
+
require 'settings'
|
6
|
+
|
7
|
+
if ARGV.size == 0
|
8
|
+
Sl.error 'The folder that will be watched for new movies should be defined'
|
9
|
+
puts ''
|
10
|
+
puts 'Please, try something like: '
|
11
|
+
puts ''
|
12
|
+
puts 'legendario "foldername" eng por '
|
13
|
+
puts ''
|
14
|
+
puts 'for example.'
|
15
|
+
puts ''
|
16
|
+
puts 'Default languages are: eng por spa ger on this sequence of priority'
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
Settings.dir = ARGV[0]
|
21
|
+
langs = ["eng", "por", "spa", "ger"]
|
22
|
+
langs = [] if ARGV.size > 1
|
23
|
+
c = 0
|
24
|
+
ARGV.each do|lang|
|
25
|
+
langs << lang if c > 0
|
26
|
+
c+=1
|
27
|
+
end
|
28
|
+
Settings.langs = langs
|
29
|
+
Sl.info "Will look for subtitles on these languages: "
|
30
|
+
Sl.info Settings.langs.join(" ")
|
31
|
+
|
32
|
+
100.times do
|
33
|
+
begin
|
34
|
+
Legendario::Watcher.new.watch_dirs
|
35
|
+
rescue => error
|
36
|
+
Sl.error error.inspect
|
37
|
+
end
|
38
|
+
end
|
data/legendario.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
25
|
spec.bindir = "bin"
|
26
|
-
spec.executables = ["
|
26
|
+
spec.executables = ["watch4subs", "crawl4subs", "lang4subs"]
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.10"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/crawler.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'find'
|
3
|
+
require 'sl'
|
4
|
+
require 'settings'
|
5
|
+
require 'os'
|
6
|
+
|
7
|
+
module Legendario
|
8
|
+
|
9
|
+
class Crawler
|
10
|
+
|
11
|
+
def crawl
|
12
|
+
default_changed = 0
|
13
|
+
Find.find(Settings.dir) do |path|
|
14
|
+
leave = false
|
15
|
+
if FileTest.directory?(path)
|
16
|
+
if File.basename(path)[0] == ?.
|
17
|
+
Find.prune # Don't look any further into this directory.
|
18
|
+
else
|
19
|
+
next
|
20
|
+
end
|
21
|
+
else
|
22
|
+
if /\.mkv$|\.mp4$|\.avi$/i =~ path
|
23
|
+
Settings.langs.each do |lang|
|
24
|
+
Sl.info "Downloading #{File.basename(path)} on #{lang}"
|
25
|
+
Os.download_subs(path)
|
26
|
+
end
|
27
|
+
Settings.langs.each do |lang|
|
28
|
+
Os.delete_video_default_subtitle(path) if Os.check_for_sub(path, lang)
|
29
|
+
# Will to it just for the 1st time
|
30
|
+
if Os.make_default_subtitle(path, lang)
|
31
|
+
Sl.info "Setting #{File.basename(path)} to #{lang}"
|
32
|
+
default_changed += 1
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
Sl.info "#{default_changed} movie's language changed"
|
40
|
+
end
|
41
|
+
|
42
|
+
end # class
|
43
|
+
end # module
|
data/lib/language.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'find'
|
3
|
+
require 'sl'
|
4
|
+
require 'settings'
|
5
|
+
require 'os'
|
6
|
+
|
7
|
+
module Legendario
|
8
|
+
|
9
|
+
class Language
|
10
|
+
|
11
|
+
def set_lang
|
12
|
+
default_changed = 0
|
13
|
+
Find.find(Settings.dir) do |path|
|
14
|
+
leave = false
|
15
|
+
if FileTest.directory?(path)
|
16
|
+
if File.basename(path)[0] == ?.
|
17
|
+
Find.prune # Don't look any further into this directory.
|
18
|
+
else
|
19
|
+
next
|
20
|
+
end
|
21
|
+
else
|
22
|
+
if /\.mkv$|\.mp4$|\.avi$/i =~ path
|
23
|
+
Settings.langs.each do |lang|
|
24
|
+
Os.delete_video_default_subtitle(path) if Os.check_for_sub(path, lang)
|
25
|
+
# Will to it just for the 1st time
|
26
|
+
if Os.make_default_subtitle(path, lang)
|
27
|
+
Sl.info "Setting #{File.basename(path)} to #{lang}"
|
28
|
+
default_changed += 1
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
Sl.info "#{default_changed} movie's language changed"
|
36
|
+
end
|
37
|
+
|
38
|
+
end # class
|
39
|
+
end # module
|
data/lib/legendario/version.rb
CHANGED
data/lib/os.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class Os
|
2
|
+
|
3
|
+
class << self
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
def default_movie_subtitle(path)
|
7
|
+
path.sub(/#{File.extname(path)}$/i, '.srt')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Receives the path of a movie file and deletes its subtitle
|
11
|
+
def delete_video_default_subtitle(path)
|
12
|
+
subtitle_file = default_movie_subtitle(path)
|
13
|
+
rm(subtitle_file) if File.exist?(subtitle_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_default_subtitle(path, lang)
|
17
|
+
# path = /tmp/a.avi
|
18
|
+
# lang = por
|
19
|
+
# /tmp/a.por.srt
|
20
|
+
default_sub = default_movie_subtitle(path)
|
21
|
+
specific_sub = path.sub(/#{File.extname(path)}$/i, ".#{lang}.srt")
|
22
|
+
if File.exist?(specific_sub) and !File.exist?(default_sub)
|
23
|
+
Sl.info "cp #{File.basename(specific_sub)} to #{File.basename(default_sub)}"
|
24
|
+
cp specific_sub, default_sub
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_for_sub(path, lang)
|
31
|
+
File.exist?(path.sub(/#{File.extname(path)}$/i, ".#{lang}.srt"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def download_subs(file)
|
35
|
+
delete_video_default_subtitle(file)
|
36
|
+
Settings.langs.each do |lang|
|
37
|
+
Sl.info "Language: #{lang}"
|
38
|
+
se("getsub -aLl #{lang} \"#{file}\"")
|
39
|
+
# Will to it just for the 1st time
|
40
|
+
make_default_subtitle(file, lang)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# Shell execute
|
46
|
+
def se(command)
|
47
|
+
o = `#{command}`
|
48
|
+
r = $?.to_i
|
49
|
+
Sl.debug "#{o} #{r}"
|
50
|
+
r
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/settings.rb
ADDED
data/lib/watcher.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'file-monitor'
|
3
|
+
require 'find'
|
4
|
+
require 'sl'
|
5
|
+
require 'settings'
|
6
|
+
require 'os'
|
7
|
+
|
8
|
+
module Legendario
|
9
|
+
|
10
|
+
class Watcher
|
11
|
+
|
12
|
+
def watch_dirs
|
13
|
+
FileMonitor.watch Settings.dir do
|
14
|
+
dirs {
|
15
|
+
disallow /\.git$/
|
16
|
+
}
|
17
|
+
|
18
|
+
files {
|
19
|
+
disallow /.*/
|
20
|
+
allow /\.mkv$|\.mp4$|\.avi$/
|
21
|
+
}
|
22
|
+
exec do |events|
|
23
|
+
events.each do |ev|
|
24
|
+
file = File.join(ev.watcher.path(), ev.name())
|
25
|
+
if File.exist?(file)
|
26
|
+
Sl.info file
|
27
|
+
Os.download_subs(file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end # class
|
35
|
+
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: legendario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evandro Junior
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,9 +98,9 @@ description: The script downloads subtitles when a new movie is put to a defined
|
|
98
98
|
email:
|
99
99
|
- evandrojr@gmail.com
|
100
100
|
executables:
|
101
|
-
-
|
102
|
-
-
|
103
|
-
-
|
101
|
+
- watch4subs
|
102
|
+
- crawl4subs
|
103
|
+
- lang4subs
|
104
104
|
extensions: []
|
105
105
|
extra_rdoc_files: []
|
106
106
|
files:
|
@@ -114,14 +114,18 @@ files:
|
|
114
114
|
- README.md
|
115
115
|
- Rakefile
|
116
116
|
- bin/console
|
117
|
-
- bin/
|
118
|
-
- bin/
|
117
|
+
- bin/crawl4subs
|
118
|
+
- bin/lang4subs
|
119
119
|
- bin/setup
|
120
|
-
- bin/
|
120
|
+
- bin/watch4subs
|
121
121
|
- legendario.gemspec
|
122
|
-
- lib/
|
122
|
+
- lib/crawler.rb
|
123
|
+
- lib/language.rb
|
123
124
|
- lib/legendario/version.rb
|
125
|
+
- lib/os.rb
|
126
|
+
- lib/settings.rb
|
124
127
|
- lib/sl.rb
|
128
|
+
- lib/watcher.rb
|
125
129
|
homepage: https://github.com/evandrojr/legendario
|
126
130
|
licenses:
|
127
131
|
- MIT
|
@@ -143,9 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
147
|
version: '0'
|
144
148
|
requirements: []
|
145
149
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.4.8
|
147
151
|
signing_key:
|
148
152
|
specification_version: 4
|
149
153
|
summary: Subtitles downloader on demand.
|
150
154
|
test_files: []
|
151
|
-
has_rdoc:
|
data/bin/crawl4subtitles
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'find'
|
3
|
-
|
4
|
-
d = "/home/j/Downloads"
|
5
|
-
lang=[]
|
6
|
-
lang=["eng", "por", "spa", "ger"]
|
7
|
-
lang.each do |l|
|
8
|
-
puts "Language: #{l}"
|
9
|
-
c = "getsub -aLl #{l} #{d}"
|
10
|
-
puts c
|
11
|
-
o = `#{c}`
|
12
|
-
puts o
|
13
|
-
r = $?.to_i
|
14
|
-
puts r
|
15
|
-
end
|
16
|
-
|
17
|
-
total_size = 0
|
18
|
-
total_files = 0
|
19
|
-
|
20
|
-
Find.find(d) do |path|
|
21
|
-
if FileTest.directory?(path)
|
22
|
-
if File.basename(path)[0] == ?.
|
23
|
-
Find.prune # Don't look any further into this directory.
|
24
|
-
else
|
25
|
-
next
|
26
|
-
end
|
27
|
-
else
|
28
|
-
if FileTest.symlink?(path)
|
29
|
-
c = "rm \"#{path}\""
|
30
|
-
puts c
|
31
|
-
o = `#{c}`
|
32
|
-
puts o
|
33
|
-
r = $?.to_i
|
34
|
-
puts r
|
35
|
-
end
|
36
|
-
lang.each do |l|
|
37
|
-
if /\.#{l}\.srt$/i =~ File.basename(path)
|
38
|
-
puts path
|
39
|
-
link = path.sub(/\.#{l}\.srt$/i, '.srt')
|
40
|
-
puts link
|
41
|
-
c = "ln -s \"#{path}\" \"#{link}\""
|
42
|
-
puts c
|
43
|
-
o = `#{c}`
|
44
|
-
puts o
|
45
|
-
r = $?.to_i
|
46
|
-
puts r
|
47
|
-
total_files +=1
|
48
|
-
total_size += FileTest.size(path)
|
49
|
-
break
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
puts "Total of files linked: #{total_files} Total of file size of linked files: #{total_size}"
|
data/bin/legendario
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'find'
|
3
|
-
require_relative '../lib/sl'
|
4
|
-
|
5
|
-
if ARGV.size == 0
|
6
|
-
Sl.error 'The parent folder that will have the language changed'
|
7
|
-
puts ''
|
8
|
-
puts 'Please, try something like: '
|
9
|
-
puts ''
|
10
|
-
puts 'change_sub_lang "folder-name" eng por '
|
11
|
-
puts ''
|
12
|
-
puts 'for example.'
|
13
|
-
puts ''
|
14
|
-
puts 'Default languages are: eng por spa ger on this sequence of priority'
|
15
|
-
exit 1
|
16
|
-
end
|
17
|
-
|
18
|
-
def se(command)
|
19
|
-
o = `#{command}`
|
20
|
-
r = $?.to_i
|
21
|
-
Sl.debug "#{o} #{r}"
|
22
|
-
r
|
23
|
-
end
|
24
|
-
|
25
|
-
dir = ARGV[0]
|
26
|
-
lang = ["eng", "por", "spa", "ger"]
|
27
|
-
if ARGV.size > 1
|
28
|
-
lang = []
|
29
|
-
c = 0
|
30
|
-
ARGV.each do|l|
|
31
|
-
lang << l if c > 0
|
32
|
-
c+=1
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
Sl.info "Language priority:"
|
37
|
-
Sl.info lang.inspect
|
38
|
-
Sl.info "The first language found will be soft linked to the subtitle file"
|
39
|
-
|
40
|
-
total_files = 0
|
41
|
-
|
42
|
-
Find.find(dir) do |path|
|
43
|
-
puts "path: #{path}"
|
44
|
-
if FileTest.directory?(path)
|
45
|
-
if File.basename(path)[0] == ?.
|
46
|
-
Find.prune # Don't look any further into this directory.
|
47
|
-
else
|
48
|
-
next
|
49
|
-
end
|
50
|
-
else
|
51
|
-
if FileTest.symlink?(path) and /\.srt$/i =~ File.basename(path)
|
52
|
-
Sl.info "Deleting: #{path}"
|
53
|
-
File.delete(path)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
Find.find(dir) do |path|
|
59
|
-
leave = false
|
60
|
-
if FileTest.directory?(path)
|
61
|
-
if File.basename(path)[0] == ?.
|
62
|
-
Find.prune # Don't look any further into this directory.
|
63
|
-
else
|
64
|
-
next
|
65
|
-
end
|
66
|
-
else
|
67
|
-
lang.each do |l|
|
68
|
-
if /\.#{l}\.srt$/i =~ File.basename(path) and !FileTest.symlink?(path)
|
69
|
-
link = path.sub(/\.#{l}\.srt$/i, '.srt')
|
70
|
-
se "ln -s \"#{path}\" \"#{link}\""
|
71
|
-
Sl.info "Linking sub lang #{l} to #{link}"
|
72
|
-
total_files +=1
|
73
|
-
# leave = true
|
74
|
-
break
|
75
|
-
end
|
76
|
-
# break if leave
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
Sl.info "Total of files linked: #{total_files}"
|
data/lib/legendario.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require "legendario/version"
|
3
|
-
require 'file-monitor'
|
4
|
-
require 'find'
|
5
|
-
require_relative 'sl'
|
6
|
-
|
7
|
-
module Legendario
|
8
|
-
|
9
|
-
lib_dir = File.join File.dirname(__FILE__), '../lib'
|
10
|
-
$:.unshift lib_dir unless $:.include? lib_dir
|
11
|
-
|
12
|
-
class Legendario
|
13
|
-
|
14
|
-
if ARGV.size == 0
|
15
|
-
Sl.error 'The folder that will be watched for new movies should be defined'
|
16
|
-
puts ''
|
17
|
-
puts 'Please, try something like: '
|
18
|
-
puts ''
|
19
|
-
puts 'legendario "folder-name" eng por '
|
20
|
-
puts ''
|
21
|
-
puts 'for example.'
|
22
|
-
puts ''
|
23
|
-
puts 'Default languages are: eng por spa ger on this sequence of priority'
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
27
|
-
@dir = ARGV[0]
|
28
|
-
@@lang = ["eng", "por", "spa", "ger"]
|
29
|
-
|
30
|
-
def self.lang
|
31
|
-
langs = ["eng", "por", "spa", "ger"]
|
32
|
-
if ARGV.size > 1
|
33
|
-
langs = []
|
34
|
-
c = 0
|
35
|
-
ARGV.each do|l|
|
36
|
-
langs << l if c > 0
|
37
|
-
c+=1
|
38
|
-
end
|
39
|
-
end
|
40
|
-
Sl.info "Will look for subtitles on these languages: "
|
41
|
-
Sl.info langs.inspect
|
42
|
-
langs
|
43
|
-
@@lang = langs
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.watch
|
47
|
-
Legendario.new.watch_dirs(@dir)
|
48
|
-
end
|
49
|
-
|
50
|
-
def se(command)
|
51
|
-
o = `#{command}`
|
52
|
-
r = $?.to_i
|
53
|
-
Sl.debug "#{o} #{r}"
|
54
|
-
r
|
55
|
-
end
|
56
|
-
|
57
|
-
def download_subs(file)
|
58
|
-
@@lang.each do |l|
|
59
|
-
Sl.info "Language: #{l}"
|
60
|
-
se("getsub -aLl #{l} \"#{file}\"")
|
61
|
-
end
|
62
|
-
symlink(File.dirname(file))
|
63
|
-
end
|
64
|
-
|
65
|
-
def symlink(dir)
|
66
|
-
Find.find(dir) do |path|
|
67
|
-
if FileTest.directory?(path)
|
68
|
-
if File.basename(path)[0] == ?.
|
69
|
-
Find.prune # Don't look any further into this directory.
|
70
|
-
else
|
71
|
-
next
|
72
|
-
end
|
73
|
-
else
|
74
|
-
if FileTest.symlink?(path)
|
75
|
-
se("rm \"#{path}\"")
|
76
|
-
end
|
77
|
-
symlinked = false
|
78
|
-
@@lang.each do |l|
|
79
|
-
if /\.#{l}\.srt$/i =~ File.basename(path) and !symlinked
|
80
|
-
Sl.debug path
|
81
|
-
link = path.sub(/\.#{l}\.srt$/i, '.srt')
|
82
|
-
Sl.debug link
|
83
|
-
symlinked = true
|
84
|
-
se("ln -s \"#{path}\" \"#{link}\"")
|
85
|
-
break #this break is not working so using !symlinked
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def watch_dirs(dir)
|
93
|
-
FileMonitor.watch dir do
|
94
|
-
dirs {
|
95
|
-
disallow /\.git$/
|
96
|
-
}
|
97
|
-
|
98
|
-
files {
|
99
|
-
disallow /.*/
|
100
|
-
allow /\.mkv$|\.mp4$|\.avi$/
|
101
|
-
}
|
102
|
-
begin
|
103
|
-
exec do |events|
|
104
|
-
events.each do |ev|
|
105
|
-
file = File.join(ev.watcher.path(), ev.name())
|
106
|
-
Sl.info file
|
107
|
-
Legendario.new.download_subs(file)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
#Avoids breaking after a directory been deleted
|
111
|
-
rescue => error
|
112
|
-
Sl.error error.inspect
|
113
|
-
Legendario.watch
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|