subdb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/subdb +1 -3
- data/bin/subdb-gui +75 -23
- data/lib/subdb/client_utils.rb +16 -9
- data/lib/subdb/version.rb +1 -1
- data/lib/subdb.rb +5 -1
- metadata +3 -3
data/bin/subdb
CHANGED
@@ -19,8 +19,6 @@
|
|
19
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
20
|
# THE SOFTWARE.
|
21
21
|
|
22
|
-
require "rubygems"
|
23
|
-
|
24
22
|
$: << File.expand_path("../../lib", __FILE__)
|
25
23
|
$: << File.expand_path("../../vendor/multipart-post", __FILE__)
|
26
24
|
|
@@ -40,7 +38,7 @@ Subdb::ClientUtils.sync files, ["pt", "en"] do |action, arg|
|
|
40
38
|
when :download_ok then puts "Download done"
|
41
39
|
when :download_not_found then puts "No version found for your language"
|
42
40
|
when :download_failed then puts "Error on download: #{arg[1]}"
|
43
|
-
when :scan_failed then puts "Error opening: #{arg}"
|
41
|
+
when :scan_failed then puts "Error opening: #{arg[1]}"
|
44
42
|
when :file_done then puts
|
45
43
|
end
|
46
44
|
end
|
data/bin/subdb-gui
CHANGED
@@ -1,10 +1,35 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Copyright (c) 2011 Wilker Lúcio
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
$: << File.expand_path("../../lib", __FILE__)
|
22
|
+
$: << File.expand_path("../../vendor/multipart-post", __FILE__)
|
23
|
+
$: << File.expand_path("../..", __FILE__)
|
24
|
+
|
25
|
+
require 'subdb'
|
3
26
|
require 'java'
|
4
|
-
require
|
27
|
+
require 'javalib/filedrop.jar'
|
5
28
|
|
6
29
|
import java.awt.BorderLayout
|
7
30
|
import java.awt.Color
|
31
|
+
import java.awt.image.BufferedImage
|
32
|
+
import javax.imageio.ImageIO
|
8
33
|
import javax.swing.BorderFactory
|
9
34
|
import javax.swing.JLabel
|
10
35
|
import javax.swing.JFrame
|
@@ -16,11 +41,11 @@ import javax.swing.JTextArea
|
|
16
41
|
include_class java.lang.System
|
17
42
|
include_class Java::FileDrop
|
18
43
|
|
19
|
-
class
|
44
|
+
class SubdbGUI < JFrame
|
20
45
|
include FileDrop::Listener
|
21
46
|
|
22
47
|
def initialize
|
23
|
-
super "
|
48
|
+
super "SubDB Sync"
|
24
49
|
|
25
50
|
@uploading = false
|
26
51
|
|
@@ -28,12 +53,18 @@ class Example < JFrame
|
|
28
53
|
end
|
29
54
|
|
30
55
|
def init_ui
|
56
|
+
begin
|
57
|
+
icon = ImageIO.read(getClass.getResource("images/subdb128.png"))
|
58
|
+
set_icon_image icon
|
59
|
+
rescue
|
60
|
+
end
|
61
|
+
|
31
62
|
@dropper = JPanel.new
|
32
63
|
@dropper.set_border BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10), BorderFactory.createLineBorder(Color.black))
|
33
64
|
|
34
65
|
@progress = JProgressBar.new(0, 100)
|
35
66
|
|
36
|
-
hint = JLabel.new("Arraste suas pastas ou arquivos aqui.")
|
67
|
+
hint = JLabel.new("Arraste suas pastas ou arquivos com videos aqui.")
|
37
68
|
|
38
69
|
@dropper.add(hint, BorderLayout::CENTER)
|
39
70
|
|
@@ -44,39 +75,60 @@ class Example < JFrame
|
|
44
75
|
content_pane.add(@dropper, BorderLayout::CENTER)
|
45
76
|
content_pane.add(@progress, BorderLayout::SOUTH)
|
46
77
|
|
47
|
-
# @progress.set_indeterminate true
|
48
|
-
|
49
78
|
FileDrop.new(nil, @dropper, self)
|
50
79
|
|
51
|
-
set_size
|
80
|
+
set_size 800, 300
|
52
81
|
set_resizable false
|
53
82
|
set_default_close_operation JFrame::EXIT_ON_CLOSE
|
54
83
|
set_location_relative_to nil
|
55
84
|
set_visible true
|
56
85
|
|
57
86
|
@progress.set_string_painted true
|
58
|
-
@progress.set_string "enviando"
|
59
|
-
|
60
|
-
Thread.new do
|
61
|
-
i = 0
|
62
|
-
|
63
|
-
while true
|
64
|
-
@progress.set_value i
|
65
|
-
i += 1
|
66
|
-
sleep(5)
|
67
|
-
end
|
68
|
-
end
|
69
87
|
end
|
70
88
|
|
71
89
|
def filesDropped(files)
|
72
90
|
return if @uploading
|
73
91
|
|
92
|
+
files = files.map { |f| f.to_s }
|
93
|
+
|
74
94
|
@uploading = true
|
75
95
|
|
76
|
-
|
77
|
-
|
96
|
+
Thread.new do
|
97
|
+
@progress.set_indeterminate true
|
98
|
+
@progress.set_string "Gerando lista de arquivos..."
|
99
|
+
|
100
|
+
puts "Generating file list..."
|
101
|
+
|
102
|
+
files = Subdb::ClientUtils.scan_paths(files)
|
103
|
+
|
104
|
+
puts "Generation done"
|
105
|
+
|
106
|
+
@progress.set_indeterminate false
|
107
|
+
@progress.set_maximum files.length
|
108
|
+
|
109
|
+
Subdb::ClientUtils.sync files, ["pt", "en"] do |action, arg|
|
110
|
+
case action
|
111
|
+
when :scan then @progress.set_string "Verificando #{arg[0]}"
|
112
|
+
when :scanned then @progress.set_string "Verificando #{arg.pathbase} [#{arg.hash}]"
|
113
|
+
when :uploading then @progress.set_string "Encontrada legenda local, subindo para o servidor..."
|
114
|
+
when :upload_failed then error "Erro ao enviar legenda #{arg[0]}: #{arg[1]}"
|
115
|
+
when :downloading then @progress.set_string "Baixando a legenda..."
|
116
|
+
when :download_not_found then error "Nenhuma legenda encontrada no seu indioma para #{arg[0].pathbase}"
|
117
|
+
when :download_failed then error "Erro ao tentar baixar #{arg[0].path}: #{arg[1]}"
|
118
|
+
when :scan_failed then error "Erro ao abrir arquivo #{arg[0]}: #{arg[1]}"
|
119
|
+
when :file_done then @progress.set_value arg[1]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
@progress.set_string "Concluido"
|
124
|
+
|
125
|
+
@uploading = false
|
78
126
|
end
|
79
127
|
end
|
128
|
+
|
129
|
+
def error(msg)
|
130
|
+
puts msg
|
131
|
+
end
|
80
132
|
end
|
81
133
|
|
82
|
-
|
134
|
+
SubdbGUI.new
|
data/lib/subdb/client_utils.rb
CHANGED
@@ -25,30 +25,37 @@ module Subdb::ClientUtils
|
|
25
25
|
class << self
|
26
26
|
def scan_paths(paths)
|
27
27
|
video_ext = VIDEO_EXTENSIONS.join(",")
|
28
|
+
p paths
|
28
29
|
|
29
|
-
|
30
|
+
files = []
|
31
|
+
|
32
|
+
for path in paths
|
30
33
|
if File.directory?(path)
|
31
|
-
path = path.chomp(
|
32
|
-
|
34
|
+
path = path.chomp(File::SEPARATOR)
|
35
|
+
globpath = "#{path.gsub("\\", "/")}/**/*{#{video_ext}}"
|
36
|
+
|
37
|
+
puts "Scanning #{globpath}"
|
38
|
+
|
39
|
+
files = files.concat(Dir.glob(globpath))
|
33
40
|
else
|
34
41
|
files << path if VIDEO_EXTENSIONS.include?(File.extname(path))
|
35
42
|
end
|
43
|
+
end
|
36
44
|
|
37
|
-
|
38
|
-
end.sort
|
45
|
+
files.sort
|
39
46
|
end
|
40
47
|
|
41
48
|
def sync(paths, languages = ["en"])
|
42
49
|
i = 0
|
43
50
|
|
44
51
|
for path in paths
|
45
|
-
base = File.dirname(path) +
|
52
|
+
base = File.dirname(path) + File::SEPARATOR + File.basename(path, File.extname(path))
|
46
53
|
sub = find_subtitle(path)
|
47
54
|
|
48
55
|
yield :scan, [path, i]
|
49
56
|
|
50
57
|
begin
|
51
|
-
subdb
|
58
|
+
subdb = Subdb.new(path)
|
52
59
|
|
53
60
|
yield :scanned, subdb
|
54
61
|
|
@@ -87,7 +94,7 @@ module Subdb::ClientUtils
|
|
87
94
|
end
|
88
95
|
end
|
89
96
|
rescue
|
90
|
-
yield :scan_failed, $!
|
97
|
+
yield :scan_failed, path, $!
|
91
98
|
end
|
92
99
|
|
93
100
|
i += 1
|
@@ -97,7 +104,7 @@ module Subdb::ClientUtils
|
|
97
104
|
end
|
98
105
|
|
99
106
|
def find_subtitle(path)
|
100
|
-
base = File.dirname(path) +
|
107
|
+
base = File.dirname(path) + File::SEPARATOR + File.basename(path, File.extname(path))
|
101
108
|
|
102
109
|
for subext in SUB_EXTESNIONS
|
103
110
|
subpath = base + subext
|
data/lib/subdb/version.rb
CHANGED
data/lib/subdb.rb
CHANGED
@@ -42,7 +42,7 @@ class Subdb
|
|
42
42
|
|
43
43
|
self.test_mode = false
|
44
44
|
|
45
|
-
attr_reader :hash
|
45
|
+
attr_reader :hash, :path
|
46
46
|
|
47
47
|
def initialize(path)
|
48
48
|
fail "#{path} is not a file" unless File.exists?(path)
|
@@ -91,6 +91,10 @@ class Subdb
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def pathbase
|
95
|
+
File.basename(path)
|
96
|
+
end
|
97
|
+
|
94
98
|
protected
|
95
99
|
|
96
100
|
def build_hash
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Wilker Lucio
|