Compare commits
3 Commits
81fb8972e1
...
782055e4ef
Author | SHA1 | Date |
---|---|---|
Derek | 782055e4ef | |
Derek | de8b52b260 | |
Derek | cdc50adabf |
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
import subprocess
|
|
||||||
import click
|
import click
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
@ -9,11 +8,14 @@ import hashlib
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import transmissionrpc
|
import transmissionrpc
|
||||||
from operator import itemgetter
|
import requests
|
||||||
|
import base64
|
||||||
|
|
||||||
|
|
||||||
def printe(*args, **kwargs):
|
def printe(*args, **kwargs):
|
||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Resolution:
|
class Resolution:
|
||||||
# In decending order of quality, since indexes are used to tell whats "better"
|
# In decending order of quality, since indexes are used to tell whats "better"
|
||||||
names = [
|
names = [
|
||||||
|
@ -28,6 +30,7 @@ class Resolution:
|
||||||
('240p', 'QVGA'),
|
('240p', 'QVGA'),
|
||||||
('Unknown', 'None', None)
|
('Unknown', 'None', None)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, _name):
|
def __init__(self, _name):
|
||||||
self.name = _name
|
self.name = _name
|
||||||
for family in self.names:
|
for family in self.names:
|
||||||
|
@ -45,16 +48,21 @@ class Resolution:
|
||||||
if not isinstance(other, Resolution):
|
if not isinstance(other, Resolution):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
return self.names.index(self.family) > other.names.index(other.family)
|
return self.names.index(self.family) > other.names.index(other.family)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Resolution):
|
if not isinstance(other, Resolution):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
return self.names.index(self.family) == other.names.index(other.family)
|
return self.names.index(self.family) == other.names.index(other.family)
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
|
|
||||||
def __gt__(self, other):
|
def __gt__(self, other):
|
||||||
return not self.__lt__(other)
|
return not self.__lt__(other)
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
return self.__lt__(other) or self.__eq__(other)
|
return self.__lt__(other) or self.__eq__(other)
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
return self.__gt__(other) or self.__eq__(other)
|
return self.__gt__(other) or self.__eq__(other)
|
||||||
|
|
||||||
|
@ -84,6 +92,7 @@ class Show:
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.key == other.key
|
return self.key == other.key
|
||||||
|
|
||||||
|
|
||||||
class Torrent:
|
class Torrent:
|
||||||
def __init__(self, name, link, id=None, episode=None, quality=None, encoding=None):
|
def __init__(self, name, link, id=None, episode=None, quality=None, encoding=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -109,7 +118,6 @@ class Torrent:
|
||||||
return self.id == other.id
|
return self.id == other.id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--config', 'config_path', type=click.Path(readable=True, dir_okay=False), default='config.json', help="Config file in JSON format.", )
|
@click.option('--config', 'config_path', type=click.Path(readable=True, dir_okay=False), default='config.json', help="Config file in JSON format.", )
|
||||||
@click.option('--seen-file', 'seen_path', type=click.Path(writable=True, dir_okay=False), default='seen.txt', help="File to store seen torrents in. Pruning is acceptable if pruned torrent id's will not appear in the RSS feeds.")
|
@click.option('--seen-file', 'seen_path', type=click.Path(writable=True, dir_okay=False), default='seen.txt', help="File to store seen torrents in. Pruning is acceptable if pruned torrent id's will not appear in the RSS feeds.")
|
||||||
|
@ -178,6 +186,8 @@ def main(config_path='config.json', seen_path='seen.txt', dry_run=False, no_seen
|
||||||
timeout=config['rpc'].get('timeout')
|
timeout=config['rpc'].get('timeout')
|
||||||
)
|
)
|
||||||
default_download_dir = rpc.get_session().download_dir
|
default_download_dir = rpc.get_session().download_dir
|
||||||
|
else:
|
||||||
|
rpc = None
|
||||||
# Choose the best item
|
# Choose the best item
|
||||||
for show, torrents in filtered.items():
|
for show, torrents in filtered.items():
|
||||||
item_config = show.getConfig(config)
|
item_config = show.getConfig(config)
|
||||||
|
@ -203,7 +213,13 @@ def main(config_path='config.json', seen_path='seen.txt', dry_run=False, no_seen
|
||||||
destination = os.path.join(default_download_dir, destination)
|
destination = os.path.join(default_download_dir, destination)
|
||||||
if not os.path.exists(destination):
|
if not os.path.exists(destination):
|
||||||
os.makedirs(destination)
|
os.makedirs(destination)
|
||||||
t = rpc.add_torrent(best_entry.link, download_dir=destination or default_download_dir)
|
|
||||||
|
if best_entry.link.startswith('http'):
|
||||||
|
r = requests.get(best_entry.link)
|
||||||
|
r.raise_for_status()
|
||||||
|
rpc.add_torrent(base64.b64encode(r.content).decode('utf-8'), download_dir=destination or default_download_dir)
|
||||||
|
else:
|
||||||
|
rpc.add_torrent(best_entry.link, download_dir=destination or default_download_dir)
|
||||||
else:
|
else:
|
||||||
printe("No torrents for {show} pass quality restrictions".format(show=show.name))
|
printe("No torrents for {show} pass quality restrictions".format(show=show.name))
|
||||||
|
|
||||||
|
@ -212,6 +228,7 @@ def main(config_path='config.json', seen_path='seen.txt', dry_run=False, no_seen
|
||||||
with open(seen_path, 'w') as seen_file:
|
with open(seen_path, 'w') as seen_file:
|
||||||
seen_file.write('\n'.join(seen))
|
seen_file.write('\n'.join(seen))
|
||||||
|
|
||||||
|
|
||||||
# Usual python stuff
|
# Usual python stuff
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue