diff options
Diffstat (limited to 'pyload')
-rw-r--r-- | pyload/FileManager.py | 2 | ||||
-rw-r--r-- | pyload/api/DownloadApi.py | 6 | ||||
-rw-r--r-- | pyload/api/FileApi.py | 22 | ||||
-rw-r--r-- | pyload/remote/apitypes.py | 2 | ||||
-rw-r--r-- | pyload/remote/apitypes_debug.py | 2 | ||||
-rw-r--r-- | pyload/remote/pyload.thrift | 2 | ||||
-rw-r--r-- | pyload/web/app/scripts/models/Package.js | 20 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/dashboardView.js | 11 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/packageView.js | 5 | ||||
-rw-r--r-- | pyload/web/app/styles/default/dashboard.less | 4 | ||||
-rw-r--r-- | pyload/web/app/templates/default/dashboard/package.html | 8 | ||||
-rw-r--r-- | pyload/web/cnl_app.py | 27 |
12 files changed, 84 insertions, 27 deletions
diff --git a/pyload/FileManager.py b/pyload/FileManager.py index 05f665135..2aba371fe 100644 --- a/pyload/FileManager.py +++ b/pyload/FileManager.py @@ -374,6 +374,7 @@ class FileManager: if pid in self.packages: del self.packages[pid] + @invalidate def updateFile(self, pyfile): """updates file""" self.db.updateFile(pyfile) @@ -381,6 +382,7 @@ class FileManager: # This event is thrown with pyfile or only fid self.evm.dispatchEvent("file:updated", pyfile) + @invalidate def updatePackage(self, pypack): """updates a package""" self.db.updatePackage(pypack) diff --git a/pyload/api/DownloadApi.py b/pyload/api/DownloadApi.py index d855dd882..a0b7c9f96 100644 --- a/pyload/api/DownloadApi.py +++ b/pyload/api/DownloadApi.py @@ -37,12 +37,12 @@ class DownloadApi(ApiComponent): @RequirePerm(Permission.Add) - def addPackage(self, name, links, password=""): + def addPackage(self, name, links, password="", paused=False): """Convenient method to add a package to the top-level and for adding links. :return: package id """ - return self.addPackageChild(name, links, password, -1, False) + return self.addPackageChild(name, links, password, -1, paused) @RequirePerm(Permission.Add) def addPackageP(self, name, links, password, paused): @@ -61,7 +61,7 @@ class DownloadApi(ApiComponent): else: folder = "" - pid = self.createPackage(name, folder, root, password) + pid = self.createPackage(name, folder, root, password, paused=paused) self.addLinks(pid, links) return pid diff --git a/pyload/api/FileApi.py b/pyload/api/FileApi.py index 5bb8e21e7..d8ee26ac2 100644 --- a/pyload/api/FileApi.py +++ b/pyload/api/FileApi.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from pyload.Api import Api, RequirePerm, Permission, DownloadState, PackageDoesNotExist, FileDoesNotExist +from pyload.Api import Api, RequirePerm, Permission, DownloadState, PackageStatus as PS, PackageDoesNotExist, FileDoesNotExist from pyload.utils import uniqify from ApiComponent import ApiComponent @@ -114,8 +114,24 @@ class FileApi(ApiComponent): self.core.files.save() @RequirePerm(Permission.Modify) - def setPackageFolder(self, pid, path): - pass + def setPackagePaused(self, pid, paused): + """ Sets the paused state of a package if possible. + + :param pid: package id + :param paused: desired paused state of the package + :return the new package status + """ + p = self.core.files.getPackage(pid) + if not p: raise PackageDoesNotExist(pid) + + if p.status == PS.Ok and paused: + p.status = PS.Paused + elif p.status == PS.Paused and not paused: + p.status = PS.Ok + + p.sync() + + return p.status @RequirePerm(Permission.Modify) def movePackage(self, pid, root): diff --git a/pyload/remote/apitypes.py b/pyload/remote/apitypes.py index decfbb8b3..07e04d5de 100644 --- a/pyload/remote/apitypes.py +++ b/pyload/remote/apitypes.py @@ -507,7 +507,7 @@ class Iface(object): pass def setInteractionResult(self, iid, result): pass - def setPackageFolder(self, pid, path): + def setPackagePaused(self, pid, paused): pass def setPassword(self, username, old_password, new_password): pass diff --git a/pyload/remote/apitypes_debug.py b/pyload/remote/apitypes_debug.py index 7c19235c2..382c3e178 100644 --- a/pyload/remote/apitypes_debug.py +++ b/pyload/remote/apitypes_debug.py @@ -115,7 +115,7 @@ methods = { 'searchSuggestions': (list, basestring), 'setConfigValue': None, 'setInteractionResult': None, - 'setPackageFolder': bool, + 'setPackagePaused': int, 'setPassword': bool, 'stopAllDownloads': None, 'stopDownloads': None, diff --git a/pyload/remote/pyload.thrift b/pyload/remote/pyload.thrift index da00bc680..6773b7eac 100644 --- a/pyload/remote/pyload.thrift +++ b/pyload/remote/pyload.thrift @@ -455,7 +455,7 @@ service Pyload { // moving package while downloading is not possible, so they will return bool to indicate success void updatePackage(1: PackageInfo pack) throws (1: PackageDoesNotExist e), - bool setPackageFolder(1: PackageID pid, 2: string path) throws (1: PackageDoesNotExist e), + PackageStatus setPackagePaused(1: PackageID pid, 2: bool paused) throws (1: PackageDoesNotExist e), // as above, this will move files on disk bool movePackage(1: PackageID pid, 2: PackageID root) throws (1: PackageDoesNotExist e), diff --git a/pyload/web/app/scripts/models/Package.js b/pyload/web/app/scripts/models/Package.js index a34ec1c69..555d5b7d6 100644 --- a/pyload/web/app/scripts/models/Package.js +++ b/pyload/web/app/scripts/models/Package.js @@ -1,5 +1,5 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'require'], - function($, Backbone, _, App, FileList, require) { +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collections/FileList', 'require'], + function($, Backbone, _, App, Api, FileList, require) { 'use strict'; return Backbone.Model.extend({ @@ -36,6 +36,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'requ toJSON: function(options) { var obj = Backbone.Model.prototype.toJSON.call(this, options); obj.percent = Math.round(obj.stats.linksdone * 100 / obj.stats.linkstotal); + obj.paused = obj.status === Api.PackageStatus.Paused; return obj; }, @@ -64,6 +65,21 @@ define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'requ // TODO }, + togglePaused: function() { + var self = this; + var paused = this.get('status') === Api.PackageStatus.Paused; + + $.ajax(App.apiRequest('setPackagePaused', { + pid: this.get('pid'), + paused: !paused + }, { + success: function(data) { + console.log('New package status', data); + self.set('status', data); + } + })); + }, + destroy: function(options) { // TODO: Not working when using data?, array seems to break it options = App.apiRequest( diff --git a/pyload/web/app/scripts/views/dashboard/dashboardView.js b/pyload/web/app/scripts/views/dashboard/dashboardView.js index d98e28fe3..6a263bf03 100644 --- a/pyload/web/app/scripts/views/dashboard/dashboardView.js +++ b/pyload/web/app/scripts/views/dashboard/dashboardView.js @@ -28,10 +28,8 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'col var self = this; // When package is added we reload the data - this.listenTo(App.vent, 'package:added', function() { - console.log('Package tree caught, package:added event'); - self.tree.fetch(); - }); + this.listenTo(App.vent, 'package:added', _.bind(this.fetch, this)); + this.listenTo(App.vent, 'package:inserted', _.bind(this.fetch, this)); this.listenTo(App.vent, 'file:updated', _.bind(this.fileUpdated, this)); @@ -59,6 +57,11 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'col this.$('.input').select2({tags: ['a', 'b', 'sdf']}); }, + fetch: function() { + console.log('Fetching package tree'); + this.tree.fetch(); + }, + update: function() { console.log('Update package list'); diff --git a/pyload/web/app/scripts/views/dashboard/packageView.js b/pyload/web/app/scripts/views/dashboard/packageView.js index 1bb250f27..243ebac9b 100644 --- a/pyload/web/app/scripts/views/dashboard/packageView.js +++ b/pyload/web/app/scripts/views/dashboard/packageView.js @@ -11,6 +11,7 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb events: { 'click .package-name, .btn-open': 'open', 'click .icon-refresh': 'restart', + 'click .toggle-paused': 'pause', 'click .select': 'select', 'click .icon-chevron-down': 'loadMenu', 'click .btn-delete': 'deleteItem', @@ -68,6 +69,10 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb App.dashboard.openPackage(this.model); }, + pause: function(e) { + this.model.togglePaused(); + }, + select: function(e) { e.preventDefault(); var checked = this.$('.select').hasClass('icon-check'); diff --git a/pyload/web/app/styles/default/dashboard.less b/pyload/web/app/styles/default/dashboard.less index 336070737..1e9f21fec 100644 --- a/pyload/web/app/styles/default/dashboard.less +++ b/pyload/web/app/styles/default/dashboard.less @@ -85,6 +85,10 @@ .package-frame { background-color: @light; + &.paused { + .stripes(fade(@yellowLightest, 90%), @light); + } + } } diff --git a/pyload/web/app/templates/default/dashboard/package.html b/pyload/web/app/templates/default/dashboard/package.html index cde0dda6e..bc8314494 100644 --- a/pyload/web/app/templates/default/dashboard/package.html +++ b/pyload/web/app/templates/default/dashboard/package.html @@ -7,14 +7,18 @@ {{ name }} </span> - <div class="package-frame"> + <div class="package-frame{{#if paused}} paused{{/if}}"> <div class="tag-area"> <!--<span class="badge badge-success"><i class="icon-tag"></i>video</span>--> <!--<span class="badge badge-success badge-ghost"><i class="icon-tag"></i> Add Tag</span>--> </div> <div class="package-indicator"> <i class="icon-plus-sign btn-move" data-toggle="tooltip" title="Move files here"></i> - <i class="icon-pause" data-toggle="tooltip" title="Pause Package"></i> + {{#if paused}} + <i class="icon-play toggle-paused" data-toggle="tooltip" title="Unpause Package"></i> + {{else}} + <i class="icon-pause toggle-paused" data-toggle="tooltip" title="Pause Package"></i> + {{/if}} <i class="icon-refresh" data-toggle="tooltip" title="Restart Package"></i> {{#if shared }} <i class="icon-eye-open" data-toggle="tooltip" title="Package is public"></i> diff --git a/pyload/web/cnl_app.py b/pyload/web/cnl_app.py index d8311d90f..a3917b052 100644 --- a/pyload/web/cnl_app.py +++ b/pyload/web/cnl_app.py @@ -5,6 +5,7 @@ import re from urllib import unquote from base64 import standard_b64decode from binascii import unhexlify +from traceback import print_exc from pyload.utils.fs import safe_filename @@ -16,6 +17,10 @@ try: except: pass +def generate_and_add(urls, paused): + packs = PYLOAD.generatePackages(urls) + for name, urls in packs.iteritems(): + PYLOAD.addPackage(name, urls, paused=paused) def local_check(function): def _view(*args, **kwargs): @@ -42,9 +47,9 @@ def add(request): urls = filter(lambda x: x != "", request.POST['urls'].split("\n")) if package: - PYLOAD.addPackage(package, urls, 0) + PYLOAD.addPackage(package, urls, paused=True) else: - PYLOAD.generateAndAddPackages(urls, 0) + generate_and_add(urls, True) return "" @@ -61,7 +66,7 @@ def addcrypted(): dlc_file.close() try: - PYLOAD.addPackage(package, [dlc_path], 0) + PYLOAD.addPackage(package, [dlc_path], paused=True) except: return HTTPError() else: @@ -108,11 +113,12 @@ def addcrypted2(): try: if package: - PYLOAD.addPackage(package, result, 0) + PYLOAD.addPackage(package, result, paused=True) else: - PYLOAD.generateAndAddPackages(result, 0) + generate_and_add(result, True) except: - return "failed can't add" + print_exc() + return "failed" else: return "success\r\n" @@ -125,16 +131,17 @@ def flashgot(): if request.environ['HTTP_REFERER'] != "http://localhost:9666/flashgot" and request.environ['HTTP_REFERER'] != "http://127.0.0.1:9666/flashgot": return HTTPError() - autostart = int(request.forms.get('autostart', 0)) + autostart = bool(int(request.forms.get('autostart', 0))) package = request.forms.get('package', None) urls = filter(lambda x: x != "", request.forms['urls'].split("\n")) + + # TODO: folder? folder = request.forms.get('dir', None) if package: - PYLOAD.addPackage(package, urls, autostart) + PYLOAD.addPackage(package, urls, paused=autostart) else: - PYLOAD.generateAndAddPackages(urls, autostart) - + generate_and_add(urls, autostart) return "" @route("/crossdomain.xml") |