-
Notifications
You must be signed in to change notification settings - Fork 0
/
gettorrent.rb
executable file
·79 lines (64 loc) · 2.42 KB
/
gettorrent.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env ruby
require 'rubygems'
require 'yaml'
require 'optparse'
require_relative 'lib/EzTVClass.rb'
#options parsing, valid options atm are -t and -f.
# -t is used to skip the download feature and just create the text files with the magnets in it so that you don't have to download everything
options = {}
optparse = OptionParser.new do |opts|
options[:skipDownload] = false
opts.on('-t') do
options[:skipDownload] = true
end
options[:force] = false
opts.on('-f') do
options[:force] = true
end
end
optparse.parse!
# loads "shows.yaml" in the current running folder.
# TODO: Update to make this dynamic so you can pass the file in as an argument
shows = YAML::load(File.open("shows.yaml"))
#Main Block
shows.each do |id,name|
eztv = EzTVClass.new(name,id)
#Test if the status is "Airing", no point downloading/parsing stuff if there isn't active uploads. This can be overriden by the -f option.
if eztv.getShowStatus == "Airing" || options[:force]
puts "Processing show: #{eztv.show}(#{eztv.id}), Status: #{eztv.getShowStatus}"
folderName = "shows"
fileName = "#{folderName}/#{eztv.show}.txt"
contents = Array.new
unless File.exists?(folderName)
Dir.mkdir(folderName)
end
#Open the text file containing the magnets if it does exist
if File.exists?(fileName)
file = File.open(fileName, 'r')
file.each_line do |line|
contents.push line.gsub("\n",'')
end
end
newMagnets = Array.new
#Append new magnets to the file if they exist
File.open(fileName, 'a') do |f|
magnets = eztv.getMagnetLinks()
magnets.each do |magnet|
if ! contents.include?(magnet)
newMagnets.push magnet
f.puts magnet
end
end
end
#Parse the magnets to get unique episodes (That way we don't download 6 copies of the same show.)
#NOTE: Because of this, you can't be selective of what version of the show is downloaded. It just downloads which ever it finds first.
uniqueEpisodes = EzTVClass.getUniqueEpisodes(newMagnets,contents)
uniqueEpisodes.each do |magnet|
if options[:skipDownload] then
puts match
else
EzTVClass.downloadShow(magnet)
end
end
end
end