Compare commits

..

3 Commits

Author SHA1 Message Date
Derek 78bb0b0007
Add dry run capibilities
Named no-dedup because dry-run is planned to do something else
over on feature/rpc
2018-06-12 10:00:23 -07:00
Derek 6262e7c3aa
Print out the resolution name
Help make sure something like b2d8313 doesnt happen again
2018-06-12 09:59:33 -07:00
Derek b2d83131be
Fix quality detection
I WAS SORTING THE WRONG WAY YIKE
2018-06-12 09:54:58 -07:00
1 changed files with 10 additions and 5 deletions

View File

@ -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))