Merge branch 'bugfixes6' of https://github.com/basilfx/headphones into basilfx-bugfixes6

This commit is contained in:
Ade
2014-07-08 18:56:42 +12:00
7 changed files with 72 additions and 53 deletions

View File

@@ -724,7 +724,6 @@ def initialize():
# Start the logger, disable console if needed
logger.initLogger(console=not QUIET, verbose=VERBOSE)
logger.initLogger(console=not QUIET, verbose=False)
if not CACHE_DIR:
# Put the cache dir in the data dir for now

View File

@@ -45,10 +45,10 @@ def request_response(url, method="get", auto_raise=True, whitelist_status_code=N
return response
except requests.ConnectionError:
logger.error("Unable to connect to remote host.")
logger.error("Unable to connect to remote host. Check if the remote host is up and running.")
except requests.Timeout:
logger.error("Request timed out.")
except requests.HTTPError, e:
logger.error("Request timed out. The remote host did not respeond timely.")
except requests.HTTPError as e:
if e.response is not None:
if e.response.status_code >= 500:
cause = "remote server error"
@@ -59,9 +59,28 @@ def request_response(url, method="get", auto_raise=True, whitelist_status_code=N
cause = "unknown"
logger.error("Request raise HTTP error with status code %d (%s).", e.response.status_code, cause)
# Some servers return extra information in the result. Try to parse
# it for debugging purpose. Messages are limited to 100 characters,
# since it may return the whole page in case of normal web page URLs
if headphones.VERBOSE:
if e.response.headers.get('content-type') == 'text/html':
soup = BeautifulSoup(e.response.content, "html5lib")
message = soup.find("body")
message = message.text if message else soup.text
else:
message = e.response.content
if message:
# Truncate message if it is too long.
if len(message) > 100:
message = message[:100] + "..."
logger.debug("Server responded with message: %s", message)
else:
logger.error("Request raised HTTP error.")
except requests.RequestException, e:
except requests.RequestException as e:
logger.error("Request raised exception: %s", e)
def request_soup(url, **kwargs):

View File

@@ -221,7 +221,7 @@ def sort_search_results(resultlist, album, new):
if not len(finallist) and len(flac_list) and headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS:
logger.info("Since there were no appropriate lossy matches (and at least one lossless match, going to use lossless instead")
finallist = sorted(flac_list, key=lambda title: (title[5], int(title[1])), reverse=True)
except Exception, e:
except Exception as e:
logger.exception('Unhandled exception')
logger.info('No track information for %s - %s. Defaulting to highest quality', (album['ArtistName'], album['AlbumTitle']))
@@ -372,7 +372,7 @@ def searchNZB(album, new=False, losslessOnly=False):
resultlist.append((title, size, url, provider, 'nzb'))
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
except Exception, e:
except Exception as e:
logger.error(u"An unknown error occurred trying to parse the feed: %s" % e)
if headphones.NEWZNAB:
@@ -444,7 +444,7 @@ def searchNZB(album, new=False, losslessOnly=False):
resultlist.append((title, size, url, provider, 'nzb'))
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
except Exception, e:
except Exception as e:
logger.exception("An unknown error occurred trying to parse the feed: %s" % e)
if headphones.NZBSORG:
@@ -491,7 +491,7 @@ def searchNZB(album, new=False, losslessOnly=False):
resultlist.append((title, size, url, provider, 'nzb'))
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
except Exception, e:
except Exception as e:
logger.exception("Unhandled exception while parsing feed")
if headphones.NZBSRUS:
@@ -543,7 +543,7 @@ def searchNZB(album, new=False, losslessOnly=False):
resultlist.append((title, size, url, provider, 'nzb'))
logger.info('Found %s. Size: %s', title, helpers.bytes_to_mb(size))
except Exception, e:
except Exception as e:
logger.exception("Unhandled exception")
if headphones.OMGWTFNZBS:
@@ -590,7 +590,7 @@ def searchNZB(album, new=False, losslessOnly=False):
resultlist.append((title, size, url, provider, 'nzb'))
logger.info('Found %s. Size: %s', title, helpers.bytes_to_mb(size))
except Exception, e:
except Exception as e:
logger.exception("Unhandled exception")
# attempt to verify that this isn't a substring result
@@ -646,7 +646,7 @@ def send_to_downloader(data, bestqual, album):
os.umask(prev)
logger.info('File saved to: %s', nzb_name)
except Exception, e:
except Exception as e:
logger.error('Couldn\'t write NZB file: %s', e)
return
else:
@@ -671,7 +671,7 @@ def send_to_downloader(data, bestqual, album):
# Gonna just take a guess at this..... Is there a better way to find this out?
folder_name = bestqual[0]
except Exception, e:
except Exception as e:
logger.error("Error opening magnet link: %s" % str(e))
return
else:
@@ -702,7 +702,7 @@ def send_to_downloader(data, bestqual, album):
folder_name = torrent_info['info'].get('name', '')
logger.info('Torrent folder name: %s' % folder_name)
except Exception, e:
except Exception as e:
logger.error('Couldn\'t get name from Torrent file: %s. Defaulting to torrent title' % e)
folder_name = bestqual[0]
@@ -732,7 +732,7 @@ def send_to_downloader(data, bestqual, album):
if bestqual[3] == 'rutracker.org':
try:
shutil.rmtree(os.path.split(file_or_url)[0])
except Exception, e:
except Exception as e:
logger.exception("Unhandled exception")
else:# if headphones.TORRENT_DOWNLOADER == 2:
@@ -758,7 +758,7 @@ def send_to_downloader(data, bestqual, album):
if bestqual[3] == 'rutracker.org':
try:
shutil.rmtree(os.path.split(file_or_url)[0])
except Exception, e:
except Exception as e:
logger.exception("Unhandled exception")
myDB = db.DBConnection()
@@ -1014,7 +1014,7 @@ def searchTorrent(album, new=False, losslessOnly=False):
# Process feed
if data:
if not len(data.entries):
logger.info(u"No results found from %s for %s" % provider, term)
logger.info(u"No results found from %s for %s", provider, term)
else:
for item in data.entries:
try:
@@ -1031,8 +1031,8 @@ def searchTorrent(album, new=False, losslessOnly=False):
resultlist.append((title, size, url, provider, 'torrent'))
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
else:
logger.info('%s is larger than the maxsize, the wrong format or has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %i, Format: %s)' % (title, size, int(seeders), rightformat))
except Exception, e:
logger.info('%s is larger than the maxsize, the wrong format or has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %d, Format: %s)', title, size, seeders, rightformat)
except Exception as e:
logger.exception("Unhandled exception in the KAT parser")
if headphones.WAFFLES:
@@ -1063,7 +1063,7 @@ def searchTorrent(album, new=False, losslessOnly=False):
'-seeders:0']) # cut out dead torrents
if bitrate:
query_items.append('bitrate:"%s"' % bitrate)
query_items.append('bitrate:"%s"', bitrate)
# Requesting content
logger.info('Parsing results from Waffles')
@@ -1087,7 +1087,7 @@ def searchTorrent(album, new=False, losslessOnly=False):
# Process feed
if data:
if not len(data.entries):
logger.info(u"No results found from %s for %s" % (provider, term))
logger.info(u"No results found from %s for %s", provider, term)
else:
for item in data.entries:
try:
@@ -1096,9 +1096,9 @@ def searchTorrent(album, new=False, losslessOnly=False):
size = int(desc_match.group(1))
url = item.link
resultlist.append((title, size, url, provider, 'torrent'))
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
except Exception, e:
logger.error(u"An error occurred while trying to parse the response from Waffles.fm: %s" % e)
logger.info('Found %s. Size: %s', title, helpers.bytes_to_mb(size))
except Exception as e:
logger.error(u"An error occurred while trying to parse the response from Waffles.fm: %s", e)
# rutracker.org
@@ -1183,7 +1183,7 @@ def searchTorrent(album, new=False, losslessOnly=False):
logger.info(u"Attempting to log in to What.cd...")
gazelle = gazelleapi.GazelleAPI(headphones.WHATCD_USERNAME, headphones.WHATCD_PASSWORD)
gazelle._login()
except Exception, e:
except Exception as e:
gazelle = None
logger.error(u"What.cd credentials incorrect or site is down. Error: %s %s" % (e.__class__.__name__, str(e)))
@@ -1307,7 +1307,7 @@ def searchTorrent(album, new=False, losslessOnly=False):
else:
logger.info('%s is larger than the maxsize or has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %i)' % (title, size, int(seeds)))
except Exception, e:
except Exception as e:
logger.error(u"An unknown error occurred in the Pirate Bay parser: %s" % e)
if headphones.ISOHUNT:
@@ -1427,7 +1427,7 @@ def searchTorrent(album, new=False, losslessOnly=False):
else:
logger.info('%s is larger than the maxsize, the wrong format or has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %i, Format: %s)' % (title, size, int(seeds), rightformat))
except Exception, e:
except Exception as e:
logger.exception("Unhandled exception in Mininova Parser")
#attempt to verify that this isn't a substring result
@@ -1482,7 +1482,7 @@ def preprocess(resultlist):
#TODO: Do we want rar checking in here to try to keep unknowns out?
#or at least the option to do so?
except Exception, e:
except Exception as e:
logger.exception('Unhandled exception. Unable to parse the best result NZB. Error: %s. (Make sure your username/password/API is correct for provider: %s', e ,result[3])
continue
@@ -1507,4 +1507,4 @@ def CalculateTorrentHash(link, data):
logger.debug('Torrent Hash: ' + str(tor_hash))
return tor_hash
return tor_hash

View File

@@ -38,7 +38,7 @@ status_cmd="${name}_status"
stop_cmd="${name}_stop"
command="/usr/sbin/daemon"
command_args="-f -p ${headphones_pid} python ${headphones_dir}/Headphones.py ${headphones_flags} --quiet"
command_args="-f -p ${headphones_pid} python ${headphones_dir}/Headphones.py ${headphones_flags} --quiet --nolaunch"
# Ensure user is root when running this script.
if [ `id -u` != "0" ]; then

View File

@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.headphones.headphones</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python</string>
<string>/Applications/Headphones/headphones.py</string>
<string>-q</string>
<string>-d</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.headphones.headphones</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python</string>
<string>/Applications/Headphones/headphones.py</string>
<string>--quiet</string>
<string>--daemon</string>
<string>--nolaunch</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

View File

@@ -7,7 +7,7 @@
<service name="application/headphones" type="service" version="1">
<create_default_instance enabled="true"/>
<single_instance/>
<dependency name="network" grouping="require_all" restart_on="error" type="service">
@@ -22,7 +22,7 @@
<method_credential user="sabnzbd" group="sabnzbd"/>
</method_context>
<exec_method type="method" name="start" exec="python /opt/headphones/Headphones.py -d" timeout_seconds="60"/>
<exec_method type="method" name="start" exec="python /opt/headphones/Headphones.py --daemon --quiet --nolaunch" timeout_seconds="60"/>
<exec_method type="method" name="stop" exec=":kill" timeout_seconds="60"/>
@@ -30,8 +30,8 @@
<propval name="duration" type="astring" value="contract"/>
<propval name="ignore_error" type="astring" value="core,signal"/>
</property_group>
<stability value="Evolving"/>
<template>

View File

@@ -4,10 +4,10 @@
## Edit user configuation in /etc/default/headphones to change
##
## Make sure init script is executable
## sudo chmod +x /opt/headphones/init.ubuntu
## sudo chmod +x /path/to/init.ubuntu
##
## Install the init script
## sudo ln -s /opt/headphones/init.ubuntu /etc/init.d/headphones
## sudo ln -s /path/to/init.ubuntu /etc/init.d/headphones
##
## Create the headphones daemon user:
## sudo adduser --system --no-create-home headphones