mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
+1
-20
@@ -472,32 +472,13 @@ def _add_torrent_file(result):
|
|||||||
# content is torrent file contents that needs to be encoded to base64
|
# content is torrent file contents that needs to be encoded to base64
|
||||||
post_data = json.dumps({"method": "core.add_torrent_file",
|
post_data = json.dumps({"method": "core.add_torrent_file",
|
||||||
"params": [result['name'] + '.torrent',
|
"params": [result['name'] + '.torrent',
|
||||||
b64encode(result['content'].encode('utf8')), {}],
|
b64encode(result['content']).decode(), {}],
|
||||||
"id": 2})
|
"id": 2})
|
||||||
response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth,
|
response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth,
|
||||||
verify=deluge_verify_cert, headers=headers)
|
verify=deluge_verify_cert, headers=headers)
|
||||||
result['hash'] = json.loads(response.text)['result']
|
result['hash'] = json.loads(response.text)['result']
|
||||||
logger.debug('Deluge: Response was %s' % str(json.loads(response.text)))
|
logger.debug('Deluge: Response was %s' % str(json.loads(response.text)))
|
||||||
return json.loads(response.text)['result']
|
return json.loads(response.text)['result']
|
||||||
except UnicodeDecodeError:
|
|
||||||
try:
|
|
||||||
# content is torrent file contents that needs to be encoded to base64
|
|
||||||
# this time let's try leaving the encoding as is
|
|
||||||
logger.debug('Deluge: There was a decoding issue, let\'s try again')
|
|
||||||
post_data = json.dumps({"method": "core.add_torrent_file",
|
|
||||||
"params": [result['name'].decode('utf8') + '.torrent',
|
|
||||||
b64encode(result['content']), {}],
|
|
||||||
"id": 22})
|
|
||||||
response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth,
|
|
||||||
verify=deluge_verify_cert, headers=headers)
|
|
||||||
result['hash'] = json.loads(response.text)['result']
|
|
||||||
logger.debug('Deluge: Response was %s' % str(json.loads(response.text)))
|
|
||||||
return json.loads(response.text)['result']
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Deluge: Adding torrent file failed after decode: %s' % str(e))
|
|
||||||
formatted_lines = traceback.format_exc().splitlines()
|
|
||||||
logger.error('; '.join(formatted_lines))
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Deluge: Adding torrent file failed: %s' % str(e))
|
logger.error('Deluge: Adding torrent file failed: %s' % str(e))
|
||||||
formatted_lines = traceback.format_exc().splitlines()
|
formatted_lines = traceback.format_exc().splitlines()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from collections import Iterable, Mapping
|
from collections.abc import Iterable, Mapping
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
from collections import MutableMapping
|
from collections.abc import MutableMapping
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ __all__ = ["APEv2", "APEv2File", "Open", "delete"]
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
from collections import MutableSequence
|
from collections.abc import MutableSequence
|
||||||
|
|
||||||
from ._compat import (cBytesIO, PY3, text_type, PY2, reraise, swap_to_string,
|
from ._compat import (cBytesIO, PY3, text_type, PY2, reraise, swap_to_string,
|
||||||
xrange)
|
xrange)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
# Loosely based on the API implementation from 'whatbetter', by Zachary Denton
|
# Loosely based on the API implementation from 'whatbetter', by Zachary Denton
|
||||||
# See https://github.com/zacharydenton/whatbetter
|
# See https://github.com/zacharydenton/whatbetter
|
||||||
from html.parser import HTMLParser
|
import html
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
@@ -219,10 +219,10 @@ class GazelleAPI(object):
|
|||||||
else:
|
else:
|
||||||
artist = Artist(id, self)
|
artist = Artist(id, self)
|
||||||
if name:
|
if name:
|
||||||
artist.name = HTMLParser().unescape(name)
|
artist.name = html.unescape(name)
|
||||||
elif name:
|
elif name:
|
||||||
artist = Artist(-1, self)
|
artist = Artist(-1, self)
|
||||||
artist.name = HTMLParser().unescape(name)
|
artist.name = html.unescape(name)
|
||||||
else:
|
else:
|
||||||
raise Exception("You must specify either an ID or a Name to get an artist.")
|
raise Exception("You must specify either an ID or a Name to get an artist.")
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from html.parser import HTMLParser
|
import html
|
||||||
|
|
||||||
class InvalidArtistException(Exception):
|
class InvalidArtistException(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -29,7 +29,7 @@ class Artist(object):
|
|||||||
if self.id > 0:
|
if self.id > 0:
|
||||||
response = self.parent_api.request(action='artist', id=self.id)
|
response = self.parent_api.request(action='artist', id=self.id)
|
||||||
elif self.name:
|
elif self.name:
|
||||||
self.name = HTMLParser().unescape(self.name)
|
self.name = html.unescape(self.name)
|
||||||
try:
|
try:
|
||||||
response = self.parent_api.request(action='artist', artistname=self.name)
|
response = self.parent_api.request(action='artist', artistname=self.name)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -47,7 +47,7 @@ class Artist(object):
|
|||||||
self.id = artist_json_response['id']
|
self.id = artist_json_response['id']
|
||||||
self.parent_api.cached_artists[self.id] = self
|
self.parent_api.cached_artists[self.id] = self
|
||||||
|
|
||||||
self.name = HTMLParser().unescape(artist_json_response['name'])
|
self.name = html.unescape(artist_json_response['name'])
|
||||||
self.notifications_enabled = artist_json_response['notificationsEnabled']
|
self.notifications_enabled = artist_json_response['notificationsEnabled']
|
||||||
self.has_bookmarked = artist_json_response['hasBookmarked']
|
self.has_bookmarked = artist_json_response['hasBookmarked']
|
||||||
self.image = artist_json_response['image']
|
self.image = artist_json_response['image']
|
||||||
|
|||||||
Reference in New Issue
Block a user