Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw better errors to the log when login fails #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/package
File renamed without changes.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Deluge Kodi/XBMC plugin
Based on [code.google.com/p/deluge-xbmc-plugin](https://code.google.com/p/deluge-xbmc-plugin/)
Connects via WebUI to Deluge to display and manipulate the status of torrents from Kodi/XBMC

## Install:
1. Install WebUI plugin for Deluge
2. Enable WebUI for Deluge
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.6.1
8 changes: 4 additions & 4 deletions plugin.program.deluge/addon.xml → addon.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.program.deluge"
name="Deluge"
version="0.5.1"
provider-name="Andriy Korchak (kharts)">
version="0.6.1"
provider-name="hermzz">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
</requires>
Expand All @@ -19,7 +19,7 @@
<description lang="en">Manages your Deluge queue from within Kodi/XBMC![CR][CR]Install:[CR]1. Install WebUI plugin for Deluge[CR]2. Enable WebUI for Deluge[CR]3. Install Deluge Kodi/XBMC plug-in[CR]4. Enter password of Deluge via 'Plug-in Settings'[CR]5. Enjoy!</description>
<description lang="ru">Управляет вашей очередью Deluge из Kodi/XBMC![CR][CR]Установка:[CR]1. Установите плагин WebUI для Deluge[CR]2. Включите плагин WebUI для Deluge[CR]3. Установите дополнение Deluge Kodi/XBMC[CR]4. Введите пароль Deluge в 'Настройках дополнения'[CR]5. Наслаждайтесь!</description>
<description lang="uk">Керує вашою чергою Deluge з Kodi/XBMC![CR][CR]Встановлення:[CR]1. Встановіть додаток WebUI для Deluge[CR]2. Увімкніть додаток WebUI для Deluge[CR]3. Встановіть додаток Deluge Kodi/XBMC[CR]4. Введіть пароль Deluge в 'Налаштуваннях додатка'[CR]5. Насолоджуйтесь!</description>
<website>https://github.com/kharts/deluge-xbmc-plugin</website>
<source>https://github.com/kharts/deluge-xbmc-plugin</source>
<website>https://github.com/hermzz/deluge-kodi-plugin</website>
<source>https://github.com/hermzz/deluge-kodi-plugin</source>
</extension>
</addon>
5 changes: 4 additions & 1 deletion plugin.program.deluge/changelog.txt → changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[B]Version 0.5.2 (11.02.2016)[/B]
- Added "Add torrent" functionality.

[B]Version 0.5.1 (29.06.2015)[/B]
- Updated for Kodi/XBMC v13+
- Fixed errors:
Expand All @@ -23,4 +26,4 @@
- Now PauseAll and ResumeAll actions are present in "Perform Function" dialogBox.

[B]Version 0.4.3 (11.04.2012)[/B]
- Initial Release
- Initial Release
11 changes: 9 additions & 2 deletions plugin.program.deluge/default.py → default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
__cwd__ = xbmc.translatePath( __addon__.getAddonInfo('path') ).decode('utf-8')
__profile__ = xbmc.translatePath( __addon__.getAddonInfo('profile') ).decode('utf-8')
__icondir__ = os.path.join( __cwd__, 'resources', 'icons' )
__addonicon__ = __addon__.getAddonInfo('icon')

# Shared resources
BASE_RESOURCE_PATH = os.path.join( __cwd__, 'resources', 'lib' )
Expand Down Expand Up @@ -179,6 +180,12 @@ def listFilters():

xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=False)

def addFiles(torrentUrl):
restoreSession()
torrentHash = webUI.addTorrent(torrentUrl)
xbmcgui.Dialog().notification(__addonname__, getTranslation(32030 if torrentHash else 32031), __addonicon__)
return torrentHash

def getParams():
global url, name, mode, hashNum, filterName, filterCount, labelName, labelCount
try:
Expand Down Expand Up @@ -257,8 +264,8 @@ def getParams():
#elif mode == 1004:
# limitSpeeds()

#elif mode == 1005:
# addFiles()
elif mode == 1005:
addFiles(url)

elif 0 < mode < 1000:
performAction(hashNum)
Expand Down
File renamed without changes
27 changes: 27 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

VERSION=$(cat ./VERSION);

STAGING_FOLDER="deluge-kodi-plugin-${VERSION}"
ZIP="package/${VERSION}.zip"

if [ ! -d "./package" ]
then
mkdir ./package;
fi

rm -rf $STAGING_FOLDER;
rm -rf $ZIP;

mkdir $STAGING_FOLDER
for FILE in resources addon.xml default.py icon.png;
do
cp -a $FILE $STAGING_FOLDER;
done;

sed -i -E "s/^(\s+version)=\"[0-9\.]+\"/\1=\"${VERSION}\"/" addon.xml

zip -rq $ZIP $STAGING_FOLDER;
rm -rf $STAGING_FOLDER;

echo "New package at ${ZIP}"
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<!-- context.menu -->
<string id="32011">Pause All</string>
<string id="32012">Resume All</string>
<!-- notification -->
<string id="32030">Torrent added !</string>
<string id="32031">Failed to add torrent.</string>
<!-- error -->
<string id="32100">Error!</string>
<string id="32101">Fail to connect to daemon.</string>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def getTorrentList(self):
torrentList = TorrentList()
jsonRes = self.updateUi()
jdata = json.loads(jsonRes)
for torrentId in jdata['result']['torrents']:
for torrentId in jdata.get('result', {}).get('torrents', ()):
torrentInfo = TorrentInfo()
jsonTorrentInfo = jdata['result']['torrents'][torrentId]
torrentInfo.torrentId = torrentId
Expand Down Expand Up @@ -82,6 +82,8 @@ def getFilters(self,filterType):
jsonRes = self.updateUi()
jdata = json.loads(jsonRes)
filterList = []
if jdata.get('error') is not None:
raise ValueError(jdata)
if filterType in jdata['result']['filters']:
for strFilter in jdata['result']['filters'][filterType]:
filterList.append(Filter(strFilter[0], int(strFilter[1])))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
@author: Iulian Postaru
'''

import json, urllib2
import json, urllib2, base64
from httplib import BadStatusLine
from utils import unGzip

class DelugeWebUIJson(object):
Expand All @@ -22,14 +23,19 @@ def sendReq(self, methodName, params, jsonid, cookie):
req = urllib2.Request(self.url, data, {'Content-Type': 'application/json'})
if cookie is not None :
req.add_header('cookie', cookie)
res = urllib2.urlopen(req)
try:
res = urllib2.urlopen(req)
except BadStatusLine as exc:
err_msg = ("Got a BadStatusLine error. Did you enable SSL in Deluge's WebUi plugin? "
"SSL isn't implemented yet in Deluge Kodi/XBMC Plugin.", exc)
raise NotImplementedError(err_msg, exc)
DelugeWebUIJson.cookie = res.headers.get('Set-Cookie')
encoding = res.headers.getheader('Content-Encoding')
content = res.read()
res.close()
if encoding == 'gzip' :
return unGzip(content)
return None
return content

def getJsonId(self):
self.jsonid += 1
Expand All @@ -50,35 +56,27 @@ def noError(self, jsonRes):
def login(self, password) :
return self.isResultOk(self.sendReq('auth.login', [password], self.getJsonId(), None))

#{"method":"auth.check_session","params":[],"id":1}
def checkSession(self) :
return self.isResultOk(self.sendReq('auth.check_session', [], self.getJsonId(), self.cookie))

#{"method":"core.pause_all_torrents","params":[],"id":0}
def pauseAllTorrents(self) :
return self.isResultOk(self.sendReq('core.pause_all_torrents', [], self.getJsonId(), self.cookie))

#{"method":"core.resume_all_torrents","params":[],"id":0}
def resumeAllTorrents(self) :
return self.isResultOk(self.sendReq('core.resume_all_torrents', [], self.getJsonId(), self.cookie))

#{"method":"system.listMethods","params":[],"id":0}
def listMethods(self) :
return self.sendReq('system.listMethods', [], self.getJsonId(), self.cookie)
#{"id":2,"method":"web.update_ui","params":[["name","state","save_path","download_payload_rate","upload_payload_rate","num_seeds","num_seeds","num_peers","total_peers","eta","total_done","total_uploaded","total_size","progress","label"],[]]}
#{"method":"web.update_ui","params":[["queue","name","total_size","state","progress","num_seeds","total_seeds","num_peers","total_peers","download_payload_rate","upload_payload_rate","eta","ratio","distributed_copies","is_auto_managed","time_added","tracker_host"],{}],"id":16}

def updateUi(self) :
return self.sendReq('web.update_ui', [["downloaded","queue","name","total_size","state","progress","num_seeds","total_seeds","num_peers","total_peers","download_payload_rate","upload_payload_rate","eta","ratio","distributed_copies","is_auto_managed","time_added","tracker_host", "label", "total_done"],{}], self.getJsonId(), self.cookie)

#{"method":"web.connected","params":[],"id":8}
def connected(self) :
return self.isResultOk(self.sendReq('web.connected', [], self.getJsonId(), self.cookie))

#{"method":"web.connect","params":["9f1fdd3f2c1b2422951ac0297c3dc9fa5dbfe1e2"],"id":15}
def connect(self, hostId) :
return self.noError(self.sendReq('web.connect', [hostId], self.getJsonId(), self.cookie))

#{"method":"web.get_hosts","params":[],"id":9}
def getHosts(self) :
jsonRes = self.sendReq('web.get_hosts', [], self.getJsonId(), self.cookie)
jdata = json.loads(jsonRes)
Expand All @@ -87,23 +85,27 @@ def getHosts(self) :
hosts.append(host)
return hosts

#{"method":"web.get_events","params":[],"id":10}
def getEvents(self) :
return self.sendReq('web.get_events', [], self.getJsonId(), self.cookie)

#{"method":"web.get_host_status","params":["e2b0f9c8feb2fdf08548459a38c5daef629fe7a4"],"id":11}
# the hostId is returned by webGetHosts
def getHostStatus(self, hostId) :
return self.sendReq('web.get_host_status', [hostId], self.getJsonId(), self.cookie)

#{"method":"core.pause_torrent","params":[["60d5d82328b4547511fdeac9bf4d0112daa0ce00"]],"id":2}
def pauseTorrent(self, torrentId):
return self.isResultOk(self.sendReq('core.pause_torrent', [[torrentId]], self.getJsonId(), self.cookie))

#{"method":"core.resume_torrent","params":[["60d5d82328b4547511fdeac9bf4d0112daa0ce00"]],"id":2}
def resumeTorrent(self, torrentId):
return self.isResultOk(self.sendReq('core.resume_torrent', [[torrentId]], self.getJsonId(), self.cookie))

def addTorrent(self, torrentUrl):
if torrentUrl.startswith("magnet:"):
jsonRes = self.sendReq('core.add_torrent_magnet', [torrentUrl, {}], self.getJsonId(), self.cookie)
else:
metaInfo = base64.b64encode(urllib2.urlopen(torrentUrl).read())
jsonRes = self.sendReq('core.add_torrent_file', ["", metaInfo, {}], self.getJsonId(), self.cookie)
return self.isResultOk(jsonRes)

#TODO: is not working, to find out the params which should be passed
#{"method":"core.remove_torrent","params":["60d5d82328b4547511fdeac9bf4d0112daa0ce00", false],"id":2}
#{"method":"core.remove_torrent","params":[["60d5d82328b4547511fdeac9bf4d0112daa0ce00"],false],"id":2}
Expand All @@ -119,54 +121,11 @@ def getLabels(self):
labels.append(label)
return labels

#label.add

def labelSetTorrent(self, torrentId, label):
return self.sendReq('label.set_torrent', [torrentId, label], self.getJsonId(), self.cookie)

#{"method":"web.get_torrent_files","params":["9982b1b5718279562760544e7007b765602a86ee"],"id":392}
def getTorrentFiles(self, torrentId):
return self.sendReq('web.get_torrent_files', [torrentId], self.getJsonId(), self.cookie)

# {"method":"core.set_torrent_options
def setTorrentOptions(self, torrentId, optionName, optionValue):
#return self.sendReq('core.set_torrent_options', [], self.getJsonId(), self.cookie)
return self.sendReq('core.set_torrent_options', [[torrentId],{optionName:optionValue}], self.getJsonId(), self.cookie)

#{"method":"web.get_events","params":[],"id":391}
#{"method":"web.get_torrent_files","params":["9982b1b5718279562760544e7007b765602a86ee"],"id":392}


#{"method":"label.get_labels","params":[],"id":10}
#def getLabels(self) :
# return self.sendReq('label.get_labels', [], self.getJsonId(), self.cookie)

#{"id":2,"method":"core.set_config","params":[[{"max_upload_speed":2},{"max_download_speed":1}]]}

#{"id":2,"method":"core.add_torrent_url","params":["http://btjunkie.org/torrent/Ubuntu-9-10-i386-BETA/4358b74c45dccf021307145a899c1fbaf0d60663f899/download.torrent",[]]}

#web.add_torrents
#core.force_recheck
#core.set_torrent_prioritize_first_last
#core.set_torrent_move_completed
#core.set_torrent_file_priorities
#core.set_torrent_remove_at_ratio
#core.set_torrent_stop_ratio
#core.move_storage
#core.force_reannounce
#core.add_torrent_file
#core.set_torrent_move_completed_path
#core.set_torrent_stop_at_ratio
#core.rename_folder
#core.rename_files
#core.queue_top
#core.queue_down
#core.queue_up
#daemon.shutdown
#web.start_daemon
#web.stop_daemon
#webui.start
#webui.stop
#core.add_torrent_magnet
#auth.change_password
#web.get_torrent_files
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.