download_tv 2.8.3 → 2.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c202232c01422b793ebb302b44517ae6e81e8d95fa9f30dbd5a87014b88386f
4
- data.tar.gz: fdff3db7c0590cfce73cef42cb8775734bb980867901a087c8af362a764ffa9f
3
+ metadata.gz: c39ab8c419d632acdd80ea9a072dbb119e27bec036d8e631bd1fe677a7cdc133
4
+ data.tar.gz: 6df0b53c0faedfa474631b8fb9c071b2bb3465a0b2172e599e2cd57d3d07b995
5
5
  SHA512:
6
- metadata.gz: f725cb5dff565e302ce166be63c142e5aeb3693e7379e135f3d7cb21de1f8fdae1a7df53f6a96abdf44ef94fcc16f4412c9a2d3d64da6c060ee5de6844eae5b6
7
- data.tar.gz: 07576b4a5194b8929a1107ef233154f72237c72d72d2e9c8ba787613a0f8047cdc9dade2a83501b1434b99181149f161cf946d33211caefe0ef7b269314e10fc
6
+ metadata.gz: e455efa1fb3c2a86b480f3e1cbc814dc97297e45f26eb3b611cd740d19033682980e2f4a85a69b8f9b16f2575806d625a63290b631966788838bde3001b9c803
7
+ data.tar.gz: 65d73597d67dc3f03280d18d32d11a1b32d10e1c53ea3b8bac6cdda910de4af2800e90010d6a558906830837d770a2e96229059a620d62307b8935832b20ec61
@@ -15,19 +15,15 @@ on:
15
15
 
16
16
  jobs:
17
17
  test:
18
-
19
18
  runs-on: ubuntu-latest
20
19
  strategy:
21
20
  matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
21
+ ruby-version: ['2.7', '3.0']
23
22
 
24
23
  steps:
25
24
  - uses: actions/checkout@v2
26
25
  - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
26
+ uses: ruby/setup-ruby@v1
31
27
  with:
32
28
  ruby-version: ${{ matrix.ruby-version }}
33
29
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Next (unreleased)
4
4
 
5
+ ## 2.8.4 (2024-08-19)
6
+
7
+ * Grabbers
8
+ * ThePirateBay: fix with upstream. Use tpb api.
9
+
5
10
  ## 2.8.3 (2024-02-20)
6
11
 
7
12
  * Grabbers
@@ -180,8 +180,9 @@ module DownloadTV
180
180
  def reject_ignored(shows)
181
181
  shows.reject do |i|
182
182
  # Remove season+episode
183
- @config[:ignored]
184
- .include?(i.split(' ')[0..-2].join(' ').downcase)
183
+ @config[:ignored].include?(
184
+ i.split(' ')[0..-2].join(' ').downcase
185
+ )
185
186
  end
186
187
  end
187
188
 
@@ -4,27 +4,42 @@ module DownloadTV
4
4
  ##
5
5
  # ThePirateBay grabber
6
6
  class ThePirateBay < LinkGrabber
7
- def initialize(tpb_proxy = 'https://tpb30.ukpass.co/')
8
- proxy = tpb_proxy.gsub(%r{/+$}, '')
9
-
10
- super("#{proxy}/search/%s/0/7/0")
7
+ TRACKERS = %w[
8
+ udp://tracker.coppersurfer.tk:6969/announce
9
+ udp://tracker.openbittorrent.com:6969/announce
10
+ udp://tracker.opentrackr.org:1337
11
+ udp://movies.zsw.ca:6969/announce
12
+ udp://tracker.dler.org:6969/announce
13
+ udp://opentracker.i2p.rocks:6969/announce
14
+ udp://open.stealth.si:80/announce
15
+ udp://tracker.0x.tf:6969/announce
16
+ ]
17
+
18
+ def initialize
19
+ super("https://tpb36.ukpass.co/apibay/q.php?q=%s&cat=")
11
20
  end
12
21
 
13
22
  def get_links(show)
14
23
  search = format(@url, show)
15
24
 
16
- # Skip the header
17
- data = agent.get(search).search('#searchResult tr').drop 1
25
+ data = agent.get(search)
26
+ parsed = JSON.parse(data.body)
27
+
28
+ raise NoTorrentsError if parsed.size == 1 && parsed.first['name'] == 'No results returned'
18
29
 
19
- raise NoTorrentsError if data.empty?
30
+ parsed.map do |elem|
31
+ [elem['name'], build_magnet(elem['info_hash'], elem['name'])]
32
+ end
33
+ end
20
34
 
21
- # Second cell of each row contains links and name
22
- results = data.map { |d| d.search('td')[1] }
35
+ private
23
36
 
24
- names = results.collect { |i| i.search('.detName').text.strip }
25
- links = results.collect { |i| i.search('a')[1].attribute('href').text }
37
+ def build_magnet(torrent_hash, name)
38
+ "magnet:?xt=urn:btih:#{torrent_hash}&dn=#{CGI.escape(name)}#{trackers_params}"
39
+ end
26
40
 
27
- names.zip(links)
41
+ def trackers_params
42
+ trackers_params ||= "&tr=#{TRACKERS.map { |tracker| CGI.escape(tracker) }.join('&tr=')}"
28
43
  end
29
44
  end
30
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DownloadTV
4
- VERSION = '2.8.3'
4
+ VERSION = '2.8.4'
5
5
  end
@@ -2,28 +2,29 @@
2
2
 
3
3
  describe DownloadTV::Torrent do
4
4
  let(:default_grabber) { nil }
5
- let(:eztv_mock) { double('eztv') }
6
- let(:torrentz_mock) { double('torrentz') }
7
- let(:tpb_mock) { double('tpb') }
8
- let(:torrentgalaxy_mock) { double('torrentgalaxy') }
5
+ let(:third_grabber) { double('eztv') }
6
+ let(:second_grabber) { double('torrentz') }
7
+ let(:fourth_grabber) { double('tpb') }
8
+ let(:first_grabber) { double('torrentgalaxy') }
9
9
  let(:test_show) { double('test_show') }
10
10
  subject { described_class.new(default_grabber) }
11
11
 
12
12
  before :each do
13
- allow(DownloadTV::TorrentGalaxy).to receive(:new).and_return torrentgalaxy_mock
14
- allow(DownloadTV::Torrentz).to receive(:new).and_return torrentz_mock
15
- allow(DownloadTV::Eztv).to receive(:new).and_return eztv_mock
16
- # allow(DownloadTV::ThePirateBay).to receive(:new).and_return tpb_mock
17
-
18
- allow(torrentgalaxy_mock).to receive(:online?).and_return(true)
19
- allow(torrentz_mock).to receive(:online?).and_return(true)
20
- allow(eztv_mock).to receive(:online?).and_return(true)
13
+ allow(DownloadTV::Torrentz).to receive(:new).and_return first_grabber
14
+ allow(DownloadTV::ThePirateBay).to receive(:new).and_return second_grabber
15
+ allow(DownloadTV::Eztv).to receive(:new).and_return third_grabber
16
+ # allow(DownloadTV::TorrentGalaxy).to receive(:new).and_return fourth_grabber
17
+
18
+ allow(first_grabber).to receive(:online?).and_return(true)
19
+ allow(second_grabber).to receive(:online?).and_return(true)
20
+ allow(third_grabber).to receive(:online?).and_return(true)
21
+ # allow(fourth_grabber).to receive(:online?).and_return(true)
21
22
  end
22
23
 
23
24
  describe 'Torrent.grabbers' do
24
25
  it 'returns the list of grabbers' do
25
26
  # This order is assumed in the other specs, so explicitly checking it here
26
- expect(described_class.grabbers).to eq %w[TorrentGalaxy Torrentz Eztv]
27
+ expect(described_class.grabbers).to eq %w[Torrentz ThePirateBay Eztv]
27
28
 
28
29
  end
29
30
  end
@@ -31,20 +32,20 @@ describe DownloadTV::Torrent do
31
32
  describe '#get_links' do
32
33
  it 'will use the first grabber and return its #get_link result' do
33
34
  result = double('result')
34
- expect(torrentgalaxy_mock).to receive(:get_links).with(test_show).and_return(result)
35
+ expect(first_grabber).to receive(:get_links).with(test_show).and_return(result)
35
36
 
36
37
  result = subject.get_links(test_show)
37
38
  end
38
39
 
39
40
  context 'when the first grabber is offline' do
40
41
  before do
41
- allow(torrentgalaxy_mock).to receive(:online?).and_return(false)
42
+ allow(first_grabber).to receive(:online?).and_return(false)
42
43
  end
43
44
 
44
45
  it 'will use the second grabber' do
45
- expect(torrentgalaxy_mock).not_to receive(:get_links)
46
- expect(torrentz_mock).to receive(:get_links).with(test_show)
47
- expect(eztv_mock).not_to receive(:get_links)
46
+ expect(first_grabber).not_to receive(:get_links)
47
+ expect(second_grabber).to receive(:get_links).with(test_show)
48
+ expect(third_grabber).not_to receive(:get_links)
48
49
  # Add other torrents here with expectation #not_to receive
49
50
 
50
51
  result = subject.get_links(test_show)
@@ -53,15 +54,15 @@ describe DownloadTV::Torrent do
53
54
 
54
55
  context 'when all the grabbers are offline' do
55
56
  before do
56
- allow(torrentgalaxy_mock).to receive(:online?).and_return(false)
57
- allow(torrentz_mock).to receive(:online?).and_return(false)
58
- allow(eztv_mock).to receive(:online?).and_return(false)
57
+ allow(first_grabber).to receive(:online?).and_return(false)
58
+ allow(second_grabber).to receive(:online?).and_return(false)
59
+ allow(third_grabber).to receive(:online?).and_return(false)
59
60
  end
60
61
 
61
62
  it 'will exit' do
62
- expect(torrentgalaxy_mock).not_to receive(:get_links)
63
- expect(torrentz_mock).not_to receive(:get_links)
64
- expect(eztv_mock).not_to receive(:get_links)
63
+ expect(first_grabber).not_to receive(:get_links)
64
+ expect(second_grabber).not_to receive(:get_links)
65
+ expect(third_grabber).not_to receive(:get_links)
65
66
 
66
67
  expect { subject.get_links(test_show) }.to raise_error(SystemExit)
67
68
  end
@@ -69,12 +70,12 @@ describe DownloadTV::Torrent do
69
70
 
70
71
  context 'when one grabber does not find a link' do
71
72
  before do
72
- allow(torrentgalaxy_mock).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
73
+ allow(first_grabber).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
73
74
  end
74
75
 
75
76
  it 'will keep trying until one does' do
76
- expect(torrentgalaxy_mock).to receive(:get_links).ordered
77
- expect(torrentz_mock).to receive(:get_links).ordered
77
+ expect(first_grabber).to receive(:get_links).ordered
78
+ expect(second_grabber).to receive(:get_links).ordered
78
79
 
79
80
  result = subject.get_links(test_show)
80
81
  end
@@ -82,15 +83,15 @@ describe DownloadTV::Torrent do
82
83
 
83
84
  context 'when no grabber can find a link' do
84
85
  before do
85
- allow(torrentgalaxy_mock).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
86
- allow(torrentz_mock).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
87
- allow(eztv_mock).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
86
+ allow(first_grabber).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
87
+ allow(second_grabber).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
88
+ allow(third_grabber).to receive(:get_links).with(test_show).and_raise(DownloadTV::NoTorrentsError)
88
89
  end
89
90
 
90
91
  it 'will return an empty array' do
91
- expect(torrentgalaxy_mock).to receive(:get_links).ordered
92
- expect(torrentz_mock).to receive(:get_links).ordered
93
- expect(eztv_mock).to receive(:get_links).ordered
92
+ expect(first_grabber).to receive(:get_links).ordered
93
+ expect(second_grabber).to receive(:get_links).ordered
94
+ expect(third_grabber).to receive(:get_links).ordered
94
95
 
95
96
  expect(subject.get_links(test_show)).to eq []
96
97
  end
@@ -101,9 +102,9 @@ describe DownloadTV::Torrent do
101
102
 
102
103
  it 'will use that grabber preferently' do
103
104
  test_show = double('test_show')
104
- expect(torrentgalaxy_mock).not_to receive(:get_links)
105
- expect(torrentz_mock).not_to receive(:get_links)
106
- expect(eztv_mock).to receive(:get_links).with(test_show)
105
+ expect(first_grabber).not_to receive(:get_links)
106
+ expect(second_grabber).not_to receive(:get_links)
107
+ expect(third_grabber).to receive(:get_links).with(test_show)
107
108
 
108
109
  result = subject.get_links(test_show)
109
110
  end
@@ -112,7 +113,7 @@ describe DownloadTV::Torrent do
112
113
  context 'when a grabber fails on a run and it is called twice' do
113
114
  before do
114
115
  count = 0
115
- allow(torrentgalaxy_mock).to receive(:get_links).exactly(2).times.with(test_show) do
116
+ allow(first_grabber).to receive(:get_links).exactly(2).times.with(test_show) do
116
117
  count += 1
117
118
  raise DownloadTV::NoTorrentsError if count == 1
118
119
  end
@@ -120,9 +121,9 @@ describe DownloadTV::Torrent do
120
121
  end
121
122
 
122
123
  it 'the second run will use the original order' do
123
- expect(torrentgalaxy_mock).to receive(:get_links).exactly(2).times
124
- expect(torrentz_mock).to receive(:get_links).exactly(1).time
125
- expect(eztv_mock).not_to receive(:get_links)
124
+ expect(first_grabber).to receive(:get_links).exactly(2).times
125
+ expect(second_grabber).to receive(:get_links).exactly(1).time
126
+ expect(third_grabber).not_to receive(:get_links)
126
127
 
127
128
  result = subject.get_links(test_show)
128
129
  result = subject.get_links(test_show)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: download_tv
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.3
4
+ version: 2.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - guille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-20 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler