mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
Merge branch 'develop'
This commit is contained in:
@@ -225,6 +225,8 @@ HPPASS = None
|
|||||||
|
|
||||||
CACHE_SIZEMB = 32
|
CACHE_SIZEMB = 32
|
||||||
|
|
||||||
|
UMASK = None
|
||||||
|
|
||||||
def CheckSection(sec):
|
def CheckSection(sec):
|
||||||
""" Check if INI section exists, if not create it """
|
""" Check if INI section exists, if not create it """
|
||||||
try:
|
try:
|
||||||
@@ -291,7 +293,8 @@ def initialize():
|
|||||||
PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_KEYS, PUSHOVER_ONSNATCH, MIRRORLIST, \
|
PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_KEYS, PUSHOVER_ONSNATCH, MIRRORLIST, \
|
||||||
MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \
|
MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \
|
||||||
XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \
|
XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \
|
||||||
PREFERRED_BITRATE_LOW_BUFFER, PREFERRED_BITRATE_ALLOW_LOSSLESS, CACHE_SIZEMB
|
PREFERRED_BITRATE_LOW_BUFFER, PREFERRED_BITRATE_ALLOW_LOSSLESS, CACHE_SIZEMB, \
|
||||||
|
UMASK
|
||||||
|
|
||||||
if __INITIALIZED__:
|
if __INITIALIZED__:
|
||||||
return False
|
return False
|
||||||
@@ -584,6 +587,10 @@ def initialize():
|
|||||||
else:
|
else:
|
||||||
LATEST_VERSION = CURRENT_VERSION
|
LATEST_VERSION = CURRENT_VERSION
|
||||||
|
|
||||||
|
# Store the original umask
|
||||||
|
UMASK = os.umask(0)
|
||||||
|
os.umask(UMASK)
|
||||||
|
|
||||||
__INITIALIZED__ = True
|
__INITIALIZED__ = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -318,7 +318,10 @@ def getRelease(releaseid, include_artist_info=True):
|
|||||||
if 'release-group' in results:
|
if 'release-group' in results:
|
||||||
release['rgid'] = unicode(results['release-group']['id'])
|
release['rgid'] = unicode(results['release-group']['id'])
|
||||||
release['rg_title'] = unicode(results['release-group']['title'])
|
release['rg_title'] = unicode(results['release-group']['title'])
|
||||||
release['rg_type'] = unicode(results['release-group']['type'])
|
try:
|
||||||
|
release['rg_type'] = unicode(results['release-group']['type'])
|
||||||
|
except KeyError:
|
||||||
|
release['rg_type'] = u'Unknown'
|
||||||
else:
|
else:
|
||||||
logger.warn("Release " + releaseid + "had no ReleaseGroup associated")
|
logger.warn("Release " + releaseid + "had no ReleaseGroup associated")
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ def checkFolder():
|
|||||||
sab_replace_spaces(sab_replace_dots(album['FolderName']))
|
sab_replace_spaces(sab_replace_dots(album['FolderName']))
|
||||||
]
|
]
|
||||||
|
|
||||||
torrent_album_path = os.path.join(headphones.DOWNLOAD_TORRENT_DIR, album['FolderName']).encode(headphones.SYS_ENCODING)
|
torrent_album_path = os.path.join(headphones.DOWNLOAD_TORRENT_DIR, album['FolderName']).encode(headphones.SYS_ENCODING,'replace')
|
||||||
|
|
||||||
for nzb_folder_name in nzb_album_possibilities:
|
for nzb_folder_name in nzb_album_possibilities:
|
||||||
|
|
||||||
nzb_album_path = os.path.join(headphones.DOWNLOAD_DIR, nzb_folder_name).encode(headphones.SYS_ENCODING)
|
nzb_album_path = os.path.join(headphones.DOWNLOAD_DIR, nzb_folder_name).encode(headphones.SYS_ENCODING, 'replace')
|
||||||
|
|
||||||
if os.path.exists(nzb_album_path):
|
if os.path.exists(nzb_album_path):
|
||||||
logger.debug('Found %s in NZB download folder. Verifying....' % album['FolderName'])
|
logger.debug('Found %s in NZB download folder. Verifying....' % album['FolderName'])
|
||||||
@@ -448,9 +448,11 @@ def addAlbumArt(artwork, albumpath, release):
|
|||||||
if album_art_name.startswith('.'):
|
if album_art_name.startswith('.'):
|
||||||
album_art_name = album_art_name.replace(0, '_')
|
album_art_name = album_art_name.replace(0, '_')
|
||||||
|
|
||||||
|
prev = os.umask(headphones.UMASK)
|
||||||
file = open(os.path.join(albumpath, album_art_name), 'wb')
|
file = open(os.path.join(albumpath, album_art_name), 'wb')
|
||||||
file.write(artwork)
|
file.write(artwork)
|
||||||
file.close()
|
file.close()
|
||||||
|
os.umask(prev)
|
||||||
|
|
||||||
def cleanupFiles(albumpath):
|
def cleanupFiles(albumpath):
|
||||||
logger.info('Cleaning up files')
|
logger.info('Cleaning up files')
|
||||||
@@ -475,22 +477,24 @@ def moveFiles(albumpath, release, tracks):
|
|||||||
releasetype = release['Type'].replace('/', '_')
|
releasetype = release['Type'].replace('/', '_')
|
||||||
|
|
||||||
if release['ArtistName'].startswith('The '):
|
if release['ArtistName'].startswith('The '):
|
||||||
sortname = release['ArtistName'][4:]
|
sortname = release['ArtistName'][4:] + ", The"
|
||||||
else:
|
else:
|
||||||
sortname = release['ArtistName']
|
sortname = release['ArtistName']
|
||||||
|
|
||||||
if sortname.isdigit():
|
if sortname[0].isdigit():
|
||||||
firstchar = '0-9'
|
firstchar = '0-9'
|
||||||
else:
|
else:
|
||||||
firstchar = sortname[0]
|
firstchar = sortname[0]
|
||||||
|
|
||||||
|
|
||||||
values = { '$Artist': artist,
|
values = { '$Artist': artist,
|
||||||
|
'$SortArtist': sortname,
|
||||||
'$Album': album,
|
'$Album': album,
|
||||||
'$Year': year,
|
'$Year': year,
|
||||||
'$Type': releasetype,
|
'$Type': releasetype,
|
||||||
'$First': firstchar.upper(),
|
'$First': firstchar.upper(),
|
||||||
'$artist': artist.lower(),
|
'$artist': artist.lower(),
|
||||||
|
'$sortartist': sortname.lower(),
|
||||||
'$album': album.lower(),
|
'$album': album.lower(),
|
||||||
'$year': year,
|
'$year': year,
|
||||||
'$type': releasetype.lower(),
|
'$type': releasetype.lower(),
|
||||||
@@ -776,16 +780,28 @@ def renameFiles(albumpath, downloaded_track_list, release):
|
|||||||
else:
|
else:
|
||||||
title = f.title
|
title = f.title
|
||||||
|
|
||||||
|
if release['ArtistName'] == "Various Artists" and f.artist:
|
||||||
|
artistname = f.artist
|
||||||
|
else:
|
||||||
|
artistname = release['ArtistName']
|
||||||
|
|
||||||
|
if artistname.startswith('The '):
|
||||||
|
sortname = artistname[4:] + ", The"
|
||||||
|
else:
|
||||||
|
sortname = artistname
|
||||||
|
|
||||||
values = { '$Disc': discnumber,
|
values = { '$Disc': discnumber,
|
||||||
'$Track': tracknumber,
|
'$Track': tracknumber,
|
||||||
'$Title': title,
|
'$Title': title,
|
||||||
'$Artist': release['ArtistName'],
|
'$Artist': artistname,
|
||||||
|
'$SortArtist': sortname,
|
||||||
'$Album': release['AlbumTitle'],
|
'$Album': release['AlbumTitle'],
|
||||||
'$Year': year,
|
'$Year': year,
|
||||||
'$disc': discnumber,
|
'$disc': discnumber,
|
||||||
'$track': tracknumber,
|
'$track': tracknumber,
|
||||||
'$title': title.lower(),
|
'$title': title.lower(),
|
||||||
'$artist': release['ArtistName'].lower(),
|
'$artist': artistname.lower(),
|
||||||
|
'$sortartist': sortname.lower(),
|
||||||
'$album': release['AlbumTitle'].lower(),
|
'$album': release['AlbumTitle'].lower(),
|
||||||
'$year': year
|
'$year': year
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-25
@@ -125,7 +125,7 @@ def searchforalbum(albumid=None, new=False, lossless=False):
|
|||||||
else:
|
else:
|
||||||
|
|
||||||
foundNZB = "none"
|
foundNZB = "none"
|
||||||
if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN) and (headphones.SAB_HOST or headphones.BLACKHOLE):
|
if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN or headphones.NZBX or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE):
|
||||||
foundNZB = searchNZB(albumid, new, lossless)
|
foundNZB = searchNZB(albumid, new, lossless)
|
||||||
|
|
||||||
if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES or headphones.RUTRACKER or headphones.WHATCD) and foundNZB == "none":
|
if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES or headphones.RUTRACKER or headphones.WHATCD) and foundNZB == "none":
|
||||||
@@ -348,18 +348,18 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
|||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
|
||||||
d = feedparser.parse(data)
|
d = json.loads(data.replace('null','None'))
|
||||||
|
|
||||||
if not len(d.entries):
|
if d['matches'] <= 0:
|
||||||
logger.info(u"No results found from NZBsRus for %s" % term)
|
logger.info(u"No results found from NZBsRus for %s" % term)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for item in d.entries:
|
for item in d['results']:
|
||||||
try:
|
try:
|
||||||
url = item.link
|
url = "http://www.nzbsrus.com/nzbdownload_rss.php/" + item['id'] + "/" + headphones.NZBSRUS_UID + "/" + item['key']
|
||||||
title = item.title
|
title = item['name']
|
||||||
size = int(item.links[1]['length'])
|
size = int(item['size'])
|
||||||
|
|
||||||
resultlist.append((title, size, url, provider))
|
resultlist.append((title, size, url, provider))
|
||||||
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||||
@@ -553,9 +553,11 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
|||||||
nzb_name = nzb_folder_name + '.nzb'
|
nzb_name = nzb_folder_name + '.nzb'
|
||||||
download_path = os.path.join(headphones.BLACKHOLE_DIR, nzb_name)
|
download_path = os.path.join(headphones.BLACKHOLE_DIR, nzb_name)
|
||||||
try:
|
try:
|
||||||
|
prev = os.umask(headphones.UMASK)
|
||||||
f = open(download_path, 'w')
|
f = open(download_path, 'w')
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
|
os.umask(prev)
|
||||||
logger.info('File saved to: %s' % nzb_name)
|
logger.info('File saved to: %s' % nzb_name)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error('Couldn\'t write NZB file: %s' % e)
|
logger.error('Couldn\'t write NZB file: %s' % e)
|
||||||
@@ -743,6 +745,12 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False):
|
|||||||
else:
|
else:
|
||||||
term = cleanartist + ' ' + cleanalbum
|
term = cleanartist + ' ' + cleanalbum
|
||||||
|
|
||||||
|
# Save user search term
|
||||||
|
if albums[4]:
|
||||||
|
usersearchterm = term
|
||||||
|
else:
|
||||||
|
usersearchterm = ''
|
||||||
|
|
||||||
semi_clean_artist_term = re.sub('[\.\-\/]', ' ', semi_cleanartist).encode('utf-8', 'replace')
|
semi_clean_artist_term = re.sub('[\.\-\/]', ' ', semi_cleanartist).encode('utf-8', 'replace')
|
||||||
semi_clean_album_term = re.sub('[\.\-\/]', ' ', semi_cleanalbum).encode('utf-8', 'replace')
|
semi_clean_album_term = re.sub('[\.\-\/]', ' ', semi_cleanalbum).encode('utf-8', 'replace')
|
||||||
# Replace bad characters in the term and unicode it
|
# Replace bad characters in the term and unicode it
|
||||||
@@ -844,11 +852,17 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False):
|
|||||||
format = "MP3"
|
format = "MP3"
|
||||||
maxsize = 300000000
|
maxsize = 300000000
|
||||||
|
|
||||||
query_items = ['artist:"%s"' % artistterm,
|
if not usersearchterm:
|
||||||
'album:"%s"' % albumterm,
|
query_items = ['artist:"%s"' % artistterm,
|
||||||
'format:(%s)' % format,
|
'album:"%s"' % albumterm,
|
||||||
'size:[0 TO %d]' % maxsize,
|
'year:(%s)' % year]
|
||||||
'-seeders:0'] # cut out dead torrents
|
else:
|
||||||
|
query_items = [usersearchterm]
|
||||||
|
|
||||||
|
query_items.extend(['format:(%s)' % format,
|
||||||
|
'size:[0 TO %d]' % maxsize,
|
||||||
|
'-seeders:0']) # cut out dead torrents
|
||||||
|
|
||||||
if bitrate:
|
if bitrate:
|
||||||
query_items.append('bitrate:"%s"' % bitrate)
|
query_items.append('bitrate:"%s"' % bitrate)
|
||||||
|
|
||||||
@@ -903,7 +917,7 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False):
|
|||||||
|
|
||||||
# Ignore if release date not specified, results too unpredictable
|
# Ignore if release date not specified, results too unpredictable
|
||||||
|
|
||||||
if not year:
|
if not year and not usersearchterm:
|
||||||
logger.info(u'Release date not specified, ignoring for rutracker.org')
|
logger.info(u'Release date not specified, ignoring for rutracker.org')
|
||||||
else:
|
else:
|
||||||
|
|
||||||
@@ -922,8 +936,12 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False):
|
|||||||
bitrate = True
|
bitrate = True
|
||||||
|
|
||||||
# build search url based on above
|
# build search url based on above
|
||||||
|
|
||||||
searchURL = rutracker.searchurl(artistterm, albumterm, year, format)
|
if not usersearchterm:
|
||||||
|
searchURL = rutracker.searchurl(artistterm, albumterm, year, format)
|
||||||
|
else:
|
||||||
|
searchURL = rutracker.searchurl(usersearchterm, ' ', ' ', format)
|
||||||
|
|
||||||
logger.info(u'Parsing results from <a href="%s">rutracker.org</a>' % searchURL)
|
logger.info(u'Parsing results from <a href="%s">rutracker.org</a>' % searchURL)
|
||||||
|
|
||||||
# parse results and get best match
|
# parse results and get best match
|
||||||
@@ -1234,17 +1252,19 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False):
|
|||||||
download_path = os.path.join(headphones.TORRENTBLACKHOLE_DIR, torrent_name)
|
download_path = os.path.join(headphones.TORRENTBLACKHOLE_DIR, torrent_name)
|
||||||
try:
|
try:
|
||||||
if bestqual[3] == 'rutracker.org':
|
if bestqual[3] == 'rutracker.org':
|
||||||
download_path = rutracker.get_torrent(bestqual[2], headphones.TORRENTBLACKHOLE_DIR)
|
download_path = rutracker.get_torrent(bestqual[2], headphones.TORRENTBLACKHOLE_DIR)
|
||||||
if not download_path:
|
if not download_path:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
#Write the torrent file to a path derived from the TORRENTBLACKHOLE_DIR and file name.
|
#Write the torrent file to a path derived from the TORRENTBLACKHOLE_DIR and file name.
|
||||||
torrent_file = open(download_path, 'wb')
|
prev = os.umask(headphones.UMASK)
|
||||||
torrent_file.write(data)
|
torrent_file = open(download_path, 'wb')
|
||||||
torrent_file.close()
|
torrent_file.write(data)
|
||||||
|
torrent_file.close()
|
||||||
#Open the fresh torrent file again so we can extract the proper torrent name
|
os.umask(prev)
|
||||||
#Used later in post-processing.
|
|
||||||
|
#Open the fresh torrent file again so we can extract the proper torrent name
|
||||||
|
#Used later in post-processing.
|
||||||
torrent_file = open(download_path, 'rb')
|
torrent_file = open(download_path, 'rb')
|
||||||
torrent_info = bencode.bdecode(torrent_file.read())
|
torrent_info = bencode.bdecode(torrent_file.read())
|
||||||
torrent_file.close()
|
torrent_file.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user