Compare commits
No commits in common. "782055e4ef9901624d2d5305480cccbf6079bc43" and "81fb8972e14c2eb5782b6aee50e30c90e1c42338" have entirely different histories.
782055e4ef
...
81fb8972e1
|
@ -1,6 +1,7 @@
|
||||||
#!/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
|
||||||
|
@ -8,14 +9,11 @@ import hashlib
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import transmissionrpc
|
import transmissionrpc
|
||||||
import requests
|
from operator import itemgetter
|
||||||
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 = [
|
||||||
|
@ -30,7 +28,6 @@ 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:
|
||||||
|
@ -48,21 +45,16 @@ 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)
|
||||||
|
|
||||||
|
@ -92,7 +84,6 @@ 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
|
||||||
|
@ -118,6 +109,7 @@ 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.")
|
||||||
|
@ -186,8 +178,6 @@ 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)
|
||||||
|
@ -213,13 +203,7 @@ 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))
|
||||||
|
|
||||||
|
@ -228,7 +212,6 @@ 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