initial move-only prototype
This commit is contained in:
commit
55db207c11
|
@ -0,0 +1,4 @@
|
|||
.DS_Store
|
||||
__pycache__
|
||||
/*.egg-info/
|
||||
/virtualenv/
|
|
@ -0,0 +1,124 @@
|
|||
import os
|
||||
import cherrypy
|
||||
import logging
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from deluge_client import DelugeRPCClient
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
|
||||
|
||||
|
||||
class MediaWeb(object):
|
||||
def __init__(self, rpc, templater, uioptions):
|
||||
self.tpl = templater
|
||||
self.rpc = rpc
|
||||
self.uioptions = uioptions
|
||||
|
||||
def render(self, template, **kwargs):
|
||||
"""
|
||||
Render a template
|
||||
"""
|
||||
return self.tpl.get_template(template).render(**kwargs, options=self.uioptions, **self.get_default_vars())
|
||||
|
||||
def get_default_vars(self):
|
||||
return {}
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
torrents = self.rpc.core.get_torrents_status({"label": "sickrage"}, ['name', 'label', 'save_path', 'is_seed', 'is_finished', 'progress'])
|
||||
return self.render("index.html", torrents=torrents)
|
||||
|
||||
@cherrypy.expose
|
||||
def move(self, thash, dest=None, otherdest=None):
|
||||
torrent = self.rpc.core.get_torrent_status(thash, []) # TODO reduce to needed fields
|
||||
|
||||
if cherrypy.request.method == "POST" and (dest or otherdest):
|
||||
target = otherdest or dest
|
||||
self.rpc.core.move_storage([thash], target)
|
||||
raise cherrypy.HTTPRedirect("/")
|
||||
|
||||
return self.render("moveform.html", torrent=torrent)
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
import signal
|
||||
|
||||
parser = argparse.ArgumentParser(description="mediaweb server")
|
||||
|
||||
parser.add_argument('-p', '--port', help="tcp port to listen on",
|
||||
default=int(os.environ.get("MEDIAWEB_PORT", 8080)), type=int)
|
||||
parser.add_argument('-i', '--download-dirs', help="download directories", nargs="+",
|
||||
default=os.environ.get("MEDIAWEB_DLDIR"))
|
||||
parser.add_argument('-o', '--library', default=os.environ.get("STORAGE_URL"), help="media library path")
|
||||
parser.add_argument('--debug', action="store_true", help="enable development options")
|
||||
parser.add_argument('-s', '--server', help="deluge uris", action="append", required=True)
|
||||
parser.add_argument('--ui-movedests', help="move destination options in the UI", nargs="+", required=True)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
uioptions = {
|
||||
"movedests": args.ui_movedests,
|
||||
}
|
||||
|
||||
# TODO smarter argparser that understands env vars
|
||||
if not args.library:
|
||||
parser.error("--download-dirs or MEDIAWEB_DLDIR is required")
|
||||
|
||||
logging.basicConfig(level=logging.INFO if args.debug else logging.WARNING,
|
||||
format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s")
|
||||
|
||||
tpl_dir = os.path.join(APPROOT, "templates") if not args.debug else "templates"
|
||||
tpl = Environment(loader=FileSystemLoader(tpl_dir),
|
||||
autoescape=select_autoescape(['html', 'xml']))
|
||||
# self.tpl.filters.update(basename=os.path.basename,
|
||||
# ceil=math.ceil
|
||||
|
||||
def validate_password(realm, user, passw):
|
||||
return user == passw # lol
|
||||
|
||||
# assume 1 deluge server for now
|
||||
uri = urlparse(args.server[0])
|
||||
assert uri.scheme == "deluge"
|
||||
rpc = DelugeRPCClient(uri.hostname, uri.port if uri.port else 58846, uri.username, uri.password, decode_utf8=True)
|
||||
|
||||
web = MediaWeb(rpc, tpl, uioptions)
|
||||
cherrypy.tree.mount(web, '/', {'/': {'tools.auth_basic.on': True,
|
||||
'tools.auth_basic.realm': 'mediaweb',
|
||||
'tools.auth_basic.checkpassword': validate_password, }})
|
||||
|
||||
# General config options
|
||||
cherrypy.config.update({
|
||||
'tools.sessions.on': False,
|
||||
'request.show_tracebacks': True,
|
||||
'server.show_tracebacks': True,
|
||||
'server.socket_port': args.port,
|
||||
'server.thread_pool': 1 if args.debug else 5,
|
||||
'server.socket_host': '0.0.0.0',
|
||||
'log.screen': False,
|
||||
'engine.autoreload.on': args.debug
|
||||
})
|
||||
|
||||
# Setup signal handling and run it.
|
||||
def signal_handler(signum, stack):
|
||||
logging.critical('Got sig {}, exiting...'.format(signum))
|
||||
cherrypy.engine.exit()
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
try:
|
||||
cherrypy.engine.start()
|
||||
cherrypy.engine.block()
|
||||
finally:
|
||||
logging.info("API has shut down")
|
||||
cherrypy.engine.exit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
# https://github.com/deluge-torrent/deluge/blob/1.3-stable/deluge/ui/console/commands/info.py#L46
|
||||
# https://deluge.readthedocs.io/en/latest/reference/api.html?highlight=rpc
|
|
@ -0,0 +1,13 @@
|
|||
backports.functools-lru-cache==1.5
|
||||
cheroot==6.5.5
|
||||
CherryPy==18.1.2
|
||||
deluge-client==1.7.1
|
||||
jaraco.functools==2.0
|
||||
Jinja2==2.10.1
|
||||
MarkupSafe==1.1.1
|
||||
more-itertools==7.2.0
|
||||
portend==2.5
|
||||
pytz==2019.2
|
||||
six==1.12.0
|
||||
tempora==1.14.1
|
||||
zc.lockfile==2.0
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
__version__ = "0.0.0"
|
||||
|
||||
|
||||
setup(name='mediaweb',
|
||||
version=__version__,
|
||||
description='web based tool for sorting your media in an opinionated way',
|
||||
url='https://git.davepedu.com/dave/mediasort',
|
||||
author='dpedu',
|
||||
author_email='dave@davepedu.com',
|
||||
packages=['mediaweb'],
|
||||
install_requires=[], # TODO
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"mswebd = mediaweb:main"
|
||||
]
|
||||
},
|
||||
include_package_data=True,
|
||||
package_data={'mediaweb': ['../templates/*.html',
|
||||
'../assets/*']},
|
||||
zip_safe=False)
|
|
@ -0,0 +1,52 @@
|
|||
{% extends "page.html" %}
|
||||
{% block body %}
|
||||
|
||||
<div class="torrents">
|
||||
<h2>Completed</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>hash</th>
|
||||
<th>name</th>
|
||||
<th>path</th>
|
||||
<th>dest</th>
|
||||
<th>status</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
{% for torid, tor in torrents.items() %}{% if tor.is_finished %}
|
||||
<tr>
|
||||
<td>{{ torid[0:6] }}</td>
|
||||
<td>{{ tor.name }}</td>
|
||||
<td>{{ tor.save_path }}</td>
|
||||
<td>x</td>
|
||||
<td>{{ "complete" if tor.is_finished else "pending" }}</td>
|
||||
<td>
|
||||
<a href="/move?thash={{ torid }}"><button>Move</button></a>
|
||||
<a href="/sort?thash={{ torid }}"><button>Sort</button></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}{% endfor %}
|
||||
</table>
|
||||
<h2>Pending</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>hash</th>
|
||||
<th>name</th>
|
||||
<th>path</th>
|
||||
<th>percent</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
{% for torid, tor in torrents.items() %}{% if not tor.is_finished %}
|
||||
<tr>
|
||||
<td>{{ torid[0:6] }}</td>
|
||||
<td>{{ tor.name }}</td>
|
||||
<td>{{ tor.save_path }}</td>
|
||||
<td>{{ tor.progress }}%</td>
|
||||
<td>
|
||||
<a href="/foo"><button>Resume</button></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,29 @@
|
|||
{% extends "page.html" %}
|
||||
{% block body %}
|
||||
<div class="moveform">
|
||||
<h2>Move {{ torrent.name }} </h2>
|
||||
<p>{{ torrent.hash }}</p>
|
||||
|
||||
<fieldset>
|
||||
<legend>current path</legend>
|
||||
{{ torrent.save_path }}
|
||||
</fieldset>
|
||||
|
||||
<br/>
|
||||
|
||||
<form action="/move" method="post">
|
||||
<input type="hidden" name="thash" value="{{ torrent.hash }}">
|
||||
<fieldset>
|
||||
<legend>new path</legend>
|
||||
<select name="dest">
|
||||
<option value="" selected="selected">-</option>
|
||||
{% for dest in options.movedests %}
|
||||
<option value="{{ dest }}">{{ dest }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<label for="other">or: <input type="text" name="otherdest" /></label>
|
||||
<input type="submit" value="go">
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Media Sort</title>
|
||||
<style>
|
||||
html, body {
|
||||
font-family: arial, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
#page {
|
||||
margin: 0px auto;
|
||||
width: 1000px;
|
||||
}
|
||||
td {
|
||||
padding: 3px 5px;
|
||||
}
|
||||
td {
|
||||
border-bottom: 1px solid #666;
|
||||
/*display: block;*/
|
||||
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
{% block body %}{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue