lynda-translator-srt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60831c42410a673f452679b38e96826b285da9a0
4
+ data.tar.gz: f5747d3df6be7d99724bd15d195eb5f3fc6d63b6
5
+ SHA512:
6
+ metadata.gz: e3e5eb2125bd6ebff924e54ebe95958012ad3381cfd5bba9594636cb600d164c031d208d182bc980ea34c2d092a04e3aa46480b3a69f55e6dff6d8294f51a209
7
+ data.tar.gz: 12f076b24eed7cf2bb57e05acc6c91a6d1650b5b695527640db6b908925b68f8239ec8d87ca5499b043e0f2492a1056998a94e21a160e8bb4ea896f074e40a80
@@ -0,0 +1,17 @@
1
+ # Ignore RubyMine project files
2
+ .idea
3
+
4
+ *.gem
5
+ *.rbc
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile*.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ tmp
17
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lynda_translator_srt.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2014, Vadim Poplavskiy
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of lynda-translator-srt nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
@@ -0,0 +1,33 @@
1
+ require 'lynda_translator_srt/srt_original/downloader'
2
+ require 'lynda_translator_srt/srt_original/reader'
3
+ require 'lynda_translator_srt/srt_original/unzipper'
4
+ require 'lynda_translator_srt/zipper'
5
+ require 'translator_srt/google_translate'
6
+
7
+ module LyndaTranslatorSrt
8
+ LANG_LYNDA_SUBS = 'en'
9
+
10
+ def self.translate(course_url, to_lang, path_to_zip)
11
+ srt_downloader = SrtOriginal::Downloader.new(course_url).download_zip_original_srt
12
+
13
+ srt_unzipper = SrtOriginal::Unzipper.new(srt_downloader.tmp_file_path).unzip
14
+
15
+ srt_reader = SrtOriginal::Reader.new(srt_unzipper.path_unzip_folder).create_list_path_srt_files
16
+
17
+ srt_reader.list_path_srt_files.each do |srt_path|
18
+ translated_srt = TranslatorSrt::GoogleTranslate.translate_srt_file LANG_LYNDA_SUBS, to_lang, srt_path
19
+ File.write srt_path, translated_srt
20
+ end
21
+
22
+ params_zipper = {
23
+ path_unzip_folder: srt_unzipper.path_unzip_folder,
24
+ root_folder_path: srt_reader.root_folder_path,
25
+ root_folder_name: srt_reader.root_folder_name,
26
+ save_to: path_to_zip
27
+ }
28
+
29
+ srt_zipper = Zipper.new(params_zipper).zip
30
+
31
+ srt_zipper.zipname
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ require 'net/http'
2
+ require 'open-uri'
3
+
4
+ module LyndaTranslatorSrt
5
+ module SrtOriginal
6
+ class Downloader
7
+ LYNDA_SRT_SERVICE_URL = 'http://www.lyndasub.ir/g/'
8
+
9
+ attr_reader :url_course, :link_original_srt, :tmp_file_path
10
+
11
+ def initialize(url_course)
12
+ @url_course = url_course
13
+ end
14
+
15
+ def download_zip_original_srt
16
+ load_link_zip_original_srt
17
+ raise ArgumentError, "Unfortunately we doesn't load transcript to this course." if @link_original_srt.nil?
18
+
19
+ tmp_file_name = "srt_original_at_"
20
+ tmp_file = Tempfile.new(tmp_file_name)
21
+ @tmp_file_path = tmp_file.path
22
+
23
+ File.open(tmp_file.path, "wb") do |saved_file|
24
+ # the following "open" is provided by open-uri
25
+ open(@link_original_srt, "rb") do |read_file|
26
+ saved_file.write(read_file.read)
27
+ end
28
+ end
29
+
30
+ self
31
+ end
32
+
33
+ private
34
+
35
+ def load_link_zip_original_srt
36
+ uri = URI(LYNDA_SRT_SERVICE_URL + @url_course)
37
+
38
+ res = Net::HTTP.get_response(uri)
39
+
40
+ @link_original_srt = res.body if res.is_a?(Net::HTTPSuccess)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ require 'pathname'
2
+
3
+ module LyndaTranslatorSrt
4
+ module SrtOriginal
5
+ class Reader
6
+ attr_reader :root_folder_path, :root_folder_name, :list_path_srt_files
7
+
8
+ def initialize(path_unzip_folder)
9
+ @path_unzip_folder = path_unzip_folder
10
+ end
11
+
12
+ def create_list_path_srt_files
13
+ @list_path_srt_files = []
14
+
15
+ pathname = Pathname.new @path_unzip_folder
16
+
17
+ @root_folder_path = pathname.children.first.to_s
18
+ @root_folder_name = pathname.children.first.basename
19
+
20
+ collect_srt pathname
21
+
22
+ puts "Created list path srt files"
23
+
24
+ self
25
+ end
26
+
27
+ private
28
+
29
+ def collect_srt(path)
30
+ path.each_child do |child|
31
+ if child.file?
32
+ @list_path_srt_files << child.to_s
33
+ elsif child.directory?
34
+ collect_srt(child) + [child]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ require 'fileutils'
2
+
3
+ module LyndaTranslatorSrt
4
+ module SrtOriginal
5
+ class Unzipper
6
+ attr_reader :path_unzip_folder
7
+
8
+ def initialize(tmp_file_path)
9
+ @tmp_file_path = tmp_file_path
10
+ end
11
+
12
+ def unzip
13
+ name_unzip_folder = "srt_original_#{Time.now.utc.iso8601}"
14
+ @path_unzip_folder = Dir.tmpdir + "/" + name_unzip_folder
15
+
16
+ FileUtils::mkdir_p @path_unzip_folder
17
+
18
+ @unzipped = system "unzip -o #{@tmp_file_path} -d #{@path_unzip_folder}"
19
+ FileUtils::rm @tmp_file_path if unzipped?
20
+
21
+ if unzipped?
22
+ puts "Unzipped course"
23
+
24
+ self
25
+ else
26
+ raise("Unfortunately we doesn't unzipped transcript to this course.")
27
+ end
28
+ end
29
+
30
+ def unzipped?
31
+ @unzipped
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module LyndaTranslatorSrt
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'fileutils'
2
+
3
+ module LyndaTranslatorSrt
4
+ class Zipper
5
+ attr_reader :zipname
6
+
7
+ def initialize(params)
8
+ @params = params
9
+ end
10
+
11
+ def zip
12
+ @zipname = "#{@params[:root_folder_name]}.zip"
13
+ path_zipfile = @params[:save_to] + @zipname
14
+
15
+ @zipped = system "7z a -tzip #{path_zipfile} -w #{@params[:root_folder_path]}"
16
+ puts @params[:root_folder_path]
17
+
18
+ cleaner if zipped?
19
+
20
+ if zipped?
21
+ puts "Zipped course"
22
+
23
+ self
24
+ else
25
+ raise("Unfortunately we doesn't zipped transcript to this course.")
26
+ end
27
+ end
28
+
29
+ def zipped?
30
+ @zipped
31
+ end
32
+
33
+ private
34
+
35
+ def cleaner
36
+ FileUtils::rm_r @params[:path_unzip_folder]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'lynda_translator_srt/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lynda-translator-srt'
7
+ spec.version = LyndaTranslatorSrt::VERSION
8
+ spec.authors = ['Vadim Poplavskiy']
9
+ spec.email = ['im@demetrodon.com']
10
+ spec.summary = %q{Downloader and translator subs to coursers Lynda.com}
11
+ spec.description = ''
12
+ spec.homepage = 'https://github.com/demetrodon/lynda-translator-srt'
13
+ spec.license = 'New BSD'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_dependency 'translator-srt'
19
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lynda-translator-srt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vadim Poplavskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: translator-srt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: ''
28
+ email:
29
+ - im@demetrodon.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE
37
+ - lib/lynda_translator_srt.rb
38
+ - lib/lynda_translator_srt/srt_original/downloader.rb
39
+ - lib/lynda_translator_srt/srt_original/reader.rb
40
+ - lib/lynda_translator_srt/srt_original/unzipper.rb
41
+ - lib/lynda_translator_srt/version.rb
42
+ - lib/lynda_translator_srt/zipper.rb
43
+ - lynda_translator_srt.gemspec
44
+ homepage: https://github.com/demetrodon/lynda-translator-srt
45
+ licenses:
46
+ - New BSD
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Downloader and translator subs to coursers Lynda.com
68
+ test_files: []