download_tv 1.0.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: 16bd7893a980f0e82a8679f7c3325e9b31e91841
4
- data.tar.gz: 7ed719b758086d4f0bc5811fc27f8e212dd592f7
3
+ metadata.gz: cd6399aa4f4c7b47b11bfef2797f874a009e9336
4
+ data.tar.gz: 6db536e4abc9ff2e58090ca782a29d2dc28149d1
5
5
  SHA512:
6
- metadata.gz: c4354d813ded87ee149c79cd99112a1a08d5abf86a52e8e0b04f32445186c2806454412f3cd52bd32e9587d79bff3e48a941aaf8426bace28676466e2795e2bd
7
- data.tar.gz: f6e4ae1b8e80a3f9c0f7be4f8a19ec0e7426b9470caf8cc006d6eb14fca7e9d164eac42c5a4599ad95f023281144c48a657daba0d0b19f2f73084a78fd0682ac
6
+ metadata.gz: 88d2844361b6213fe0eea64d0e14cbdcacd42a9f8ce75e29c5136c9fc4a9c748ebc6fb60226d186eee17080c7b5ae40953b8af304f52daaba09bd4d359a00eb6
7
+ data.tar.gz: ed7969953514c6e45be2ee25c808426c4ae3e66482a1e79bd11c632e801cc5f60e941675105a236d9bc652d306f13ed8b3133a4293f08f4d5e46f4b21f0426e4
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  date
2
- config.rb
2
+ config
3
3
  cookie
4
- /Gemfile.lock
4
+ /Gemfile.lock
5
+ /pkg/
data/.travis.yml CHANGED
@@ -3,5 +3,3 @@ language: ruby
3
3
 
4
4
  rvm:
5
5
  - ruby-head
6
-
7
- before_install: cp lib/download_tv/config_example.rb lib/download_tv/config.rb
data/bin/tv CHANGED
@@ -5,6 +5,8 @@ require 'download_tv'
5
5
 
6
6
  options = {}
7
7
  options[:offset] = 0
8
+ options[:auto] = true
9
+ options[:subs] = true
8
10
  options[:dry] = false
9
11
  options[:cmd] = "run"
10
12
 
@@ -28,10 +30,22 @@ opt_parser = OptionParser.new do |opts|
28
30
  options[:arg] = s
29
31
  end
30
32
 
33
+ opts.on("-c", "--configure", "Configures defaults") do
34
+ options[:cmd] = "config"
35
+ end
36
+
31
37
  opts.on("--dry-run", "Don't write to the date file") do |n|
32
38
  options[:dry] = n
33
39
  end
34
40
 
41
+ opts.on("-a", "--[no-]auto", "Automatically find links") do |n|
42
+ options[:auto] = n
43
+ end
44
+
45
+ opts.on("-s", "--[no-]subtitles", "Download subtitles") do |n|
46
+ options[:subs] = n
47
+ end
48
+
35
49
  opts.on_tail("-h", "--help", "Show this message") do
36
50
  puts opts
37
51
  exit
@@ -49,6 +63,8 @@ begin
49
63
  dl.download_single_show(options[:arg])
50
64
  when "file"
51
65
  dl.download_from_file(options[:arg])
66
+ when "config"
67
+ DownloadTV::Configuration.new.change_configuration
52
68
  end
53
69
  rescue Interrupt
54
70
  puts "Interrupt signal detected. Exiting..."
@@ -0,0 +1,39 @@
1
+ module DownloadTV
2
+ class Configuration
3
+ attr_reader :content
4
+
5
+ def initialize
6
+ if File.exists? "config.rb"
7
+ @content = File.open("config", "rb") {|f| Marshal.load(f)}
8
+ else
9
+ @content = {}
10
+ change_configuration
11
+ end
12
+ end
13
+
14
+
15
+ def change_configuration
16
+ if @content[:myepisodes_user]
17
+ print "Enter your MyEpisodes username (#{@content[:myepisodes_user]}) : "
18
+ else
19
+ print "Enter your MyEpisodes username : "
20
+ end
21
+ @content[:myepisodes_user] = STDIN.gets.chomp
22
+ puts
23
+
24
+ print "Save cookie? (y)/n: "
25
+ @content[:cookie] = STDIN.gets.chomp.downcase != "n"
26
+ puts
27
+
28
+ puts "Enter a comma-separated list of shows to ignore: (#{@content[:ignored]})"
29
+ @content[:ignored] = STDIN.gets.chomp
30
+ puts
31
+
32
+ serialize()
33
+ end
34
+
35
+ def serialize()
36
+ File.open("config", "wb") {|f| Marshal.dump(@content, f)}
37
+ end
38
+ end
39
+ end
@@ -1,20 +1,20 @@
1
- begin
2
- require_relative 'config'
3
- rescue LoadError
4
- puts "Config file not found. Try renaming the config_example file to config.rb"
5
- exit
6
- end
7
-
8
1
  module DownloadTV
9
2
 
10
3
  class Downloader
11
4
 
12
5
  attr_reader :offset, :auto, :subs
6
+ attr_accessor :config
13
7
 
14
- def initialize(offset)
8
+ def initialize(offset, auto, subs, config={})
15
9
  @offset = offset.abs
16
- @auto = DownloadTV::CONFIG[:auto]
17
- # @subs = DownloadTV::CONFIG[:subs]
10
+ @auto = auto
11
+ @subs = subs
12
+ if config.empty?
13
+ @config = Configuration.new.content # Load configuration
14
+ else
15
+ @config = config
16
+ end
17
+
18
18
  Thread.abort_on_exception = true
19
19
  end
20
20
 
@@ -39,7 +39,7 @@ module DownloadTV
39
39
 
40
40
  date = check_date
41
41
 
42
- myepisodes = MyEpisodes.new(DownloadTV::CONFIG[:myepisodes_user], DownloadTV::CONFIG[:cookie_path])
42
+ myepisodes = MyEpisodes.new(@config[:myepisodes_user], @config[:cookie])
43
43
  # Log in using cookie by default
44
44
  myepisodes.load_cookie
45
45
  shows = myepisodes.get_shows(date)
@@ -107,7 +107,7 @@ module DownloadTV
107
107
  # Ignored shows
108
108
  s = shows.reject do |i|
109
109
  # Remove season+episode
110
- DownloadTV::CONFIG[:ignored].include?(i.split(" ")[0..-2].join(" "))
110
+ @config[:ignored].include?(i.split(" ")[0..-2].join(" "))
111
111
  end
112
112
 
113
113
  # Removes apostrophes and parens
@@ -2,8 +2,8 @@ module DownloadTV
2
2
 
3
3
  class ThePirateBay < LinkGrabber
4
4
 
5
- def initialize()
6
- proxy = DownloadTV::CONFIG[:tpb_proxy].gsub(/\/+$/, "") || "https://thepiratebay.cr"
5
+ def initialize(tpb_proxy = "https://pirateproxy.cc")
6
+ proxy = tpb_proxy.gsub(/\/+$/, "") || "https://thepiratebay.cr"
7
7
 
8
8
  super("#{proxy}/search/%s/0/7/0")
9
9
 
@@ -2,11 +2,10 @@ module DownloadTV
2
2
 
3
3
  class MyEpisodes
4
4
 
5
- def initialize(user=nil, cookie_path="")
5
+ def initialize(user=nil, save_cookie)
6
6
  @agent = Mechanize.new
7
7
  @user = user
8
- @cookie_path = cookie_path
9
- @save_cookie = cookie_path != ""
8
+ @save_cookie = save_cookie
10
9
  end
11
10
 
12
11
  def login
@@ -36,8 +35,8 @@ module DownloadTV
36
35
  end
37
36
 
38
37
  def load_cookie
39
- if File.exists? @cookie_path
40
- @agent.cookie_jar.load @cookie_path
38
+ if File.exists? "cookie"
39
+ @agent.cookie_jar.load "cookie"
41
40
  page = @agent.get "https://www.myepisodes.com/login.php"
42
41
  if page.links[1].text == "Register"
43
42
  puts "The cookie is invalid/has expired."
@@ -52,7 +51,7 @@ module DownloadTV
52
51
  end
53
52
 
54
53
  def save_cookie
55
- @agent.cookie_jar.save(@cookie_path, session: true)
54
+ @agent.cookie_jar.save("cookie", session: true)
56
55
  @agent
57
56
 
58
57
  end
@@ -5,7 +5,7 @@ module DownloadTV
5
5
  attr_reader :g_names, :g_instances, :n_grabbers
6
6
 
7
7
  def initialize
8
- @g_names = DownloadTV::CONFIG[:grabbers].clone
8
+ @g_names = ["Eztv", "ThePirateBay", "TorrentAPI"]
9
9
  @g_instances = Array.new
10
10
  @n_grabbers = @g_names.size # Initial size
11
11
  @tries = @n_grabbers - 1
@@ -1,3 +1,3 @@
1
1
  module DownloadTV
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/download_tv.rb CHANGED
@@ -4,6 +4,7 @@ require "date"
4
4
  require "io/console"
5
5
 
6
6
  require "download_tv/version"
7
+ require "download_tv/configuration"
7
8
  require "download_tv/downloader"
8
9
  require "download_tv/torrent"
9
10
  require "download_tv/myepisodes"
@@ -7,36 +7,56 @@ describe DownloadTV::Downloader do
7
7
  end
8
8
 
9
9
  describe "when creating the object" do
10
- it "should receive an integer" do
11
- ->{ DownloadTV::Downloader.new("foo") }.must_raise NoMethodError
10
+ it "should receive three parameters" do
11
+ ->{ DownloadTV::Downloader.new(0) }.must_raise ArgumentError
12
+ ->{ DownloadTV::Downloader.new(0, true) }.must_raise ArgumentError
13
+ end
14
+
15
+ it "can receive an optional configuration hash" do
16
+ DownloadTV::Downloader.new(0, true, true, {:hi => 1}).config.must_equal ({:hi => 1})
17
+ end
18
+
19
+ it "should receive an integer for the offset" do
20
+ ->{ DownloadTV::Downloader.new("foo", true, true, {1=>1}) }.must_raise NoMethodError
12
21
  end
13
22
 
14
23
  it "should store the first argument as @offset" do
15
- DownloadTV::Downloader.new(3).offset.must_equal 3
24
+ DownloadTV::Downloader.new(3, true, true, {1=>1}).offset.must_equal 3
25
+ end
26
+
27
+ it "should store the second argument as @auto" do
28
+ DownloadTV::Downloader.new(3, true, true, {1=>1}).auto.must_equal true
29
+ DownloadTV::Downloader.new(3, false, true, {1=>1}).auto.must_equal false
30
+ end
31
+
32
+ it "should store the second argument as @subs" do
33
+ DownloadTV::Downloader.new(3, true, true, {1=>1}).subs.must_equal true
34
+ DownloadTV::Downloader.new(3, true, false, {1=>1}).subs.must_equal false
16
35
  end
17
36
 
18
37
  end
19
38
 
20
39
  describe "the fix_names function" do
40
+ config = {:ignored => ["Ignored"]}
41
+ dl = DownloadTV::Downloader.new(0, true, true, config)
42
+
21
43
  it "should remove apostrophes and parens" do
22
44
  shows = ["Mr. Foo S01E02", "Bar (UK) S00E22", "Let's S05E03"]
23
45
  result = ["Mr. Foo S01E02", "Bar S00E22", "Lets S05E03"]
24
- DownloadTV::Downloader.new(0).fix_names(shows).must_equal result
46
+ dl.fix_names(shows).must_equal result
25
47
  end
26
48
 
27
49
  it "should remove ignored shows" do
28
- DownloadTV::CONFIG[:ignored] = ["Ignored"]
50
+
29
51
  shows = ["Mr. Foo S01E02", "Bar (UK) S00E22", "Ignored S20E22", "Let's S05E03"]
30
52
  result = ["Mr. Foo S01E02", "Bar S00E22", "Lets S05E03"]
31
- DownloadTV::Downloader.new(0).fix_names(shows).must_equal result
53
+ dl.fix_names(shows).must_equal result
32
54
  end
33
55
  end
34
56
 
35
57
 
36
58
  describe "the date file" do
37
- dl = DownloadTV::Downloader.new(0)
38
-
39
-
59
+ dl = DownloadTV::Downloader.new(0, true, true, {1=>1})
40
60
 
41
61
  it "should be created if it doesn't exist" do
42
62
  dl.check_date
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  describe DownloadTV::LinkGrabber do
4
4
 
5
- grabbers = DownloadTV::CONFIG[:grabbers].clone
5
+ grabbers = ["Eztv", "ThePirateBay", "TorrentAPI"]
6
6
  instances = grabbers.map { |g| (DownloadTV.const_get g).new }
7
7
 
8
8
  instances.each do |grabber|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: download_tv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - guille
@@ -124,7 +124,7 @@ files:
124
124
  - bin/tv
125
125
  - download_tv.gemspec
126
126
  - lib/download_tv.rb
127
- - lib/download_tv/config_example.rb
127
+ - lib/download_tv/configuration.rb
128
128
  - lib/download_tv/downloader.rb
129
129
  - lib/download_tv/grabbers/addic7ed.rb
130
130
  - lib/download_tv/grabbers/eztv.rb
@@ -1,12 +0,0 @@
1
- module DownloadTV
2
- CONFIG = {
3
- myepisodes_user: "", # MyEpisodes login username
4
- auto: true, # Try to automatically select the torrents
5
- subs: true, # Download subtitles (not implemented yet)
6
- cookie_path: "cookie", # Leave blank to prevent the app from storing cookies
7
- ignored: [], # list of strings that match show names as written in myepisodes
8
- tpb_proxy: "https://pirateproxy.cc", # URL of the TPB proxy to use
9
- grabbers: ["Eztv", "ThePirateBay", "TorrentAPI"], # names of the classes in /grabbers
10
- }
11
-
12
- end