From 73710ab76e451cc549f10df20df86fa56de29525 Mon Sep 17 00:00:00 2001 From: Remy Date: Fri, 22 Jul 2011 13:07:05 -0700 Subject: [PATCH] Music scan fix for Synology/NAS users.Fixed error message when retrying a download with no more matches --- Headphones.py | 7 +------ headphones/importer.py | 10 +++++++++- headphones/searcher.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Headphones.py b/Headphones.py index 3564436f..f8053ff4 100755 --- a/Headphones.py +++ b/Headphones.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import os, sys, locale +import os, sys from lib.configobj import ConfigObj @@ -24,11 +24,6 @@ def main(): headphones.PROG_DIR = os.path.dirname(headphones.FULL_PATH) headphones.ARGS = sys.argv[1:] - try: - locale.setlocale(locale.LC_ALL, "") - except Exception, e: - pass - # Set up and gather command line arguments parser = argparse.ArgumentParser(description='Music add-on for SABnzbd+') diff --git a/headphones/importer.py b/headphones/importer.py index 8e657289..a5f8a584 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -12,6 +12,13 @@ def scanMusic(dir=None): if not dir: dir = headphones.MUSIC_DIR + + try: + dir = str(dir) + except UnicodeEncodeError: + dir = unicode(dir).encode('unicode_escape') + + logger.info('Starting Music Scan with directory: %s' % dir) results = [] @@ -32,7 +39,8 @@ def scanMusic(dir=None): f = MediaFile(song) #logger.debug('Reading: %s' % song.decode('UTF-8')) except: - logger.warn('Could not read file: %s' % song.decode('UTF-8')) + logger.warn('Could not read file: %s' % song) + continue else: if f.albumartist: artist = f.albumartist diff --git a/headphones/searcher.py b/headphones/searcher.py index 45aee2c4..019b98ef 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -14,7 +14,8 @@ def searchNZB(albumid=None, new=False): results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" AND AlbumID=?', [albumid]) else: results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted"') - + new = True + for albums in results: albumid = albums[2] @@ -107,7 +108,6 @@ def searchNZB(albumid=None, new=False): d = feedparser.parse(searchURL) - if not len(d.entries): logger.info(u"No results found from %s for %s" % (headphones.NEWZNAB_HOST, term)) pass @@ -233,6 +233,12 @@ def searchNZB(albumid=None, new=False): bestqual = nzblist[i] break + try: + x = bestqual[0] + except UnboundLocalError: + logger.info('No more matches for %s' % term) + return + else: bestqual = nzblist[0]