mirror of
https://github.com/JohnDoee/deluge-streaming/
synced 2026-07-01 07:31:17 -07:00
a bit of cleanup
This commit is contained in:
@@ -39,18 +39,21 @@
|
||||
|
||||
from deluge.plugins.init import PluginInitBase
|
||||
|
||||
|
||||
class CorePlugin(PluginInitBase):
|
||||
def __init__(self, plugin_name):
|
||||
from core import Core as _plugin_cls
|
||||
self._plugin_cls = _plugin_cls
|
||||
super(CorePlugin, self).__init__(plugin_name)
|
||||
|
||||
|
||||
class GtkUIPlugin(PluginInitBase):
|
||||
def __init__(self, plugin_name):
|
||||
from gtkui import GtkUI as _plugin_cls
|
||||
self._plugin_cls = _plugin_cls
|
||||
super(GtkUIPlugin, self).__init__(plugin_name)
|
||||
|
||||
|
||||
class WebUIPlugin(PluginInitBase):
|
||||
def __init__(self, plugin_name):
|
||||
from webui import WebUI as _plugin_cls
|
||||
|
||||
@@ -50,12 +50,12 @@ from copy import copy
|
||||
|
||||
from deluge import component, configmanager
|
||||
from deluge._libtorrent import lt
|
||||
from deluge.core.rpcserver import export, check_ssl_keys
|
||||
from deluge.core.rpcserver import export
|
||||
from deluge.plugins.pluginbase import CorePluginBase
|
||||
|
||||
from twisted.internet import reactor, defer, task
|
||||
from twisted.internet import reactor, defer
|
||||
from twisted.python import randbytes
|
||||
from twisted.web import server, resource, static, http, client
|
||||
from twisted.web import server, resource, static, client
|
||||
|
||||
from .filelike import FilelikeObjectResource
|
||||
from .resource import Resource
|
||||
@@ -80,11 +80,13 @@ DEFAULT_PREFS = {
|
||||
|
||||
PRIORITY_INCREASE = 5
|
||||
|
||||
|
||||
def sleep(seconds):
|
||||
d = defer.Deferred()
|
||||
reactor.callLater(seconds, d.callback, seconds)
|
||||
return d
|
||||
|
||||
|
||||
class ServerContextFactory(object):
|
||||
def __init__(self, cert_file, key_file):
|
||||
self._cert_file = cert_file
|
||||
@@ -103,6 +105,7 @@ class ServerContextFactory(object):
|
||||
ctx.use_privatekey_file(self._key_file)
|
||||
return ctx
|
||||
|
||||
|
||||
class FileServeResource(resource.Resource):
|
||||
isLeaf = True
|
||||
|
||||
@@ -131,6 +134,7 @@ class FileServeResource(resource.Resource):
|
||||
tfr = f.open()
|
||||
return FilelikeObjectResource(tfr, f.size).render_GET(request)
|
||||
|
||||
|
||||
class StreamResource(Resource):
|
||||
isLeaf = True
|
||||
|
||||
@@ -180,12 +184,15 @@ class StreamResource(Resource):
|
||||
result = yield self.client.stream_torrent(infohash=infohash, filepath_or_index=path, wait_for_end_pieces=wait_for_end_pieces)
|
||||
defer.returnValue(json.dumps(result))
|
||||
|
||||
|
||||
class UnknownTorrentException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnknownFileException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TorrentFileReader(object):
|
||||
def __init__(self, torrent_file):
|
||||
self.torrent_file = torrent_file
|
||||
@@ -222,6 +229,7 @@ class TorrentFileReader(object):
|
||||
def seek(self, offset, whence=os.SEEK_SET):
|
||||
self.position = offset
|
||||
|
||||
|
||||
class TorrentFile(object): # can be read from, knows about itself
|
||||
def __init__(self, torrent, first_piece, last_piece, piece_size, offset, path, full_path, size, index):
|
||||
self.torrent = torrent
|
||||
@@ -244,7 +252,6 @@ class TorrentFile(object): # can be read from, knows about itself
|
||||
|
||||
self.alerts = component.get("AlertManager")
|
||||
|
||||
|
||||
def open(self):
|
||||
"""
|
||||
Returns a filelike object
|
||||
@@ -335,6 +342,7 @@ class TorrentFile(object): # can be read from, knows about itself
|
||||
def shutdown(self):
|
||||
self.do_shutdown = True
|
||||
|
||||
|
||||
class Torrent(object):
|
||||
def __init__(self, torrent_handler, infohash):
|
||||
self.infohash = infohash
|
||||
@@ -349,7 +357,6 @@ class Torrent(object):
|
||||
self.do_shutdown = False
|
||||
self.torrent_released = True # set to True if all the files are set to download
|
||||
|
||||
|
||||
self.populate_files()
|
||||
self.file_priorities = [0] * len(self.torrent_files)
|
||||
|
||||
@@ -491,7 +498,6 @@ class Torrent(object):
|
||||
for head_piece in heads:
|
||||
priority_increased = 0
|
||||
for piece, status in enumerate(self.torrent.status.pieces[head_piece:f.last_piece+1], head_piece):
|
||||
#logger.debug('Checking status for %s/%s/%s/%s' % (head_piece, piece, status, self.torrent.handle.piece_priority(piece)))
|
||||
if status or piece in currently_downloading:
|
||||
continue
|
||||
|
||||
@@ -547,6 +553,7 @@ class Torrent(object):
|
||||
|
||||
reactor.callLater(1, self.update_piece_priority)
|
||||
|
||||
|
||||
class TorrentHandler(object):
|
||||
def __init__(self, config):
|
||||
self.torrents = {}
|
||||
@@ -584,6 +591,7 @@ class TorrentHandler(object):
|
||||
for torrent in self.torrents.values():
|
||||
torrent.shutdown()
|
||||
|
||||
|
||||
class Core(CorePluginBase):
|
||||
listening = None
|
||||
base_url = None
|
||||
|
||||
@@ -30,8 +30,7 @@ class SingleRangeStaticProducer(static.SingleRangeStaticProducer):
|
||||
if not self.request:
|
||||
return
|
||||
|
||||
data = yield defer.maybeDeferred(self.fileObject.read,
|
||||
min(self.bufferSize, self.size - self.bytesWritten))
|
||||
data = yield defer.maybeDeferred(self.fileObject.read, min(self.bufferSize, self.size - self.bytesWritten))
|
||||
|
||||
if not self.request:
|
||||
return
|
||||
@@ -62,9 +61,7 @@ class MultipleRangeStaticProducer(static.MultipleRangeStaticProducer):
|
||||
dataLength += len(self.partBoundary)
|
||||
data.append(self.partBoundary)
|
||||
self.partBoundary = None
|
||||
p = yield defer.maybeDeferred(self.fileObject.read,
|
||||
min(self.bufferSize - dataLength,
|
||||
self._partSize - self._partBytesWritten))
|
||||
p = yield defer.maybeDeferred(self.fileObject.read, min(self.bufferSize - dataLength, self._partSize - self._partBytesWritten))
|
||||
self._partBytesWritten += len(p)
|
||||
dataLength += len(p)
|
||||
data.append(p)
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
|
||||
import json
|
||||
import gtk
|
||||
import os
|
||||
import subprocess
|
||||
@@ -50,8 +49,7 @@ from deluge.plugins.pluginbase import GtkPluginBase
|
||||
import deluge.component as component
|
||||
import deluge.common
|
||||
|
||||
from twisted.internet import reactor, defer, threads
|
||||
from twisted.web import server, resource
|
||||
from twisted.internet import defer, threads
|
||||
|
||||
from common import get_resource
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from twisted.web.resource import Resource as TwistedResource, _computeAllowedMethods
|
||||
from twisted.web import server, error
|
||||
from twisted.web import server
|
||||
from twisted.internet import defer
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ class Resource(TwistedResource):
|
||||
if self.username == username and self.password == password:
|
||||
authenticated = True
|
||||
|
||||
|
||||
if not authenticated:
|
||||
print auth_header
|
||||
print self.username, self.password
|
||||
|
||||
@@ -44,6 +44,6 @@ from deluge.plugins.pluginbase import WebPluginBase
|
||||
|
||||
from common import get_resource
|
||||
|
||||
class WebUI(WebPluginBase):
|
||||
|
||||
class WebUI(WebPluginBase):
|
||||
scripts = [get_resource("streaming.js")]
|
||||
Reference in New Issue
Block a user