mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-22 12:49:26 +00:00
Merge branch 'develop'
This commit is contained in:
0
Headphones.py
Executable file → Normal file
0
Headphones.py
Executable file → Normal file
@@ -57,11 +57,11 @@
|
||||
"oLanguage": {
|
||||
"sLengthMenu":"Show _MENU_ results per page",
|
||||
"sEmptyTable": "No results",
|
||||
"sInfo":"Showing _TOTAL_ results",
|
||||
"sInfo":"Showing _START_ to _END_ of _TOTAL_ results",
|
||||
"sInfoEmpty":"Showing 0 to 0 of 0 results",
|
||||
"sInfoFiltered":"(filtered from _MAX_ total results)"},
|
||||
"bPaginate": false,
|
||||
"bFilter": false,
|
||||
"iDisplayLength": 25,
|
||||
"sPaginationType": "full_numbers",
|
||||
"aaSorting": []
|
||||
|
||||
});
|
||||
|
||||
0
headphones/__init__.py
Executable file → Normal file
0
headphones/__init__.py
Executable file → Normal file
@@ -161,12 +161,12 @@ def addArtisttoDB(artistid, extrasonly=False):
|
||||
"CleanName": cleanname
|
||||
}
|
||||
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone()
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone()
|
||||
|
||||
if not match:
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone()
|
||||
if not match:
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [artist['artist_name'], rg['title'], track['title']]).fetchone()
|
||||
if not match:
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone()
|
||||
if match:
|
||||
newValueDict['Location'] = match['Location']
|
||||
newValueDict['BitRate'] = match['BitRate']
|
||||
@@ -286,14 +286,14 @@ def addReleaseById(rid):
|
||||
"TrackNumber": track['number'],
|
||||
"CleanName": cleanname
|
||||
}
|
||||
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone()
|
||||
|
||||
if not match:
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone()
|
||||
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone()
|
||||
|
||||
if not match:
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [release_dict['artist_name'], release_dict['rg_title'], track['title']]).fetchone()
|
||||
|
||||
if not match:
|
||||
match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone()
|
||||
|
||||
if match:
|
||||
newValueDict['Location'] = match['Location']
|
||||
|
||||
@@ -8,6 +8,13 @@ from headphones import db, logger, helpers, importer
|
||||
|
||||
def libraryScan(dir=None):
|
||||
|
||||
# Clean up bad filepaths
|
||||
tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL')
|
||||
|
||||
for track in tracks:
|
||||
if not os.path.isfile(track['Location'].encode(headphones.SYS_ENCODING)):
|
||||
myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [None, track['TrackID']])
|
||||
|
||||
if not dir:
|
||||
dir = headphones.MUSIC_DIR
|
||||
|
||||
@@ -44,17 +51,6 @@ def libraryScan(dir=None):
|
||||
if f.bitrate:
|
||||
bitrates.append(f.bitrate)
|
||||
|
||||
# Try to match on metadata first, starting with the track id
|
||||
if f.mb_trackid:
|
||||
|
||||
# Wondering if theres a better way to do this -> do one thing if the row exists,
|
||||
# do something else if it doesn't
|
||||
track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone()
|
||||
|
||||
if track:
|
||||
myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']])
|
||||
continue
|
||||
|
||||
# Try to find a match based on artist/album/tracktitle
|
||||
if f.albumartist:
|
||||
f_artist = f.albumartist
|
||||
@@ -74,6 +70,17 @@ def libraryScan(dir=None):
|
||||
myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']])
|
||||
continue
|
||||
|
||||
# Try to match on mbid if available and we couldn't find a match based on metadata
|
||||
if f.mb_trackid:
|
||||
|
||||
# Wondering if theres a better way to do this -> do one thing if the row exists,
|
||||
# do something else if it doesn't
|
||||
track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone()
|
||||
|
||||
if track:
|
||||
myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']])
|
||||
continue
|
||||
|
||||
# if we can't find a match in the database on a track level, it might be a new artist or it might be on a non-mb release
|
||||
new_artists.append(f_artist)
|
||||
|
||||
@@ -162,14 +169,6 @@ def libraryScan(dir=None):
|
||||
continue
|
||||
|
||||
logger.info('Done checking empty filepaths')
|
||||
|
||||
# Clean up bad filepaths
|
||||
tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL')
|
||||
|
||||
for track in tracks:
|
||||
if not os.path.isfile(track['Location']):
|
||||
myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [None, track['TrackID']])
|
||||
|
||||
logger.info('Done syncing library with directory: %s' % dir)
|
||||
|
||||
# Clean up the new artist list
|
||||
|
||||
@@ -110,6 +110,8 @@ def verify(albumid, albumpath):
|
||||
release = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone()
|
||||
tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])
|
||||
|
||||
albumpath = albumpath.encode(headphones.SYS_ENCODING)
|
||||
|
||||
downloaded_track_list = []
|
||||
|
||||
for r,d,f in os.walk(albumpath):
|
||||
@@ -311,20 +313,20 @@ def moveFiles(albumpath, release, tracks):
|
||||
if folder.endswith('.'):
|
||||
folder = folder.replace(folder[len(folder)-1], '_')
|
||||
|
||||
destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, folder))
|
||||
destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, folder)).encode(headphones.SYS_ENCODING)
|
||||
|
||||
if os.path.exists(destination_path):
|
||||
i = 1
|
||||
while True:
|
||||
newfolder = folder + '[%i]' % i
|
||||
destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, newfolder))
|
||||
destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, newfolder)).encode(headphones.SYS_ENCODING)
|
||||
if os.path.exists(destination_path):
|
||||
i += 1
|
||||
else:
|
||||
folder = newfolder
|
||||
break
|
||||
|
||||
logger.info('Moving files from %s to %s' % (albumpath, destination_path))
|
||||
|
||||
logger.info('Moving files from %s to %s' % (unicode(albumpath, headphones.SYS_ENCODING, errors="replace"), unicode(destination_path, headphones.SYS_ENCODING, errors="replace")))
|
||||
|
||||
try:
|
||||
os.makedirs(destination_path)
|
||||
@@ -332,7 +334,7 @@ def moveFiles(albumpath, release, tracks):
|
||||
except Exception, e:
|
||||
logger.error('Could not create folder for %s. Not moving: %s' % (release['AlbumTitle'], e))
|
||||
return albumpath
|
||||
|
||||
|
||||
for r,d,f in os.walk(albumpath):
|
||||
for files in f:
|
||||
shutil.move(os.path.join(r, files), destination_path)
|
||||
@@ -342,7 +344,7 @@ def moveFiles(albumpath, release, tracks):
|
||||
|
||||
temp_f = headphones.DESTINATION_DIR
|
||||
for f in folder_list:
|
||||
temp_f = os.path.join(temp_f, f)
|
||||
temp_f = os.path.join(temp_f, f).encode(headphones.SYS_ENCODING)
|
||||
os.chmod(temp_f, int(headphones.FOLDER_PERMISSIONS, 8))
|
||||
|
||||
try:
|
||||
@@ -357,13 +359,17 @@ def correctMetadata(albumid, release, downloaded_track_list):
|
||||
logger.info('Writing metadata')
|
||||
items = []
|
||||
for downloaded_track in downloaded_track_list:
|
||||
|
||||
try:
|
||||
items.append(beets.library.Item.from_path(downloaded_track))
|
||||
except Exception, e:
|
||||
logger.error("Beets couldn't create an Item from: " + downloaded_track + " - not a media file?" + str(e))
|
||||
|
||||
cur_artist, cur_album, out_tuples, rec = autotag.tag_album(items, search_artist=release['ArtistName'], search_album=release['AlbumTitle'])
|
||||
|
||||
try:
|
||||
cur_artist, cur_album, out_tuples, rec = autotag.tag_album(items, search_artist=helpers.latinToAscii(release['ArtistName']), search_album=helpers.latinToAscii(release['AlbumTitle']))
|
||||
except Exception, e:
|
||||
logger.error('Error getting recommendation: %s. Not writing metadata' % e)
|
||||
return
|
||||
if rec == 'RECOMMEND_NONE':
|
||||
logger.warn('No accurate album match found for %s, %s - not writing metadata' % (release['ArtistName'], release['AlbumTitle']))
|
||||
return
|
||||
@@ -412,10 +418,10 @@ def renameFiles(albumpath, downloaded_track_list, release):
|
||||
|
||||
new_file_name = helpers.replace_all(headphones.FILE_FORMAT, values).replace('/','_') + ext
|
||||
|
||||
new_file_name = new_file_name.replace('?','_').replace(':', '_')
|
||||
new_file_name = new_file_name.replace('?','_').replace(':', '_').encode(headphones.SYS_ENCODING)
|
||||
|
||||
new_file = os.path.join(albumpath, new_file_name)
|
||||
|
||||
|
||||
logger.debug('Renaming %s ---> %s' % (downloaded_track, new_file_name))
|
||||
try:
|
||||
os.rename(downloaded_track, new_file)
|
||||
@@ -451,7 +457,7 @@ def updateHave(albumpath):
|
||||
else:
|
||||
continue
|
||||
|
||||
myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [song, f.bitrate, artist, f.album, f.title])
|
||||
myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [unicode(song, headphones.SYS_ENCODING, errors="replace"), f.bitrate, artist, f.album, f.title])
|
||||
|
||||
def renameUnprocessedFolder(albumpath):
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
HEADPHONES_VERSION = "master"
|
||||
HEADPHONES_VERSION = "develop"
|
||||
@@ -62,9 +62,9 @@ class WebInterface(object):
|
||||
if len(name) == 0:
|
||||
raise cherrypy.HTTPRedirect("home")
|
||||
if type == 'artist':
|
||||
searchresults = mb.findArtist(name, limit=20)
|
||||
searchresults = mb.findArtist(name, limit=100)
|
||||
else:
|
||||
searchresults = mb.findRelease(name, limit=20)
|
||||
searchresults = mb.findRelease(name, limit=100)
|
||||
return serve_template(templatename="searchresults.html", title='Search Results for: "' + name + '"', searchresults=searchresults, type=type)
|
||||
search.exposed = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user