mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-19 10:05:30 +01:00
Fixed beets m4a album artist bug, redirect to artist page after adding, new folder naming option, fixed bug with folder names and forward slashes, have tracks update instantly on index page after processing, new filter for release groups
This commit is contained in:
@@ -48,7 +48,7 @@ def latinToAscii(unicrap):
|
||||
0xdd:'Y', 0xde:'th', 0xdf:'ss',
|
||||
0xe0:'a', 0xe1:'a', 0xe2:'a', 0xe3:'a', 0xe4:'a', 0xe5:'a',
|
||||
0xe6:'ae', 0xe7:'c',
|
||||
0xe8:'e', 0xe9:'e', 0xea:'e', 0xeb:'e',
|
||||
0xe8:'e', 0xe9:'e', 0xea:'e', 0xeb:'e', 0x0259:'e',
|
||||
0xec:'i', 0xed:'i', 0xee:'i', 0xef:'i',
|
||||
0xf0:'th', 0xf1:'n',
|
||||
0xf2:'o', 0xf3:'o', 0xf4:'o', 0xf5:'o', 0xf6:'o', 0xf8:'o',
|
||||
|
||||
@@ -182,7 +182,7 @@ def addArtisttoDB(artistid, extrasonly=False):
|
||||
try:
|
||||
release_dict = mb.getReleaseGroup(rgid)
|
||||
except Exception, e:
|
||||
logger.info('Unable to get release information for %s - it may not be a valid release group (or it might just not be tagged right in MusicBrainz)' % rg['title'])
|
||||
logger.info('Unable to get release information for %s - there may not be any official releases in this release group' % rg['title'])
|
||||
continue
|
||||
|
||||
if not release_dict:
|
||||
|
||||
@@ -157,7 +157,7 @@ def getArtist(artistid, extrasonly=False):
|
||||
|
||||
def getReleaseGroup(rgid):
|
||||
"""
|
||||
Returns the best release out of any given release group
|
||||
Returns a dictionary of the best stuff from a release group
|
||||
"""
|
||||
with mb_lock:
|
||||
|
||||
@@ -185,7 +185,7 @@ def getReleaseGroup(rgid):
|
||||
# to get more detailed release info (ASIN, track count, etc.)
|
||||
for release in releaseGroup.releases:
|
||||
|
||||
inc = ws.ReleaseIncludes(tracks=True, releaseEvents=True)
|
||||
inc = ws.ReleaseIncludes(tracks=True, releaseEvents=True)
|
||||
releaseResult = None
|
||||
attempt = 0
|
||||
|
||||
@@ -201,9 +201,13 @@ def getReleaseGroup(rgid):
|
||||
|
||||
if not releaseResult:
|
||||
continue
|
||||
|
||||
if releaseResult.title.lower() != releaseGroup.title.lower():
|
||||
continue
|
||||
|
||||
# Release filter for non-official live albums
|
||||
types = releaseResult.getTypes()
|
||||
if any('Live' in type for type in types):
|
||||
if not any('Official' in type for type in types):
|
||||
logger.debug('%s is not an official live album. Skipping' % releaseResult.name)
|
||||
continue
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
@@ -219,7 +223,7 @@ def getReleaseGroup(rgid):
|
||||
country = {
|
||||
'US': '0',
|
||||
'GB': '1',
|
||||
'JP': '1',
|
||||
'JP': '2',
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +235,7 @@ def getReleaseGroup(rgid):
|
||||
try:
|
||||
country = int(replace_all(releaseResult.releaseEvents[0].country, country))
|
||||
except:
|
||||
country = 2
|
||||
country = 3
|
||||
|
||||
release_dict = {
|
||||
'hasasin': bool(releaseResult.asin),
|
||||
@@ -260,8 +264,13 @@ def getReleaseGroup(rgid):
|
||||
release_dict['tracks'] = tracks
|
||||
|
||||
releaselist.append(release_dict)
|
||||
|
||||
a = multikeysort(releaselist, ['-hasasin', 'country', 'format', 'trackscount'])
|
||||
|
||||
average_tracks = sum(x['trackscount'] for x in releaselist) / len(releaselist)
|
||||
|
||||
for item in releaselist:
|
||||
item['trackscount_delta'] = abs(average_tracks - item['trackscount'])
|
||||
|
||||
a = multikeysort(releaselist, ['-hasasin', 'country', 'format', 'trackscount_delta'])
|
||||
|
||||
release_dict = {'releaseid' :a[0]['releaseid'],
|
||||
'releasedate' : releaselist[0]['releasedate'],
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import glob, os, shutil
|
||||
|
||||
import headphones
|
||||
|
||||
from headphones import logger
|
||||
|
||||
def moveFiles():
|
||||
for root, dirs, files in os.walk(headphones.DOWNLOAD_DIR):
|
||||
for file in files:
|
||||
if file[-4:].lower() == '.mp3' and os.path.isfile(file):
|
||||
print file
|
||||
shutil.copy2(os.path.join(root, file),
|
||||
os.path.join(path_to_itunes, file))
|
||||
@@ -114,6 +114,17 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list)
|
||||
albumpath = moveFiles(albumpath, release, tracks)
|
||||
|
||||
myDB = db.DBConnection()
|
||||
# There's gotta be a better way to update the have tracks - sqlite
|
||||
|
||||
trackcount = myDB.select('SELECT HaveTracks from artists WHERE ArtistID=?', [release['ArtistID']])
|
||||
|
||||
if not trackcount[0][0]:
|
||||
cur_track_count = 0
|
||||
else:
|
||||
cur_track_count = trackcount[0][0]
|
||||
|
||||
new_track_count = cur_track_count + len(downloaded_track_list)
|
||||
myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [new_track_count, release['ArtistID']])
|
||||
myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid])
|
||||
myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?', [albumid])
|
||||
updateHave(albumpath)
|
||||
@@ -158,10 +169,20 @@ def moveFiles(albumpath, release, tracks):
|
||||
year = release['ReleaseDate'][:4]
|
||||
except TypeError:
|
||||
year = ''
|
||||
|
||||
artist = release['ArtistName'].replace('/', '_')
|
||||
album = release['AlbumTitle'].replace('/', '_')
|
||||
|
||||
if artist[0].isdigit():
|
||||
firstchar = '0-9'
|
||||
else:
|
||||
firstchar = artist[0]
|
||||
|
||||
|
||||
values = { 'artist': release['ArtistName'],
|
||||
'album': release['AlbumTitle'],
|
||||
'year': year
|
||||
values = { 'artist': artist,
|
||||
'album': album,
|
||||
'year': year,
|
||||
'first': firstchar,
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +192,7 @@ def moveFiles(albumpath, release, tracks):
|
||||
if folder.endswith('.'):
|
||||
folder = folder.replace(folder[len(folder)-1], '_')
|
||||
|
||||
destination_path = os.path.join(headphones.DESTINATION_DIR, folder)
|
||||
destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, folder))
|
||||
|
||||
if os.path.exists(destination_path):
|
||||
i = 1
|
||||
@@ -183,8 +204,7 @@ def moveFiles(albumpath, release, tracks):
|
||||
destination_path = new_folder_name
|
||||
break
|
||||
|
||||
|
||||
logger.info('Moving files from %s to %s' % (folder, destination_path))
|
||||
logger.info('Moving files from %s to %s' % (albumpath, destination_path))
|
||||
|
||||
try:
|
||||
os.makedirs(destination_path)
|
||||
@@ -356,7 +376,10 @@ def forcePostProcess():
|
||||
else:
|
||||
logger.info('Querying MusicBrainz for the release group id for: %s - %s' % (name, album))
|
||||
from headphones import mb
|
||||
rgid = unicode(mb.findAlbumID(name, album))
|
||||
try:
|
||||
rgid = unicode(mb.findAlbumID(name, album))
|
||||
except:
|
||||
logger.error('Can not get release information for this album')
|
||||
if rgid:
|
||||
verify(rgid, albumpath)
|
||||
|
||||
|
||||
@@ -77,8 +77,8 @@ def searchNZB(albumid=None, new=False):
|
||||
cleanartistalbum = helpers.latinToAscii(helpers.replace_all(albums[0]+' '+albums[1], dic))
|
||||
|
||||
# FLAC usually doesn't have a year for some reason so I'll leave it out:
|
||||
term = re.sub('[\.\-]', ' ', '%s' % (cleanartistalbum)).encode('utf-8')
|
||||
altterm = re.sub('[\.\-]', ' ', '%s %s' % (cleanartistalbum, year)).encode('utf-8')
|
||||
term = re.sub('[\.\-\/]', ' ', '%s' % (cleanartistalbum)).encode('utf-8')
|
||||
altterm = re.sub('[\.\-\/]', ' ', '%s %s' % (cleanartistalbum, year)).encode('utf-8')
|
||||
|
||||
# Only use the year if the term could return a bunch of different albums, i.e. self-titled albums
|
||||
if albums[0] in albums[1] or len(albums[0]) < 4 or len(albums[1]) < 4:
|
||||
@@ -381,7 +381,7 @@ def searchNZB(albumid=None, new=False):
|
||||
data = urllib.urlopen(url, data=params).read()
|
||||
nzb = classes.NZBDataSearchResult()
|
||||
nzb.extraInfo.append(data)
|
||||
nzb_folder_name = '%s - %s [%s]' % (helpers.latinToAscii(albums[0]).encode('UTF-8'), helpers.latinToAscii(albums[1]).encode('UTF-8'), year)
|
||||
nzb_folder_name = '%s - %s [%s]' % (helpers.latinToAscii(albums[0]).encode('UTF-8').replace('/', '_'), helpers.latinToAscii(albums[1]).encode('UTF-8').replace('/', '_'), year)
|
||||
nzb.name = nzb_folder_name
|
||||
logger.info(u"Sending FILE to SABNZBD: " + nzb.name)
|
||||
sab.sendNZB(nzb)
|
||||
@@ -390,8 +390,8 @@ def searchNZB(albumid=None, new=False):
|
||||
myDB.action('INSERT INTO snatched VALUES( ?, ?, ?, ?, DATETIME("NOW", "localtime"), ?, ?)', [albums[2], bestqual[0], bestqual[1], bestqual[2], "Snatched", nzb_folder_name])
|
||||
else:
|
||||
downloadurl = bestqual[2]
|
||||
nzb_folder_name = '%s - %s [%s]' % (helpers.latinToAscii(albums[0]).encode('UTF-8'), helpers.latinToAscii(albums[1]).encode('UTF-8'), year)
|
||||
|
||||
nzb_folder_name = '%s - %s [%s]' % (helpers.latinToAscii(albums[0]).encode('UTF-8').replace('/', '_'), helpers.latinToAscii(albums[1]).encode('UTF-8').replace('/', '_'), year)
|
||||
|
||||
if headphones.SAB_HOST and not headphones.BLACKHOLE:
|
||||
linkparams = {}
|
||||
|
||||
|
||||
@@ -337,7 +337,8 @@ configform = form = '''
|
||||
|
||||
<p><b>Folder Format</b>:<br><input type="text" name="folder_format" value="%s" size="60">
|
||||
<br>
|
||||
<i class="smalltext">Use: artist, album and year, '/' for directories. <br />E.g.: artist/album [year]</i>
|
||||
<i class="smalltext">Use: artist, album, year and first (first letter in artist name)<br />
|
||||
E.g.: first/artist/album [year] = G/Girl Talk/All Day [2010]</i>
|
||||
</p>
|
||||
|
||||
<p><b>File Format</b>:<br><input type="text" name="file_format" value="%s" size="60">
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import os, sys
|
||||
import os
|
||||
|
||||
import cherrypy
|
||||
|
||||
import lib.musicbrainz2.webservice as ws
|
||||
import lib.musicbrainz2.model as m
|
||||
import lib.musicbrainz2.utils as u
|
||||
|
||||
import time
|
||||
import datetime
|
||||
import threading
|
||||
|
||||
import headphones
|
||||
@@ -101,10 +96,13 @@ class WebInterface(object):
|
||||
page.append(templates._nav)
|
||||
myDB = db.DBConnection()
|
||||
|
||||
artist = myDB.select('SELECT ArtistName, IncludeExtras from artists WHERE ArtistID=?', [ArtistID])
|
||||
|
||||
artist = myDB.select('SELECT ArtistName, IncludeExtras, Status from artists WHERE ArtistID=?', [ArtistID])
|
||||
while not artist:
|
||||
time.sleep(1)
|
||||
page.append('''<div class="table"><table><p align="center">%s</p>
|
||||
''' % artist[0][0])
|
||||
if artist[0][2] == 'Loading':
|
||||
page.append('<p align="center"><i>Loading...</i></p>')
|
||||
|
||||
if templates.displayAlbums(ArtistID, 'Album'):
|
||||
page.append(templates.displayAlbums(ArtistID, 'Album'))
|
||||
@@ -222,12 +220,12 @@ class WebInterface(object):
|
||||
|
||||
artistInfo.exposed = True
|
||||
|
||||
def addArtist(self, artistid, redirect='home'):
|
||||
def addArtist(self, artistid):
|
||||
|
||||
threading.Thread(target=importer.addArtisttoDB, args=[artistid]).start()
|
||||
time.sleep(5)
|
||||
threading.Thread(target=lastfm.getSimilar).start()
|
||||
raise cherrypy.HTTPRedirect(redirect)
|
||||
raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % artistid)
|
||||
|
||||
addArtist.exposed = True
|
||||
|
||||
@@ -693,7 +691,7 @@ class WebInterface(object):
|
||||
<div class="cloud">
|
||||
<ul id="cloud">''')
|
||||
for item in cloudlist:
|
||||
page.append('<li><a href="addArtist?artistid=%s&redirect=extras" class="tag%i">%s</a></li>' % (item['ArtistID'], item['Count'], item['ArtistName']))
|
||||
page.append('<li><a href="addArtist?artistid=%s" class="tag%i">%s</a></li>' % (item['ArtistID'], item['Count'], item['ArtistName']))
|
||||
page.append('</ul><br /><br /></div></div>')
|
||||
page.append(templates._footer % headphones.CURRENT_VERSION)
|
||||
return page
|
||||
|
||||
@@ -789,8 +789,7 @@ class MediaFile(object):
|
||||
)
|
||||
albumartist = MediaField(
|
||||
mp3 = StorageStyle('TPE2'),
|
||||
mp4 = StorageStyle(
|
||||
'----:com.apple.iTunes:Album Artist'),
|
||||
mp4 = StorageStyle('aART'),
|
||||
etc = [StorageStyle('album artist'),
|
||||
StorageStyle('albumartist')]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user