ehbrs_ruby_utils 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (19) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs_ruby_utils/version.rb +1 -1
  3. data/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode.rb +30 -0
  4. data/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title.rb +26 -0
  5. data/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers.rb +13 -0
  6. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/episode.rb +44 -0
  7. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/subtitle.rb +39 -0
  8. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/title.rb +37 -0
  9. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors.rb +13 -0
  10. data/lib/ehbrs_ruby_utils/videos/opensubtitles.rb +9 -0
  11. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb +7 -0
  12. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html +993 -0
  13. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml +5 -0
  14. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html +478 -0
  15. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml +43 -0
  16. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb +7 -0
  17. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html +763 -0
  18. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml +22 -0
  19. metadata +61 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5acf6fe93e603883c1a2e9f816ffadcbd8d4a38bd20ccf813735e844f7b2e348
4
- data.tar.gz: f497605aacb3b71e4e0b45faaac5bd3f9ead04fda51e6ffef3593ef88cfe09d7
3
+ metadata.gz: 5b5a4ff5b36fa6184fe024c0dd3c31514b03656e9f31fc8f9d680bc0d71a46f6
4
+ data.tar.gz: 168d749fb34a32df6e65e31ffca81ded6123b7b96e79e74b60d2d7f749800fd6
5
5
  SHA512:
6
- metadata.gz: b4acafae07d720b20b8102e2757c39dee8a8ee629c68e05110440324a77850e147ac2a8954a0644c6b85a96cdb5b90db306f417b09be6b9c538a496387b6ad1a
7
- data.tar.gz: b4b6437fb9ad509308540a7913d6021c378f1e5450d66a65871ae4f5356adc6222db771840b666d672c75bb18e7212673ef00a79e94da70c65a4fd2ecbbbf931
6
+ metadata.gz: 86ede6154dc60b53a6fc4b871782be51e9f88e8abefd4ed82f0d8237e8e71935ac69b62406d00cee10c05090051e04deca3106ca3a57f2ec372bc8c97bfe3d84
7
+ data.tar.gz: 47bf252d71924e6f385ff8b9d99013475ddeda2e9975c49a913abcfcd84ad109ade0beff12e13781b80151c127d453ee33891891533e786d98f9726384e51ca6
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.18.0'
4
+ VERSION = '0.19.0'
5
5
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/html/item_list'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module Videos
8
+ module Opensubtitles
9
+ module Parsers
10
+ class Episode < ::Aranha::Parsers::Html::ItemList
11
+ ITEMS_XPATH = '//table[@id = "search_results"]/tbody/tr[starts-with(@id, "name")]'
12
+
13
+ field :href, :string, './/a[contains(@href, "/subtitleserve/")]/@href'
14
+
15
+ def items_xpath
16
+ ITEMS_XPATH
17
+ end
18
+
19
+ def data
20
+ { subtitles: items_data, next_page_href: next_page_href }
21
+ end
22
+
23
+ def next_page_href
24
+ nokogiri.at_xpath('//*[@id = "pager"]//a[text() = ">>"]/@href').if_present(&:text)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/html/item_list'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module Videos
8
+ module Opensubtitles
9
+ module Parsers
10
+ class Title < ::Aranha::Parsers::Html::ItemList
11
+ ITEMS_XPATH = '//table[@id = "search_results"]/tbody/tr[@itemprop = "episode"]'
12
+
13
+ field :href, :string, './/a[@itemprop = "url"]/@href'
14
+
15
+ def items_xpath
16
+ ITEMS_XPATH
17
+ end
18
+
19
+ def data
20
+ { episodes: items_data }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ module Opensubtitles
8
+ module Parsers
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/default_processor'
4
+ require 'ehbrs_ruby_utils/videos/opensubtitles/parsers/episode'
5
+ require 'ehbrs_ruby_utils/videos/opensubtitles/processors/subtitle'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module EhbrsRubyUtils
9
+ module Videos
10
+ module Opensubtitles
11
+ module Processors
12
+ class Episode < ::Aranha::DefaultProcessor
13
+ enable_simple_cache
14
+ enable_speaker
15
+
16
+ def perform
17
+ infov source_uri, subtitles.count
18
+ subtitles.each(&:perform)
19
+ next_page.if_present(&:perform)
20
+ end
21
+
22
+ private
23
+
24
+ def next_page_uncached
25
+ data.fetch(:next_page_href)
26
+ .if_present { |v| self.class.new(source_uri + v, extra_data) }
27
+ end
28
+
29
+ def subtitle_uri(subtitle_data)
30
+ source_uri + subtitle_data.fetch(:href)
31
+ end
32
+
33
+ def subtitles_uncached
34
+ data.fetch(:subtitles).map do |subtitle_data|
35
+ ::EhbrsRubyUtils::Videos::Opensubtitles::Processors::Subtitle.new(
36
+ subtitle_uri(subtitle_data), extra_data
37
+ )
38
+ end + next_page.if_present([], &:subtitles)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/default_processor'
4
+ require 'eac_fs/cached_download'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EhbrsRubyUtils
8
+ module Videos
9
+ module Opensubtitles
10
+ module Processors
11
+ class Subtitle < ::Aranha::DefaultProcessor
12
+ enable_simple_cache
13
+ enable_speaker
14
+
15
+ def perform
16
+ infov ' * ', source_uri
17
+ assert_download
18
+ rescue ::RuntimeError => e
19
+ error(e)
20
+ end
21
+
22
+ private
23
+
24
+ def assert_download
25
+ cached_download.assert
26
+ end
27
+
28
+ def cached_download_uncached
29
+ ::EacFs::CachedDownload.new(source_uri, fs_cache)
30
+ end
31
+
32
+ def fs_object_id
33
+ source_uri.to_s.parameterize
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/default_processor'
4
+ require 'ehbrs_ruby_utils/videos/opensubtitles/parsers/title'
5
+ require 'ehbrs_ruby_utils/videos/opensubtitles/processors/episode'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module EhbrsRubyUtils
9
+ module Videos
10
+ module Opensubtitles
11
+ module Processors
12
+ class Title < ::Aranha::DefaultProcessor
13
+ enable_simple_cache
14
+ enable_speaker
15
+
16
+ def perform
17
+ infov 'Episodes', episodes.count
18
+ episodes.each(&:perform)
19
+ end
20
+
21
+ private
22
+
23
+ def episode_uri(episode_data)
24
+ source_uri + episode_data.fetch(:href)
25
+ end
26
+
27
+ def episodes_uncached
28
+ data.fetch(:episodes).map do |episode_data|
29
+ ::EhbrsRubyUtils::Videos::Opensubtitles::Processors::Episode
30
+ .new(episode_uri(episode_data), extra_data)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ module Opensubtitles
8
+ module Processors
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Opensubtitles
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/videos/opensubtitles/parsers/episode'
4
+
5
+ RSpec.describe ::EhbrsRubyUtils::Videos::Opensubtitles::Parsers::Episode do
6
+ include_examples 'source_target_fixtures', __FILE__
7
+ end