mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-10 05:39:35 +01:00
Moved Around Torrent-Type Checking
- From local/data->URL>magnet to magnet->URL->local/data. I feel stupid.
This commit is contained in:
@@ -53,33 +53,12 @@ def addTorrent(link, data=None):
|
||||
try:
|
||||
result = {}
|
||||
retid = False
|
||||
if not (link.startswith('http://') or link.startswith('https://')):
|
||||
if link.endswith('.torrent') or data:
|
||||
if data:
|
||||
logger.debug('Deluge: Getting .torrent data')
|
||||
torrentfile = data
|
||||
else:
|
||||
logger.debug('Deluge: Getting .torrent file')
|
||||
with open(link, 'rb') as f:
|
||||
torrentfile = f.read()
|
||||
# Extract torrent name from .torrent
|
||||
try:
|
||||
logger.debug('Deluge: Getting torrent name length')
|
||||
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]
|
||||
except Exception as e:
|
||||
logger.debug('Deluge: Could not get torrent name, getting file name')
|
||||
# get last part of link/path (name only)
|
||||
name = link.split('\\')[-1].split('/')[-1]
|
||||
# remove '.torrent' suffix
|
||||
if name[-len('.torrent'):] == '.torrent':
|
||||
name = name[:-len('.torrent')]
|
||||
logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name, torrentfile[:40]))
|
||||
result = {'type': 'torrent',
|
||||
'name': name,
|
||||
'content': torrentfile}
|
||||
retid = _add_torrent_file(result)
|
||||
|
||||
if link.startswith('magnet:'):
|
||||
logger.debug('Deluge: Got a magnet link: %s' % link)
|
||||
result = {'type': 'magnet',
|
||||
'url': link}
|
||||
retid = _add_torrent_magnet(result)
|
||||
|
||||
elif link.startswith('http://') or link.startswith('https://'):
|
||||
logger.debug('Deluge: Got a URL: %s' % link)
|
||||
@@ -122,11 +101,34 @@ def addTorrent(link, data=None):
|
||||
'content': torrentfile}
|
||||
retid = _add_torrent_file(result)
|
||||
|
||||
elif link.startswith('magnet:'):
|
||||
logger.debug('Deluge: Got a magnet link: %s' % link)
|
||||
result = {'type': 'magnet',
|
||||
'url': link}
|
||||
retid = _add_torrent_magnet(result)
|
||||
elif not (link.startswith('http://') or link.startswith('https://')):
|
||||
#elif link.endswith('.torrent') or data:
|
||||
if data:
|
||||
logger.debug('Deluge: Getting .torrent data')
|
||||
torrentfile = data
|
||||
else:
|
||||
logger.debug('Deluge: Getting .torrent file')
|
||||
with open(link, 'rb') as f:
|
||||
torrentfile = f.read()
|
||||
# Extract torrent name from .torrent
|
||||
try:
|
||||
logger.debug('Deluge: Getting torrent name length')
|
||||
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]
|
||||
except Exception as e:
|
||||
logger.debug('Deluge: Could not get torrent name, getting file name')
|
||||
# get last part of link/path (name only)
|
||||
name = link.split('\\')[-1].split('/')[-1]
|
||||
# remove '.torrent' suffix
|
||||
if name[-len('.torrent'):] == '.torrent':
|
||||
name = name[:-len('.torrent')]
|
||||
logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name, torrentfile[:40]))
|
||||
result = {'type': 'torrent',
|
||||
'name': name,
|
||||
'content': torrentfile}
|
||||
retid = _add_torrent_file(result)
|
||||
|
||||
else:
|
||||
logger.error('Deluge: Unknown file type: %s' % link)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user