Compare commits

...

6 Commits

Author SHA1 Message Date
Derek c0bf189444
Fix spelling mistake 2018-06-12 10:57:17 -07:00
Derek 3af2633762
Import os so 8843604 works
oops
2018-06-12 10:52:50 -07:00
Derek 8843604cea
Even BETTER destination handling
Create dir (recursively) if it doesnt exist
2018-06-12 10:33:02 -07:00
Derek 6d46811732
Better destination handling
Aparently transmissionrpc also doesnt like
having `download_dir = None`. It should actually work now.
2018-06-12 10:25:25 -07:00
Derek 4c81b4faae
Implement rpc via transmissionrpc 2018-06-12 10:06:50 -07:00
Derek 8cd76c368f
Add new dependency: transmissionrpc 2018-06-12 10:05:06 -07:00
3 changed files with 50 additions and 4 deletions

View File

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

18
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "18122d84aba43b06f2a0f80eb6421c8fdbfa21ef685c1eee5d19c7892242a5fd"
"sha256": "56df164d5b8c07561949eff5536f0465cb02f949b3dd19fa0ba699e562502bc0"
},
"pipfile-spec": 6,
"requires": {
@ -32,6 +32,22 @@
],
"index": "pypi",
"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": {}

View File

@ -7,6 +7,8 @@ import re
import json
import hashlib
import sys
import os
import transmissionrpc
from operator import itemgetter
def printe(*args, **kwargs):
@ -24,7 +26,7 @@ class Resolution:
('480p', 'SD', 'VGA'),
('360p', 'nHD'),
('240p', 'QVGA'),
('Unkown', 'None', None)
('Unknown', 'None', None)
]
def __init__(self, _name):
self.name = _name
@ -111,8 +113,9 @@ class Torrent:
@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('--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.")
def main(config_path='config.json', seen_path='seen.txt', no_seen=False):
def main(config_path='config.json', seen_path='seen.txt', dry_run=False, no_seen=False):
# Get our config
with open(config_path, 'r') as config_file:
config_json = ''.join(config_file.readlines())
@ -160,6 +163,21 @@ def main(config_path='config.json', seen_path='seen.txt', no_seen=False):
# Record that we have seen it
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
for show, torrents in filtered.items():
item_config = show.getConfig(config)
@ -175,11 +193,22 @@ def main(config_path='config.json', seen_path='seen.txt', no_seen=False):
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?
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:
printe("No torrents for {show} pass quality restrictions".format(show=show.name))
# Save our records to a file for later use
if not no_seen:
if not (dry_run or no_seen):
with open(seen_path, 'w') as seen_file:
seen_file.write('\n'.join(seen))