Compare commits

..

No commits in common. "c0bf189444b9f08b697f80f7c6c4f2b54521ea6f" and "78bb0b00079f6337a86e8949997ef94ec60af09c" have entirely different histories.

3 changed files with 4 additions and 50 deletions

View File

@ -6,7 +6,6 @@ url = "https://pypi.org/simple"
[packages] [packages]
click = "*" click = "*"
feedparser = "*" feedparser = "*"
transmissionrpc = "*"
[requires] [requires]
python_version = "3.6" python_version = "3.6"

18
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "56df164d5b8c07561949eff5536f0465cb02f949b3dd19fa0ba699e562502bc0" "sha256": "18122d84aba43b06f2a0f80eb6421c8fdbfa21ef685c1eee5d19c7892242a5fd"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -32,22 +32,6 @@
], ],
"index": "pypi", "index": "pypi",
"version": "==5.2.1" "version": "==5.2.1"
},
"six": {
"hashes": [
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
],
"version": "==1.11.0"
},
"transmissionrpc": {
"hashes": [
"sha256:8178e2a61bc4381ce214401e4513dad00d082bc0d55edbb805586e66a2bbd824",
"sha256:ec43b460f9fde2faedbfa6d663ef495b3fd69df855a135eebe8f8a741c0dde60",
"sha256:f55d9eebd71672890f747ff5467bcdfb19ad9a08d3e5afb03f61442750ed2569"
],
"index": "pypi",
"version": "==0.11"
} }
}, },
"develop": {} "develop": {}

View File

@ -7,8 +7,6 @@ import re
import json import json
import hashlib import hashlib
import sys import sys
import os
import transmissionrpc
from operator import itemgetter from operator import itemgetter
def printe(*args, **kwargs): def printe(*args, **kwargs):
@ -26,7 +24,7 @@ class Resolution:
('480p', 'SD', 'VGA'), ('480p', 'SD', 'VGA'),
('360p', 'nHD'), ('360p', 'nHD'),
('240p', 'QVGA'), ('240p', 'QVGA'),
('Unknown', 'None', None) ('Unkown', 'None', None)
] ]
def __init__(self, _name): def __init__(self, _name):
self.name = _name self.name = _name
@ -113,9 +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.")
@click.option('--dry-run', 'dry_run', type=click.BOOL, is_flag=True, default=False, help="Don't act on any torrents found. Implies --no-dedup")
@click.option('--no-dedup', 'no_seen', type=click.BOOL, is_flag=True, default=False, help="Don't save seen torrents to the seen file.") @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', dry_run=False, no_seen=False): 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())
@ -163,21 +160,6 @@ def main(config_path='config.json', seen_path='seen.txt', dry_run=False, no_seen
# Record that we have seen it # Record that we have seen it
seen.append(torrent.id) seen.append(torrent.id)
# Configure a transmissionrpc client if set
if config.get('rpc'):
# Allows for a setting like `"rpc": true` to just use defaults
# HACK: Should just do the config['rpc'].get better
if isinstance(config['rpc'], bool):
config['rpc'] = {}
rpc = transmissionrpc.Client(
address=config['rpc'].get('address', 'localhost'),
port=config['rpc'].get('port', 9091),
user=config['rpc'].get('user'),
password=config['rpc'].get('password'),
http_handler=config['rpc'].get('http_handler'),
timeout=config['rpc'].get('timeout')
)
default_download_dir = rpc.get_session().download_dir
# 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)
@ -193,22 +175,11 @@ def main(config_path='config.json', seen_path='seen.txt', dry_run=False, no_seen
printe("Choosing {torrent} as best choice for {show} (quality: {res})".format(torrent=best_entry.id, show=show.name, res=best_entry.quality.getNormalizedName())) 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)
# Add torrent to transmission directly
if rpc and not dry_run:
destination = item_config.get('destination')
if destination:
destination = destination.format(show=show, torrent=torrent)
destination = os.path.expanduser(destination)
if not destination.startswith('/'):
destination = os.path.join(default_download_dir, destination)
if not os.path.exists(destination):
os.makedirs(destination)
t = 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))
# Save our records to a file for later use # Save our records to a file for later use
if not (dry_run or no_seen): 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))