ehbrs_ruby_utils 0.18.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode.rb +30 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title.rb +26 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers.rb +13 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/episode.rb +44 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/subtitle.rb +39 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/title.rb +37 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors.rb +13 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles.rb +9 -0
- data/lib/ehbrs_ruby_utils/web_utils/instance.rb +23 -13
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb +7 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html +993 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml +5 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html +478 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml +43 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb +7 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html +763 -0
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml +22 -0
- metadata +50 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd6cda8266cb8a597f2a1c3847fca05b4002a9d387feae26339a1e9d808191d6
|
4
|
+
data.tar.gz: b69eab41353b59a452dbb4a44a23e54fc9c34458902d4e48e1d1dc423a1e63c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced46b8aa2ebecd983986c3f6ff6e386aeeb0e3741457933a8da7d24cc945bc743a75695aea753aff086a7fe536608edd0631b1f538ae62d4b05b13409de1ae1
|
7
|
+
data.tar.gz: '0673885d858f19ed325b95708c749e7b25cf20c0ac3f9b2e2a78cafb151c48b696f7ac1aa4534c9f81ac591b3e68714489f41f40982884bfb1ea39396fce96a7'
|
@@ -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,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
|
@@ -1,14 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_rest/api'
|
3
4
|
require 'eac_ruby_utils/core_ext'
|
4
5
|
require 'avm/instances/base'
|
5
|
-
require 'httpclient'
|
6
6
|
|
7
7
|
module EhbrsRubyUtils
|
8
8
|
module WebUtils
|
9
9
|
class Instance < ::Avm::Instances::Base
|
10
10
|
require_sub __FILE__
|
11
11
|
|
12
|
+
# @return [EacRest::Api]
|
13
|
+
def api
|
14
|
+
::EacRest::Api.new(root_url, read_entry(:admin_username), read_entry(:admin_password))
|
15
|
+
end
|
16
|
+
|
12
17
|
def finances
|
13
18
|
@finances ||= ::EhbrsRubyUtils::WebUtils::Instance::Finances.new(self)
|
14
19
|
end
|
@@ -17,21 +22,26 @@ module EhbrsRubyUtils
|
|
17
22
|
read_entry(::Avm::Instances::EntryKeys::WEB_URL)
|
18
23
|
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
# @param resource_url_suffix [String]
|
26
|
+
# @param options [Hash]
|
27
|
+
# @return [EacRest::Response]
|
24
28
|
def http_request(resource_url_suffix, options = {})
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
options = http_request_options(options)
|
30
|
+
r = api.request(resource_url_suffix).verb(options.verb).headers(options.headers)
|
31
|
+
.body_data(options.body_data).response
|
32
|
+
::Struct.new(:status, :body).new(r.status, r.body_str)
|
28
33
|
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
# @return [::Struct.new(:verb, :body_data, :headers)]
|
38
|
+
def http_request_options(options)
|
39
|
+
options = options.to_options_consumer
|
40
|
+
verb = options.consume(:method, :get).to_sym
|
41
|
+
body_data = options.consume(:body)
|
42
|
+
headers = options.consume(:header)
|
43
|
+
options.validate
|
44
|
+
::Struct.new(:verb, :body_data, :headers).new(verb, body_data, headers)
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|