Compare commits
3 Commits
279f0cbbf0
...
78bb0b0007
Author | SHA1 | Date |
---|---|---|
Derek | 78bb0b0007 | |
Derek | 6262e7c3aa | |
Derek | b2d83131be |
|
@ -35,6 +35,9 @@ class Resolution:
|
||||||
else:
|
else:
|
||||||
raise ValueError("Did not recongnize resolution name. See Resolution.names")
|
raise ValueError("Did not recongnize resolution name. See Resolution.names")
|
||||||
|
|
||||||
|
def getNormalizedName(self):
|
||||||
|
return self.family[0]
|
||||||
|
|
||||||
# Rich comparison support
|
# Rich comparison support
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
if not isinstance(other, Resolution):
|
if not isinstance(other, Resolution):
|
||||||
|
@ -108,7 +111,8 @@ class Torrent:
|
||||||
@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.")
|
||||||
def main(config_path='config.json', seen_path='seen.txt'):
|
@click.option('--no-dedup', 'no_seen', type=click.BOOL, is_flag=True, default=False, help="Don't save seen torrents to the seen file.")
|
||||||
|
def main(config_path='config.json', seen_path='seen.txt', no_seen=False):
|
||||||
# Get our config
|
# Get our config
|
||||||
with open(config_path, 'r') as config_file:
|
with open(config_path, 'r') as config_file:
|
||||||
config_json = ''.join(config_file.readlines())
|
config_json = ''.join(config_file.readlines())
|
||||||
|
@ -166,15 +170,16 @@ def main(config_path='config.json', seen_path='seen.txt'):
|
||||||
torrents = [torrent for torrent in torrents if torrent.quality >= Resolution(item_config['min-quality'])]
|
torrents = [torrent for torrent in torrents if torrent.quality >= Resolution(item_config['min-quality'])]
|
||||||
|
|
||||||
if len(torrents) > 0:
|
if len(torrents) > 0:
|
||||||
best_entry = sorted(torrents, key=lambda t: t.quality)[0]
|
best_entry = sorted(torrents, key=lambda t: t.quality, reverse=True)[0]
|
||||||
# Output the magnet / torrent link
|
# Output the magnet / torrent link
|
||||||
printe("Choosing {torrent} as best choice for {show}".format(torrent=torrent.id, show=show.name))
|
printe("Choosing {torrent} as best choice for {show} (quality: {res})".format(torrent=best_entry.id, show=show.name, res=best_entry.quality.getNormalizedName()))
|
||||||
# TODO: transmission-cli subprocess call here?
|
# TODO: transmission-cli subprocess call here?
|
||||||
print(best_entry.link)
|
print(best_entry.link)
|
||||||
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))
|
||||||
|
|
||||||
# Save our records to a file for later use
|
# Save our records to a file for later use
|
||||||
|
if not 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))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue