subfinder 0.0.2.4 → 0.0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 491dbbfa5744087587e018ebce5fe4bfa022d16f393b0f8011c32dc4e1aae0ac
4
- data.tar.gz: 664aa2629ff27e846c2f38fd2045f89dc2a9f1ca9b965cbbaf9a9e52c1bd5f35
3
+ metadata.gz: 5b5c0c954cb1ef5d74e2de7e5112290116330a58264932c14f4dd55ffcf34bd0
4
+ data.tar.gz: 1ff9be3de677d9060d027823525bb4d06d80a40e070629fe32f374b6baf05bbe
5
5
  SHA512:
6
- metadata.gz: 64ae660718fda1bf21e8dedbcedc6166e3533150ad65d7059978d6ad2526323ed8a5debb33b58f390eed4aaedfafee25da09f3a11b663064800d531318fe9096
7
- data.tar.gz: b902c1a019c08e80cc1fb2572c4e9646a523be3ba5826a5d66f128ba54f9d6e765c335879eee53537d3b2e59e79d096c29248d9924cf841582cf242c39bdc505
6
+ metadata.gz: ecdab554e2d3c5f0bcbb36b41fbbb51dff9d047084f0d82a0332591b77d6a9996716643db6d6f76443e83e194594853cee95ec1b05c6a6c2013dcd2e4032bac3
7
+ data.tar.gz: 1ebe24da29c9b1628e124ddb9cbbb66a5af5bdb0ae2732220d22d1ad16f487e10a201080dd678b99cefd4aa86f73a48e1ef2eaf1ce6099d6a4573372b0bce8ea
@@ -35,7 +35,8 @@ jobs:
35
35
  - run:
36
36
  name: install dependencies
37
37
  command: |
38
- bundle install --jobs=4 --retry=3 --path vendor/bundle
38
+ #bundle install --jobs=4 --retry=3 --path vendor/bundle
39
+ bundle install --jobs=4 --retry=3
39
40
 
40
41
  - save_cache:
41
42
  paths:
@@ -51,7 +52,7 @@ jobs:
51
52
  name: run tests
52
53
  command: |
53
54
  mkdir /tmp/test-results
54
- rake test
55
+ rake test --trace
55
56
 
56
57
  # collect reports
57
58
  - store_test_results:
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  .DS*
10
+ *.swp
11
+ /dryrun_test_directory/
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
- ruby "2.5.1"
4
+ ruby '2.5.1'
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in subfinder.gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- subfinder (0.0.2.3)
4
+ subfinder (0.0.2.4)
5
5
  bundler (~> 2.0.1)
6
6
  colorize (~> 0.8)
7
7
  nokogiri (~> 1.10.1)
@@ -54,7 +54,6 @@ PLATFORMS
54
54
  ruby
55
55
 
56
56
  DEPENDENCIES
57
- colorize (~> 0.8)
58
57
  minitest (~> 5.0)
59
58
  subfinder!
60
59
  test-unit (~> 3.1.8)
data/README.md CHANGED
@@ -10,26 +10,19 @@ You have a TV series without subtitles. Open the terminal, go to the folder wher
10
10
 
11
11
  It works fine with the video file names which followed `S01E01` naming format.
12
12
 
13
- ## Installation
14
13
 
15
-
14
+ ## Installation
16
15
 
17
16
  First you need to have `Ruby` and `Gem` on your machine.
18
17
 
19
-
20
-
21
18
  Then simply run:
22
19
 
23
-
24
-
25
20
  `$ gem install subfinder`
26
21
 
27
22
  Without any switches, this will unzip all zipped or compressed files and find/rename them to correspondent video file. Also you can provide the URL for `subscene.com` list page with `-u` and it would download the correct file and do the rest.
28
23
 
29
- ## Usage
30
-
31
24
 
32
-
25
+ ## Usage
33
26
 
34
27
  `$ subfinder -u https://subscene.com/subtitles/the-kominsky-method -l fa`
35
28
 
@@ -37,69 +30,31 @@ Without any switches, this will unzip all zipped or compressed files and find/re
37
30
 
38
31
  - Use `-u` or `--url` to specify a URL page of a TV series on `subscene.com` website.
39
32
 
40
- - Also see `sunfinder -h` for help
33
+ - Run `subfinder --dryrun` to create set of mock files on you current directory and running Subfinder.
41
34
 
42
-
35
+ - Also see `sunfinder -h` for help
43
36
 
44
37
 
38
+
45
39
  ## Development
46
40
 
47
41
  * Please report any broken thing using Github issues *
48
42
 
49
43
  To run tests, run `rake test`.
50
44
 
51
-
52
- To see all logs, run with `-d` or `--degub`
53
-
45
+ To see all logs, run with `-d` or `--degub`
54
46
 
55
47
  Clone the project. Make changes and then `rake build` inside the project folder to create Gem.
56
48
 
57
49
  Then `gem install pkg/subfinder-0.0.1.gem` to install it locally.
58
50
 
59
- Create a temp folder and run `movies_list_creator.rb` inside that folder. It will create fake files.
60
-
61
-
62
-
63
51
 
64
52
  ## License
65
53
 
66
-
67
-
68
54
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
69
55
 
70
-
71
-
72
56
 
73
57
  # TODO
74
58
 
75
- - [x] get sub title language
76
-
77
- - [x] extract all files
78
-
79
- - [x] list all files
80
-
81
- - [x] match srt for each video file
82
-
83
- - [x] rename all matches
84
-
85
- - [x] move all other files to extract folder
86
-
87
- - [x] if not available then find it online test
88
-
89
- - [x] if not available then find it online code
90
-
91
- - [x] if language sub is not available then find English
92
-
93
- - [x] download match subtitle
94
-
95
- - [x] check for internet connectivity or issue for accessing blocked websites
96
-
97
- - [ ] add all language codes
98
-
99
- - [ ] move all other files from sub folders to main folder when extracting
100
-
101
- - [ ] add messages for timeout on web browsing
102
-
103
- - [ ] save user entered config for later use
59
+ - Add all language codes
104
60
 
105
- - [ ] Writing article about it (VCR)
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'subfinder'
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'bundler/setup'
3
5
  require_relative '../lib/subfinder'
4
6
 
@@ -1,14 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'colorize'
3
5
  require 'logger'
4
6
  require 'optparse'
5
7
  require 'zip'
8
+ require 'rest-client'
6
9
 
7
10
  require_relative 'subfinder/version'
8
11
  require_relative 'subfinder/subtitle'
9
12
  require_relative 'subfinder/config'
10
13
  require_relative 'subfinder/main'
11
14
  require_relative 'subfinder/logger'
15
+ require_relative 'subfinder/dryrun'
12
16
 
13
17
  require_relative 'subfinder/parser/args'
14
18
  require_relative 'subfinder/parser/files'
@@ -1,8 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subfinder
4
+ # Configuration for different running modes
2
5
  class Config
3
6
  @video_formats = %w[.avi .mp4 .mkv]
4
7
  class << self
5
- attr_accessor :subtitles, :language, :url, :working_dir, :video_formats, :debug
8
+ attr_accessor :subtitles, :language, :url,
9
+ :working_dir, :video_formats, :debug,
10
+ :quiet
6
11
  end
7
12
  end
8
13
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subfinder
4
+ # Would create a folder, create fake files and run Subfinder
5
+ class Dryrun
6
+ class << self
7
+ def enable
8
+ Logger.info 'Runnign in Dryrun mode.'
9
+ dryrun_dir = Dir.pwd + '/dryrun_test_directory'
10
+ Dir.mkdir(dryrun_dir)
11
+ Config.working_dir = dryrun_dir
12
+ create_mock_files_in dryrun_dir
13
+ end
14
+
15
+ def mock_list_file
16
+ # files with different subtitle file names
17
+ files = video_subtitle_pairs
18
+
19
+ # Files with space in their names
20
+ files += ['The Mechanism S01E06 - The Silkworm pt1 x264 RB58.mp4',
21
+ 'The Mechanism S01E06.pilot.720p BluRay BRRip 480p'\
22
+ ' BoB-edited version.srt']
23
+
24
+ # Dingle file without subtutles
25
+ files + %w[The.Mechanism.S02E03.1080p.HDTV.x264.mp4]
26
+ end
27
+
28
+ def video_subtitle_pairs
29
+ %w(
30
+ Mechanism.The.S01E01.1080p.5.1Ch.BluRay.ReEnc-DeeJayAhmed.mkv
31
+ The.Mechanism.S01E02.HDTV.x264-SVA[eztv].mkv
32
+ The.Mechanism.S01E03.1080p.HDTV.x264.mp4
33
+ The.Mechanism.S01E04.720p.WEB-DL.DibaMoviez.mkv
34
+ Agatha.Christies.Poirot.S13E02.1080p.BluRay.x264.mkv
35
+ The.Mechanism.S01E01.WEB-DL.srt
36
+ The.Mechanism.S01E02.HDTV.x264-SVA.srt
37
+ The.Mechanism.S01E03.720p.HDTV.x264-IMMERSE.srt
38
+ The.Mechanism.S01E04.HDTV.x264.KILLERS.HI.srx.srt
39
+ The.Mechanism.S01E05.720p.WEB.H264-MEMENTO.srt
40
+ )
41
+ end
42
+
43
+ def create_mock_files_in(folder)
44
+ mock_list_file.each do |file_name|
45
+ File.open(folder + '/' + file_name, 'w') do |f|
46
+ f.write('this is sample file')
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subfinder
4
+ # Logger class, shoud initiate at the start of the program
2
5
  class Logger < ::Logger
3
6
  class << self
4
7
  def setting
@@ -11,7 +14,7 @@ module Subfinder
11
14
  end
12
15
 
13
16
  def info(str)
14
- @logger.info(str)
17
+ @logger.info(str) unless Config.quiet
15
18
  end
16
19
 
17
20
  def debug(str)
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subfinder
4
+ # Initialize config and then search and match subtitles
2
5
  class Main
3
6
  class << self
4
7
  def run(args)
5
- Subfinder::Logger.setting
6
- Subfinder::Parser::Args.new args
7
- Subfinder::Subtitle.new.match
8
+ Logger.setting
9
+ Parser::Args.new args
10
+ Subtitle.new.match
8
11
  end
9
12
  end
10
13
  end
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subfinder
2
4
  module Parser
3
5
  class Args
6
+ # Initialze and parse input args
4
7
  def initialize(args)
5
8
  @args = args
6
9
  parse_args
7
- validate_required_args
10
+ set_default_values
8
11
  end
9
12
 
10
13
  def parse_args
@@ -12,27 +15,30 @@ module Subfinder
12
15
  opts.banner = usage_msg
13
16
  opts.separator ''
14
17
  opts.separator 'options:'
15
- opts.on('-u', '--url url', 'Set subscene url page') { |url| Config.url = url }
18
+ opts.on('-u', '--url url', 'Set Subscene url page') { |url| Config.url = url }
16
19
  opts.on('-l', '--language language', 'Set subtitle language') { |language| Config.language = language }
17
- opts.on('-v', '--version', 'Show the Compare Crypto version') { puts("Subfinder #{Subfinder::VERSION}"); exit }
18
- opts.on('-h', '--help', 'Show this message') { puts(opts); exit }
19
- opts.on('-d', '--debug', 'debug') { Config.debug = true }
20
+ opts.on('-v', '--version', 'Show the Subfinder version') { puts("Subfinder #{Subfinder::VERSION}"); exit }
21
+ opts.on('-h', '--help', 'You used it just now') { puts(opts); exit }
22
+ opts.on('-d', '--debug', 'Run in debug mode') { Config.debug = true }
23
+ opts.on('-q', '--quiet', 'Display no message') { Config.quiet = true }
24
+ opts.on('--dryrun', 'Test application on mock files') { Subfinder::Dryrun.enable }
20
25
 
21
26
  opts.parse!(@args)
22
27
  end
23
28
 
24
29
  private
25
30
 
26
- def validate_required_args
31
+ def set_default_values
32
+ # Set English as a default value for subtitle language if not provided
27
33
  Config.language ||= 'en'
28
- Config.working_dir = Dir.pwd
34
+ Config.working_dir ||= Dir.pwd
29
35
  end
30
36
 
31
37
  def usage_msg
32
38
  usage = '
33
39
  Usage:
34
40
  subfinder [options]
35
- See https://github.com/sizief/subfinder for more information.
41
+ See https://github.com/sizief/subfinder for more information.
36
42
  '
37
43
  usage
38
44
  end
@@ -1,7 +1,8 @@
1
- require 'rest-client'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Subfinder
4
4
  module Parser
5
+ # Download subtitle files from Internet
5
6
  class Download
6
7
  def initialize(url)
7
8
  @url = url
@@ -9,7 +10,7 @@ module Subfinder
9
10
 
10
11
  def save
11
12
  res = RestClient.get @url
12
- return false unless @url =~ URI::regexp
13
+ return false unless @url =~ URI::DEFAULT_PARSER.make_regexp
13
14
  return false unless response_is_healthy? res
14
15
 
15
16
  file_name = res.headers[:content_disposition].split('=')[1]
@@ -23,11 +24,11 @@ module Subfinder
23
24
 
24
25
  def response_is_healthy?(res)
25
26
  if res.code != 200
26
- Logger.info "Error when downloading '#{@url}'\n Error message: resposnse code is #{res.code}\n".red
27
- false
27
+ Logger.info "Error when downloading '#{@url}'\n resposnse code: #{res.code}\n".red
28
+ return false
28
29
  elsif res.body.include? 'An error occurred while processing your request.'
29
- Logger.info "Error when downloading '#{@url}'\n Error message: 'An error occurred while processing your request.'\n".red
30
- false
30
+ Logger.info "Error downloading '#{@url}'. Try Again in few seconds".red
31
+ return false
31
32
  else
32
33
  true
33
34
  end
@@ -1,15 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subfinder
2
4
  module Parser
5
+ # All file and folder related actions
3
6
  class Files
4
7
  class << self
5
8
  def list
6
9
  prepare_file_list
7
- Dir["#{Config.working_dir}/*"]
10
+ Dir["#{pwd}/*"]
8
11
  end
9
12
 
10
13
  def prepare_file_list
11
- files = Dir["#{Config.working_dir}/*"]
12
- compressed_files = files.select { |file| ['.zip', '.rar'].include? File.extname(file) }
14
+ files = Dir["#{pwd}/*"]
15
+ compressed_files = files.select do |file|
16
+ ['.zip', '.rar'].include? File.extname(file)
17
+ end
13
18
  extract_all compressed_files
14
19
  move_compressed_files compressed_files
15
20
  end
@@ -18,7 +23,7 @@ module Subfinder
18
23
  array_list.each do |file|
19
24
  Zip::File.open(file) do |zip_file|
20
25
  zip_file.each do |entry|
21
- file_path = Config.working_dir + '/' + entry.name
26
+ file_path = pwd + '/' + entry.name
22
27
  unless File.exist? file_path
23
28
  Logger.info "Extracting #{entry.name}"
24
29
  entry.extract(file_path)
@@ -29,11 +34,17 @@ module Subfinder
29
34
  end
30
35
 
31
36
  def move_compressed_files(compressed_files)
32
- unless compressed_files.empty?
33
- Dir.mkdir(Config.working_dir + '/compressed') unless File.exist?(Config.working_dir + '/compressed')
34
- compressed_files.each { |f| File.rename(f, File.dirname(f) + '/compressed/' + File.basename(f)) }
37
+ return if compressed_files.empty?
38
+
39
+ Dir.mkdir("#{pwd}/compressed") unless File.exist?("#{pwd}/compressed")
40
+ compressed_files.each do |f|
41
+ File.rename(f, File.dirname(f) + '/compressed/' + File.basename(f))
35
42
  end
36
43
  end
44
+
45
+ def pwd
46
+ Config.working_dir
47
+ end
37
48
  end
38
49
  end
39
50
  end