mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-21 08:24:00 +01:00
Added Logging
For debugging
This commit is contained in:
+23
-9
@@ -56,31 +56,40 @@ def addTorrent(link, data=None):
|
|||||||
retid = False
|
retid = False
|
||||||
if link.endswith('.torrent') or data:
|
if link.endswith('.torrent') or data:
|
||||||
if data:
|
if data:
|
||||||
|
logger.debug('Deluge: Getting .torrent data')
|
||||||
torrentfile = data
|
torrentfile = data
|
||||||
else:
|
else:
|
||||||
|
logger.debug('Deluge: Getting .torrent file')
|
||||||
with open(link, 'rb') as f:
|
with open(link, 'rb') as f:
|
||||||
torrentfile = f.read()
|
torrentfile = f.read()
|
||||||
# Extract torrent name from .torrent
|
# Extract torrent name from .torrent
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Deluge: Getting torrent name length')
|
||||||
name_length = int(re.findall('name([0-9]*)\:.*?\:', torrentfile)[0])
|
name_length = int(re.findall('name([0-9]*)\:.*?\:', torrentfile)[0])
|
||||||
|
logger.debug('Deluge: Getting torrent name')
|
||||||
name = re.findall('name[0-9]*\:(.*?)\:', torrentfile)[0][:name_length]
|
name = re.findall('name[0-9]*\:(.*?)\:', torrentfile)[0][:name_length]
|
||||||
except:
|
except:
|
||||||
|
logger.debug('Deluge: Could not get torrent name, getting file name')
|
||||||
# get last part of link/path (name only)
|
# get last part of link/path (name only)
|
||||||
name = link.split('\\')[-1].split('/')[-1]
|
name = link.split('\\')[-1].split('/')[-1]
|
||||||
# remove '.torrent' suffix
|
# remove '.torrent' suffix
|
||||||
if name[-len('.torrent'):] == '.torrent':
|
if name[-len('.torrent'):] == '.torrent':
|
||||||
name = name[:-len('.torrent')]
|
name = name[:-len('.torrent')]
|
||||||
|
logger.debug('Deluge: Sending Deluge torrent with name ' + name)
|
||||||
result = {'type': 'torrent',
|
result = {'type': 'torrent',
|
||||||
'name': name,
|
'name': name,
|
||||||
'content': torrentfile}
|
'content': torrentfile}
|
||||||
retid = _add_torrent_file(result)
|
retid = _add_torrent_file(result)
|
||||||
|
|
||||||
elif link.startswith('http://') or link.startswith('https://'):
|
elif link.startswith('http://') or link.startswith('https://'):
|
||||||
|
logger.debug('Deluge: Got a URL: ' + link)
|
||||||
user_agent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2243.2 Safari/537.36'
|
user_agent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2243.2 Safari/537.36'
|
||||||
headers = {'User-Agent': user_agent}
|
headers = {'User-Agent': user_agent}
|
||||||
torrentfile = ''
|
torrentfile = ''
|
||||||
|
logger.debug('Deluge: Trying to download (GET)')
|
||||||
r = requests.get(link, headers=headers)
|
r = requests.get(link, headers=headers)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
|
logger.debug('Deluge: 200 OK')
|
||||||
for chunk in r.iter_content(chunk_size=1024):
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
if chunk: # filter out keep-alive new chunks
|
if chunk: # filter out keep-alive new chunks
|
||||||
torrentfile = torrentfile + chunk
|
torrentfile = torrentfile + chunk
|
||||||
@@ -92,20 +101,25 @@ def addTorrent(link, data=None):
|
|||||||
return False
|
return False
|
||||||
# Extract torrent name from .torrent
|
# Extract torrent name from .torrent
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Deluge: Getting torrent name length')
|
||||||
name_length = int(re.findall('name([0-9]*)\:.*?\:', torrentfile)[0])
|
name_length = int(re.findall('name([0-9]*)\:.*?\:', torrentfile)[0])
|
||||||
|
logger.debug('Deluge: Getting torrent name')
|
||||||
name = re.findall('name[0-9]*\:(.*?)\:', torrentfile)[0][:name_length]
|
name = re.findall('name[0-9]*\:(.*?)\:', torrentfile)[0][:name_length]
|
||||||
except:
|
except:
|
||||||
|
logger.debug('Deluge: Could not get torrent name, getting file name')
|
||||||
# get last part of link/path (name only)
|
# get last part of link/path (name only)
|
||||||
name = link.split('\\')[-1].split('/')[-1]
|
name = link.split('\\')[-1].split('/')[-1]
|
||||||
# remove '.torrent' suffix
|
# remove '.torrent' suffix
|
||||||
if name[-len('.torrent'):] == '.torrent':
|
if name[-len('.torrent'):] == '.torrent':
|
||||||
name = name[:-len('.torrent')]
|
name = name[:-len('.torrent')]
|
||||||
|
logger.debug('Deluge: Sending Deluge torrent with name ' + name)
|
||||||
result = {'type': 'torrent',
|
result = {'type': 'torrent',
|
||||||
'name': name,
|
'name': name,
|
||||||
'content': torrentfile}
|
'content': torrentfile}
|
||||||
retid = _add_torrent_file(result)
|
retid = _add_torrent_file(result)
|
||||||
|
|
||||||
elif link.startswith('magnet:'):
|
elif link.startswith('magnet:'):
|
||||||
|
logger.debug('Deluge: Got a magnet link: ' + link)
|
||||||
result = {'type': 'magnet',
|
result = {'type': 'magnet',
|
||||||
'url': link}
|
'url': link}
|
||||||
retid = _add_torrent_uri(result)
|
retid = _add_torrent_uri(result)
|
||||||
@@ -191,7 +205,7 @@ def removeTorrent(torrentid, remove_data=False):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_auth():
|
def _get_auth():
|
||||||
|
logger.debug('Deluge: Authenticating...')
|
||||||
global delugeweb_auth, delugeweb_url
|
global delugeweb_auth, delugeweb_url
|
||||||
delugeweb_auth = {}
|
delugeweb_auth = {}
|
||||||
|
|
||||||
@@ -274,7 +288,7 @@ def _get_auth():
|
|||||||
return auth
|
return auth
|
||||||
|
|
||||||
def _add_torrent_uri(result):
|
def _add_torrent_uri(result):
|
||||||
|
logger.debug('Deluge: Adding URI')
|
||||||
if not any(delugeweb_auth):
|
if not any(delugeweb_auth):
|
||||||
_get_auth()
|
_get_auth()
|
||||||
|
|
||||||
@@ -283,11 +297,11 @@ def _add_torrent_uri(result):
|
|||||||
"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)
|
||||||
result['hash'] = json.loads(response.text)['result']
|
result['hash'] = json.loads(response.text)['result']
|
||||||
|
logger.debug('Deluge: Response was ' + json.loads(response.text)['result'])
|
||||||
return json.loads(response.text)['result']
|
return json.loads(response.text)['result']
|
||||||
|
|
||||||
def _add_torrent_file(result):
|
def _add_torrent_file(result):
|
||||||
|
logger.debug('Deluge: Adding file')
|
||||||
if not any(delugeweb_auth):
|
if not any(delugeweb_auth):
|
||||||
_get_auth()
|
_get_auth()
|
||||||
|
|
||||||
@@ -297,11 +311,11 @@ def _add_torrent_file(result):
|
|||||||
"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)
|
||||||
result['hash'] = json.loads(response.text)['result']
|
result['hash'] = json.loads(response.text)['result']
|
||||||
|
logger.debug('Deluge: Response was ' + json.loads(response.text)['result'])
|
||||||
return json.loads(response.text)['result']
|
return json.loads(response.text)['result']
|
||||||
|
|
||||||
def setTorrentLabel(result):
|
def setTorrentLabel(result):
|
||||||
|
logger.debug('Deluge: Setting label')
|
||||||
label = headphones.CONFIG.DELUGE_LABEL
|
label = headphones.CONFIG.DELUGE_LABEL
|
||||||
|
|
||||||
if not any(delugeweb_auth):
|
if not any(delugeweb_auth):
|
||||||
@@ -340,7 +354,7 @@ def setTorrentLabel(result):
|
|||||||
return not json.loads(response.text)['error']
|
return not json.loads(response.text)['error']
|
||||||
|
|
||||||
def setSeedRatio(result):
|
def setSeedRatio(result):
|
||||||
|
logger.debug('Deluge: Setting seed ratio')
|
||||||
if not any(delugeweb_auth):
|
if not any(delugeweb_auth):
|
||||||
_get_auth()
|
_get_auth()
|
||||||
|
|
||||||
@@ -363,7 +377,7 @@ def setSeedRatio(result):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def setTorrentPath(result):
|
def setTorrentPath(result):
|
||||||
|
logger.debug('Deluge: Setting download path')
|
||||||
if not any(delugeweb_auth):
|
if not any(delugeweb_auth):
|
||||||
_get_auth()
|
_get_auth()
|
||||||
|
|
||||||
@@ -391,7 +405,7 @@ def setTorrentPath(result):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def setTorrentPause(result):
|
def setTorrentPause(result):
|
||||||
|
logger.debug('Deluge: Pausing torrent')
|
||||||
if not any(delugeweb_auth):
|
if not any(delugeweb_auth):
|
||||||
_get_auth()
|
_get_auth()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user