warlley-subtitle_it 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.autotest +19 -0
  2. data/History.txt +30 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +53 -0
  5. data/README.markdown +41 -0
  6. data/README.txt +84 -0
  7. data/Rakefile +4 -0
  8. data/bin/subtitle_it +107 -0
  9. data/config/hoe.rb +73 -0
  10. data/config/requirements.rb +15 -0
  11. data/lib/subtitle_it/formats/ass.rb +14 -0
  12. data/lib/subtitle_it/formats/rsb.rb +33 -0
  13. data/lib/subtitle_it/formats/srt.rb +34 -0
  14. data/lib/subtitle_it/formats/sub.rb +31 -0
  15. data/lib/subtitle_it/formats/xml.rb +64 -0
  16. data/lib/subtitle_it/formats/yml.rb +20 -0
  17. data/lib/subtitle_it/movie.rb +25 -0
  18. data/lib/subtitle_it/movie_hasher.rb +30 -0
  19. data/lib/subtitle_it/subline.rb +25 -0
  20. data/lib/subtitle_it/subtime.rb +63 -0
  21. data/lib/subtitle_it/subtitle.rb +32 -0
  22. data/lib/subtitle_it/version.rb +9 -0
  23. data/lib/subtitle_it.rb +16 -0
  24. data/script/console +10 -0
  25. data/script/destroy +14 -0
  26. data/script/generate +14 -0
  27. data/script/txt2html +82 -0
  28. data/setup.rb +1585 -0
  29. data/spec/fixtures/godfather.srt +2487 -0
  30. data/spec/fixtures/huge.ass +22 -0
  31. data/spec/fixtures/movie.xml +28 -0
  32. data/spec/fixtures/movie.yml +163 -0
  33. data/spec/fixtures/pseudo.rsb +6 -0
  34. data/spec/fixtures/pulpfiction.sub +2025 -0
  35. data/spec/fixtures/sincity.yml +12 -0
  36. data/spec/spec.opts +1 -0
  37. data/spec/spec_helper.rb +33 -0
  38. data/spec/subtitle_it/formats/ass_spec.rb +5 -0
  39. data/spec/subtitle_it/formats/rsb_spec.rb +42 -0
  40. data/spec/subtitle_it/formats/srt_spec.rb +42 -0
  41. data/spec/subtitle_it/formats/sub_spec.rb +46 -0
  42. data/spec/subtitle_it/formats/xml_spec.rb +60 -0
  43. data/spec/subtitle_it/formats/yml_spec.rb +20 -0
  44. data/spec/subtitle_it/subline_spec.rb +30 -0
  45. data/spec/subtitle_it/subtime_spec.rb +76 -0
  46. data/spec/subtitle_it/subtitle_spec.rb +1 -0
  47. data/spec/subtitle_it_spec.rb +11 -0
  48. data/subtitle_it.gemspec +41 -0
  49. data/tasks/deployment.rake +34 -0
  50. data/tasks/environment.rake +7 -0
  51. data/tasks/rspec.rake +21 -0
  52. metadata +132 -0
data/.autotest ADDED
@@ -0,0 +1,19 @@
1
+ # #
2
+ # SMS AUTOTEST
3
+ #
4
+ #require 'autotest/growl'
5
+ #require 'autotest/html_report'
6
+ # require 'autotest/kdenotify'
7
+ require 'autotest/menu'
8
+ #require 'autotest/pretty'
9
+ require 'autotest/redgreen'
10
+ # require 'autotest/snarl'
11
+ require 'autotest/timestamp'
12
+
13
+
14
+ class Autotest
15
+ Autotest.add_hook :initialize do |at|
16
+ %w{.svn .hg .git .DS_store}.each {|exception|at.add_exception(exception)}
17
+ end
18
+ end
19
+
data/History.txt ADDED
@@ -0,0 +1,30 @@
1
+ == 0.1.0 2008-09-04
2
+
3
+ * 1 major enhancement:
4
+ * Support yml
5
+
6
+ == 0.2.0 2008-09-07
7
+
8
+ * 1 major enhancement:
9
+ * Support sub
10
+
11
+ == 0.3.0 2008-09-07
12
+
13
+ * 2 major enhancement:
14
+ * Support srt
15
+ * subtitle_it tool
16
+
17
+ == 0.4.0 2008-09-07
18
+
19
+ * 1 major enhancement:
20
+ * Adds yml generator
21
+
22
+ == 0.5.1 2008-09-08
23
+
24
+ * 1 major enhancement:
25
+ * Adds rsb support
26
+
27
+ == 0.6.1 2008-09-09
28
+
29
+ * 1 major enhancement:
30
+ * Adds xml tt support
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Marcos Piccinini, Warlley Rezende, Marcin (tiraeth) Chwedziak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,53 @@
1
+ .autotest
2
+ History.txt
3
+ License.txt
4
+ Manifest.txt
5
+ README.markdown
6
+ README.txt
7
+ Rakefile
8
+ bin/subtitle_it
9
+ blu.rsb
10
+ blua.rsb
11
+ config/hoe.rb
12
+ config/requirements.rb
13
+ lib/subtitle_it.rb
14
+ lib/subtitle_it/formats/ass.rb
15
+ lib/subtitle_it/formats/rsb.rb
16
+ lib/subtitle_it/formats/srt.rb
17
+ lib/subtitle_it/formats/sub.rb
18
+ lib/subtitle_it/formats/xml.rb
19
+ lib/subtitle_it/formats/yml.rb
20
+ lib/subtitle_it/movie.rb
21
+ lib/subtitle_it/movie_hasher.rb
22
+ lib/subtitle_it/subline.rb
23
+ lib/subtitle_it/subtime.rb
24
+ lib/subtitle_it/subtitle.rb
25
+ lib/subtitle_it/version.rb
26
+ script/console
27
+ script/destroy
28
+ script/generate
29
+ script/txt2html
30
+ setup.rb
31
+ spec/fixtures/godfather.srt
32
+ spec/fixtures/huge.ass
33
+ spec/fixtures/movie.xml
34
+ spec/fixtures/movie.yml
35
+ spec/fixtures/pseudo.rsb
36
+ spec/fixtures/pulpfiction.sub
37
+ spec/fixtures/sincity.yml
38
+ spec/spec.opts
39
+ spec/spec_helper.rb
40
+ spec/subtitle_it/formats/ass_spec.rb
41
+ spec/subtitle_it/formats/rsb_spec.rb
42
+ spec/subtitle_it/formats/srt_spec.rb
43
+ spec/subtitle_it/formats/sub_spec.rb
44
+ spec/subtitle_it/formats/xml_spec.rb
45
+ spec/subtitle_it/formats/yml_spec.rb
46
+ spec/subtitle_it/subline_spec.rb
47
+ spec/subtitle_it/subtime_spec.rb
48
+ spec/subtitle_it/subtitle_spec.rb
49
+ spec/subtitle_it_spec.rb
50
+ subtitle_it.gemspec
51
+ tasks/deployment.rake
52
+ tasks/environment.rake
53
+ tasks/rspec.rake
data/README.markdown ADDED
@@ -0,0 +1,41 @@
1
+ h1. Subtitle It
2
+
3
+ Ruby tool to work with subtitle files.
4
+
5
+ h1. FEATURES:
6
+
7
+ * Converts to and from: yml/srt/sub/rsb nice subtitle code
8
+ * Fixes delays. (SrtResync)
9
+
10
+ h2. TODO:
11
+
12
+ * Compatibility with "sube" (http://github.com/vic/sube)
13
+ * Download subtitles. (http://github.com/johanlunds/downsub/tree)
14
+
15
+ h1. SYNOPSIS:
16
+
17
+ Bash tool:
18
+
19
+ Convert a srt to sub:
20
+ subtitle_it in.srt out.sub
21
+
22
+ Add a delay of 1 minute:
23
+ subtitle_it -d 60 in.srt
24
+
25
+ Create a template
26
+ subtitle_it unexistent.file
27
+
28
+
29
+ h1. INSTALL:
30
+
31
+ sudo gem install SubtitleIt
32
+
33
+
34
+ h1. THE "Ruby Subtitle" Format - RSB
35
+
36
+ It`s just a easy way, proof of concept to edit subtitles. Here is what it looks like:
37
+
38
+ 00:32 => 00:33 == Nice police work! | Thank you!
39
+ MM:SS => N == TEXT | NEWLINE
40
+
41
+ Create a template to check it out.
data/README.txt ADDED
@@ -0,0 +1,84 @@
1
+ = Subtitle It
2
+
3
+ Ruby tool to work with subtitle files.
4
+
5
+
6
+ == FEATURES:
7
+
8
+ * Converts to and from: SRT, SUB, XML(TT), YML, RSB and ASS
9
+ * Fixes delays. (SrtResync)
10
+
11
+ TODO:
12
+
13
+ * Compatibility with "sube" (http://github.com/vic/sube)
14
+ * Download subtitles. (http://github.com/johanlunds/downsub/tree)
15
+ * Download from http://trac.opensubtitles.org/projects/opensubtitles/wiki/XMLRPC
16
+ * Fix delays
17
+ * Convert 1 to 2 CD`s and versa-vice
18
+ * ASS Format (Yes, for the funny of it...)
19
+
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * hpricot
24
+
25
+
26
+ == SYNOPSIS:
27
+
28
+ Bash tool:
29
+
30
+ Convert a srt to sub:
31
+ subtitle_it in.srt out.sub
32
+
33
+ Add a delay of 1 minute:
34
+ subtitle_it -d 60 in.srt
35
+
36
+ Create a template
37
+ subtitle_it unexistent.file
38
+
39
+
40
+ == INSTALL:
41
+
42
+ sudo gem install SubtitleIt
43
+
44
+
45
+ == THE "Ruby Subtitle" Format - RSB
46
+
47
+ It`s just a easy way, proof of concept to edit subtitles. Here is what it looks like:
48
+
49
+ 00:32 => 00:33 == Nice police work! | Thank you!
50
+ MM:SS => N == TEXT | NEWLINE
51
+
52
+ Create a template to check it out.
53
+
54
+
55
+ == OTHER TOOLS:
56
+
57
+ Aegisub: http://www.malakith.net/aegiwiki/Main_Page
58
+
59
+
60
+ == LICENSE:
61
+
62
+ (The MIT License)
63
+
64
+ Copyright (c) 2008 Warlley Rezende, Marcos Piccinini
65
+ Parts of subrip code by Marcin (tiraeth) Chwedziak
66
+
67
+ Permission is hereby granted, free of charge, to any person obtaining
68
+ a copy of this software and associated documentation files (the
69
+ 'Software'), to deal in the Software without restriction, including
70
+ without limitation the rights to use, copy, modify, merge, publish,
71
+ distribute, sublicense, and/or sell copies of the Software, and to
72
+ permit persons to whom the Software is furnished to do so, subject to
73
+ the following conditions:
74
+
75
+ The above copyright notice and this permission notice shall be
76
+ included in all copies or substantial portions of the Software.
77
+
78
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
79
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
80
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
81
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
82
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
83
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
84
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/subtitle_it ADDED
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env ruby
2
+ # SubtitleIt
3
+ #
4
+ # Created on 2008-9-4.
5
+ # Copyright (c) 2008. All rights reserved.
6
+ #
7
+ begin
8
+ require 'rubygems'
9
+ rescue LoadError
10
+ # no rubygems to load, so we fail silently
11
+ end
12
+
13
+ require 'optparse'
14
+ require 'subtitle_it'
15
+
16
+ include SubtitleIt
17
+
18
+ OPTIONS = {
19
+ :force => false,
20
+ :format => nil,
21
+ :delay => nil
22
+ }
23
+ MANDATORY_OPTIONS = %w( )
24
+
25
+ parser = OptionParser.new do |opts|
26
+ opts.banner = <<BANNER
27
+ SubtitleIt - Convert and create subtitles.
28
+
29
+ Usage: #{File.basename($0)} [options] file_in [file_out]
30
+
31
+ Options are:
32
+ -c FORMAT --convert=FORMAT Format to convert to: yml, srt or sub.
33
+ You don`t need to use this if fileout contains a extension.
34
+
35
+ -f --force Force overwrite.
36
+
37
+ -d DELAY --delay=DELAY Fix the delay of the file.
38
+
39
+ -h --help Show this.
40
+
41
+ -v --version Program version.
42
+ BANNER
43
+ opts.separator ""
44
+
45
+ opts.on("-c", "--convert=FORMAT", String,
46
+ "Format to convert to") { |OPTIONS[:format]| }
47
+
48
+ opts.on("-d", "--delay=DELAY", Float,
49
+ "Delay to add/remove") { |OPTIONS[:delay]| }
50
+
51
+ opts.on("-f", "--force", "Force overwrite") { OPTIONS[:force] = true }
52
+
53
+ opts.on("-h", "--help",
54
+ "Show this help message.") { puts opts; exit }
55
+
56
+ #FIXME: I gave up... I cant acess the version var from here... missing something.
57
+ opts.on("-v", "--version",
58
+ "Show program version") { puts 'SubtitleIt v0.6.3'; exit }
59
+
60
+ opts.parse!(ARGV)
61
+
62
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
63
+ puts opts; exit
64
+ end
65
+ end
66
+
67
+ if ARGV.empty?
68
+ puts parser.banner
69
+ exit
70
+ end
71
+
72
+ filein, filein_ext = ARGV[0].split('.')
73
+ fileout, fileout_ext = ARGV[1] ? ARGV[1].split('.') : [filein, filein_ext]
74
+ t = Time.now
75
+ if File.exists?(ARGV[0]) && ( ARGV[1] || OPTIONS[:format] )
76
+ content = File.open(ARGV[0], 'r')
77
+ if OPTIONS[:delay]
78
+ ARGV[1] ||= ARGV[0] + "_new"
79
+ SubtitleIt.srt_delay(ARGV[0],ARGV[1])
80
+ else
81
+ puts "Working on file #{filein}..."
82
+ sub = Subtitle.new(content, filein_ext)
83
+ format = OPTIONS[:format]
84
+ format ||= fileout_ext unless fileout_ext == filein_ext
85
+ out = sub.send :"to_#{format}"
86
+ #TODO: rescue format not found....
87
+ end
88
+ else
89
+ format = 'rsb'
90
+ out = <<GEN
91
+ - title: #{ARGV[0]}
92
+ - authors: FIXME
93
+ - version: FIXME
94
+ 00:05:26.500 => 00:05:28.500 == worth killing for...
95
+ 00:06:00.400 => 00:06:03.400 == worth dying for...
96
+ 00:07:00.300 => 00:07:03.300 == worth going to the hell for...
97
+ GEN
98
+ end
99
+
100
+ fout = "#{fileout}.#{format}"
101
+
102
+ if File.exists?(fout) && !OPTIONS[:force]
103
+ puts "File exists. #{fout}"
104
+ else
105
+ File.open(fout, 'w') {|f| f.write(out) }
106
+ puts "Done. Wrote: #{fout} in #{Time.now - t}s."
107
+ end
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'subtitle_it/version'
2
+
3
+ AUTHOR = 'FIXME full name' # can also be an array of Authors
4
+ EMAIL = "FIXME email"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'subtitle_it' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'subtitle_it' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = SubtitleIt::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'subtitle_it documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,14 @@
1
+ # SubtitleIt
2
+ # ASS - http://en.wikipedia.org/wiki/SubStation_Alpha
3
+ #
4
+ module SubtitleIt
5
+ module Formats
6
+ def parse_ass
7
+
8
+ end
9
+
10
+ #not mine!
11
+ def to_ass
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ # SubtitleIt
2
+ # RSB - Ruby Subtitle
3
+ #
4
+ # 00:32 => 00:33 == Nice police work! | Thank you!
5
+ # 00:53 => N == Howdy ho!
6
+ # MM:SS => N == TEXT | NEWLINE
7
+ #
8
+ # Where N is the seconds to last.
9
+ #
10
+ module SubtitleIt
11
+ module Formats
12
+ def parse_rsb
13
+ inn = @raw.to_a
14
+ @title = inn.delete_at(0).split(':')[1]
15
+ @authors = inn.delete_at(0).split(':')[1]
16
+ @version = inn.delete_at(0).split(':')[1]
17
+ inn.inject([]) do |final,line|
18
+ text_on,text_off = line.split('=>').map { |t| t.strip }
19
+ text = line.split('==')[1].strip
20
+ final << Subline.new(text_on, text_off, text)
21
+ end
22
+ end
23
+
24
+ def to_rsb
25
+ out = "- title: #{@title}\n- authors: #{@authors}\n- version: #{@version}\n"
26
+ out << @lines.inject([]) do |i,l|
27
+ i << "%s => %s == %s" % [l.text_on.to_s, l.text_off.to_s, l.text]
28
+ end.join("\n")
29
+ end
30
+ end
31
+ end
32
+
33
+
@@ -0,0 +1,34 @@
1
+ # SubtitleIt
2
+ # SRT format
3
+ #
4
+ # N
5
+ # 00:55:21,600 --> 00:55:27,197
6
+ # lt's not even 20 years. You've sold the
7
+ # casinos and made fortunes for all of us.
8
+ #
9
+ # Where N is the sub index number
10
+ #
11
+ module SubtitleIt
12
+ module Formats
13
+ def parse_srt
14
+ @raw.split(/\n\n/).inject([]) do |final,line|
15
+ line = line.split(/\n/)
16
+ line.delete_at(0)
17
+ text_on,text_off = line[0].split('-->').map { |t| t.strip }
18
+ line.delete_at(0)
19
+ text = line.join("|")
20
+ final << Subline.new(text_on, text_off, text)
21
+ end
22
+ end
23
+
24
+ def to_srt
25
+ out = []
26
+ @lines.each_with_index do |l,i|
27
+ out << "#{i}"
28
+ out << "%s --> %s" % [l.text_on.to_s, l.text_off.to_s]
29
+ out << l.text.gsub("|","\n")
30
+ end
31
+ out.join("\n")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ # SubtitleIt
2
+ # MicroDVD - Subrip format
3
+ #
4
+ # {1025}{1115}You always say that.|The same thing every time.
5
+ # {1118}{1177}"l'm throug h, never again,|too dangerous."
6
+ #
7
+ # Where N is ms / framerate / 1000 (ms -> s)
8
+ #
9
+ # parts of the code from 'simplesubtitler' from Marcin (tiraeth) Chwedziak
10
+ #
11
+ module SubtitleIt
12
+ module Formats
13
+ def parse_sub
14
+ @raw.to_a.inject([]) do |i,l|
15
+ line_data = l.scan(/^\{([0-9]{1,})\}\{([0-9]{1,})\}(.+)$/)
16
+ line_data = line_data.at 0
17
+ text_on, text_off, text = line_data
18
+ text_on, text_off = [text_on.to_i, text_off.to_i].map { |t| (t.to_i/@fps*1000).to_i }
19
+ i << Subline.new(text_on, text_off, text.chomp)
20
+ end
21
+ end
22
+
23
+ def to_sub
24
+ @lines.inject([]) do |i,l|
25
+ start = l.text_on.to_i / @fps / 1000
26
+ stop = l.text_off.to_i / @fps / 1000
27
+ i << "{%d}{%d}%s" % [start, stop, l.text]
28
+ end.join("\r\n")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,64 @@
1
+ # SubtitleIt
2
+ # XML TT Timed Text
3
+ # http://www.w3.org/TR/2006/CR-ttaf1-dfxp-20061116/
4
+ # http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000604.html
5
+ #
6
+ # <?xml version="1.0" encoding="UTF-8"?>
7
+ # <tt xml:lang="en" xmlns="http://www.w3.org/2006/04/ttaf1" xmlns:tts="http://www.w3.org/2006/04/ttaf1#styling">
8
+ # <head>
9
+ # <styling>
10
+ # <style id="1" tts:textAlign="right"/>
11
+ # <style id="2" tts:color="transparent"/>
12
+ # </styling>
13
+ # </head>
14
+ # <body>
15
+ # <div xml:lang="en">
16
+ # <p begin="00:00:00.00" dur="00:00:03.07">I had just joined <span tts:fontFamily="monospaceSansSerif,proportionalSerif,TheOther"tts:fontSize="+2">Macromedia</span> in 1996,</p>
17
+ # <p begin="00:00:03.07" dur="00:00:03.35">and we were trying to figure out what to do about the internet.</p>
18
+ # <p begin="00:00:29.02" dur="00:00:01.30" style="1">as <span tts:color="#ccc333">easy</span> as drawing on paper.</p>
19
+ # </div>
20
+ # </body>
21
+ #</tt>
22
+ require 'hpricot'
23
+ module SubtitleIt
24
+ module Formats
25
+
26
+ def parse_xml
27
+ final = []
28
+ doc = Hpricot.XML(@raw)
29
+ # p (doc/'tt'/'p').first[:dur]#inspect
30
+ (doc/'tt'/'p').each do |line|
31
+ text_on = line[:begin]
32
+ text_off = line[:dur]
33
+ text = line.innerHTML
34
+ final << Subline.new(text_on,text_off,text)
35
+ end
36
+ final
37
+ end
38
+
39
+ def xml_lines
40
+ @lines.inject([]) do |i,l|
41
+ toff = l.text_off - l.text_on
42
+ i << " <p begin=\"#{l.text_on}\" dur=\"#{toff}\">#{l.text}</p>"
43
+ end.join("\n")
44
+ end
45
+
46
+ def to_xml
47
+ out = <<XML
48
+ <?xml version="1.0" encoding="UTF-8"?>
49
+ <tt xml:lang="en" xmlns="http://www.w3.org/2006/04/ttaf1" xmlns:tts="http://www.w3.org/2006/04/ttaf1#styling">
50
+ <head>
51
+ <styling>#{@style + "\n" if @style}
52
+ </styling>
53
+ </head>
54
+ <body>
55
+ <div xml:lang="en">
56
+ #{xml_lines}
57
+ </div>
58
+ </body>
59
+ </tt>
60
+ XML
61
+ out.chomp
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,20 @@
1
+ # SubtitleIt
2
+ # YML Dump
3
+ #
4
+ require 'yaml'
5
+ module SubtitleIt
6
+ module Formats
7
+ def parse_yml
8
+ @yaml = YAML::load(@raw)
9
+ header = @yaml.delete('header')
10
+ @title = header['title']
11
+ @author = header['authors']
12
+ @version = header['version']
13
+ @yaml['lines'].map { |l| Subline.new(l[0], l[1], l[2]) }
14
+ end
15
+
16
+ def to_yml
17
+ YAML.dump(self)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # downsub - github.com/johanlunds/downsub
2
+ require 'down_sub/movie_hasher'
3
+
4
+ module SubtitleIt
5
+ class Movie
6
+ EXTS = %w(3g2 3gp 3gp2 3gpp 60d ajp asf asx avchd avi bik bix box cam dat divx dmf dv dvr-ms evo flc fli flic flv flx gvi gvp h264 m1v m2p m2ts m2v m4e m4v mjp mjpeg mjpg mkv moov mov movhd movie movx mp4 mpe mpeg mpg mpv mpv2 mxf nsv nut ogg ogm omf ps qt ram rm rmvb swf ts vfw vid video viv vivo vob vro wm wmv wmx wrap wvx wx x264 xvid)
7
+
8
+ attr_reader :filename
9
+ attr_accessor :info
10
+
11
+ def initialize(filename)
12
+ @filename = filename
13
+ @hash = nil
14
+ @info = {}
15
+ end
16
+
17
+ def hash
18
+ @hash ||= MovieHasher::compute_hash(@filename)
19
+ end
20
+
21
+ def size
22
+ File.size(@filename)
23
+ end
24
+ end
25
+ end