forked from sccpregmatch/scc-autodl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
executable file
·87 lines (64 loc) · 2.63 KB
/
base.py
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
80
81
82
83
84
85
86
87
#!/usr/bin/env python
"""
SCC Auto-downloader v1
Copyright (C) 2014 pregmatch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from configuration import configuration
import feedparser
import re
import requests
import pushover
class scc(object):
def __init__(self):
self.tvshows = self.tvlist(configuration.TV_SHOW_FILE)
def parse(self, url):
feed = feedparser.parse(url)
return feed
def tvlist(self, file):
with open(file) as f:
lines = f.read().splitlines()
return lines
def replace(self, title):
a = re.sub('[.-]', ' ', title)
return a
def search(self, title):
for t in self.tvshows:
m = re.search(t, title, re.IGNORECASE)
if m:
return True
def allowdl(self, title):
downloadedfile = open(configuration.TORRENT_ARCHIVE_FILE)
downloadedlist = downloadedfile.readlines()
downloadedfile.close()
for line in downloadedlist:
if title in line:
return False
return True
def writefile(self, file, type, content, title):
write = open(file, type)
write.write("{}\n".format(content))
write.close()
def download(self, url, title):
r = requests.get(url)
if self.allowdl(title):
# Write Torrent to file
self.writefile("{}{}.torrent".format(configuration.TORRENT_DOWNLOAD_DIR, title), "w", r.content, title)
# Write Torrent name to archive
self.writefile(configuration.TORRENT_ARCHIVE_FILE, "ab+", title, title)
# Send Pushover notification
if configuration.PUSHOVER_ENABLED:
self.pushover(title)
def pushover(self, title):
pushover.init(configuration.PUSHOVER_TOKEN)
client = pushover.Client(configuration.PUSHOVER_CLIENT_ID)
client.send_message(title, title=title, priority=1)