mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
Fixed folder.jpg bug, added forced postprocessing
This commit is contained in:
@@ -66,6 +66,29 @@ h1{
|
|||||||
-moz-border-radius: 20px;
|
-moz-border-radius: 20px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
}
|
}
|
||||||
|
.tableleft{
|
||||||
|
padding: 3px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
float: left;
|
||||||
|
width: 46%;
|
||||||
|
height: 200px;
|
||||||
|
margin-top: 25px;
|
||||||
|
margin-left: 25px;
|
||||||
|
margin-right: auto;
|
||||||
|
-moz-border-radius: 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
.tableright{
|
||||||
|
padding: 3px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
width: 46%;
|
||||||
|
height: 200px;
|
||||||
|
margin-top: 25px;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: 0px;
|
||||||
|
-moz-border-radius: 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
.nav{
|
.nav{
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
font-size:19px;
|
font-size:19px;
|
||||||
|
|||||||
+13
-1
@@ -1,6 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
import headphones
|
import headphones
|
||||||
|
|
||||||
@@ -97,4 +98,15 @@ def bytes_to_mb(bytes):
|
|||||||
def replace_all(text, dic):
|
def replace_all(text, dic):
|
||||||
for i, j in dic.iteritems():
|
for i, j in dic.iteritems():
|
||||||
text = text.replace(i, j)
|
text = text.replace(i, j)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def extract_data(s):
|
||||||
|
pattern = re.compile(r'(?P<name>.*?)\s\-\s(?P<album>.*?)\s\[(?P<year>.*?)\]', re.VERBOSE)
|
||||||
|
|
||||||
|
match = pattern.match(s)
|
||||||
|
|
||||||
|
name = match.group("name")
|
||||||
|
album = match.group("album")
|
||||||
|
year = match.group("year")
|
||||||
|
|
||||||
|
return (name, album, year)
|
||||||
+26
-1
@@ -360,4 +360,29 @@ def findArtistbyAlbum(name):
|
|||||||
artist_dict['score'] = result.score
|
artist_dict['score'] = result.score
|
||||||
|
|
||||||
return artist_dict
|
return artist_dict
|
||||||
|
|
||||||
|
def findAlbumID(artist=None, album=None):
|
||||||
|
|
||||||
|
term = '"'+album+'" AND artist:"'+artist+'"'
|
||||||
|
|
||||||
|
f = ws.ReleaseGroupFilter(query=term, limit=1)
|
||||||
|
results = None
|
||||||
|
attempt = 0
|
||||||
|
|
||||||
|
while attempt < 5:
|
||||||
|
|
||||||
|
try:
|
||||||
|
results = q.getReleaseGroups(f)
|
||||||
|
break
|
||||||
|
except WebServiceError, e:
|
||||||
|
logger.warn('Attempt to query MusicBrainz for %s failed: %s. Sleeping 5 seconds.' % (name, e))
|
||||||
|
attempt += 1
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if not results:
|
||||||
|
return False
|
||||||
|
|
||||||
|
rgid = u.extractUuid(results[0].releaseGroup.id)
|
||||||
|
return rgid
|
||||||
@@ -127,8 +127,9 @@ def embedAlbumArt(artwork, downloaded_track_list):
|
|||||||
try:
|
try:
|
||||||
f = MediaFile(downloaded_track)
|
f = MediaFile(downloaded_track)
|
||||||
except:
|
except:
|
||||||
continue
|
logger.error('Could not read %s. Not adding album art' % downloaded_track)
|
||||||
|
|
||||||
|
logger.debug('Adding album art to: %s' % downloaded_track)
|
||||||
f.art = artwork
|
f.art = artwork
|
||||||
f.save()
|
f.save()
|
||||||
|
|
||||||
@@ -136,7 +137,7 @@ def addAlbumArt(artwork, albumpath):
|
|||||||
logger.info('Adding album art to folder')
|
logger.info('Adding album art to folder')
|
||||||
|
|
||||||
artwork_file_name = os.path.join(albumpath, 'folder.jpg')
|
artwork_file_name = os.path.join(albumpath, 'folder.jpg')
|
||||||
file = open(artwork_file_name, 'w')
|
file = open(artwork_file_name, 'wb')
|
||||||
file.write(artwork)
|
file.write(artwork)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
@@ -145,8 +146,12 @@ def cleanupFiles(albumpath):
|
|||||||
for r,d,f in os.walk(albumpath):
|
for r,d,f in os.walk(albumpath):
|
||||||
for files in f:
|
for files in f:
|
||||||
if not any(files.endswith(x) for x in (".mp3", ".flac", ".aac", ".ogg", ".ape", ".m4a")):
|
if not any(files.endswith(x) for x in (".mp3", ".flac", ".aac", ".ogg", ".ape", ".m4a")):
|
||||||
os.remove(os.path.join(r, files))
|
logger.debug('Removing: %s' % files)
|
||||||
|
try:
|
||||||
|
os.remove(os.path.join(r, files))
|
||||||
|
except Exception, e:
|
||||||
|
logger.error('Could not remove file: %s. Error: %s' % (files, e))
|
||||||
|
|
||||||
def moveFiles(albumpath, release, tracks):
|
def moveFiles(albumpath, release, tracks):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -253,6 +258,7 @@ def renameFiles(albumpath, downloaded_track_list, release):
|
|||||||
|
|
||||||
new_file = os.path.join(albumpath, new_file_name)
|
new_file = os.path.join(albumpath, new_file_name)
|
||||||
|
|
||||||
|
logger.debug('Renaming %s ---> %s' % (downloaded_track, new_file_name))
|
||||||
try:
|
try:
|
||||||
shutil.move(downloaded_track, new_file)
|
shutil.move(downloaded_track, new_file)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@@ -303,4 +309,42 @@ def renameUnprocessedFolder(albumpath):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
os.rename(albumpath, new_folder_name)
|
os.rename(albumpath, new_folder_name)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def forcePostProcess():
|
||||||
|
|
||||||
|
if not headphones.DOWNLOAD_DIR:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
download_dir = headphones.DOWNLOAD_DIR
|
||||||
|
|
||||||
|
logger.info('Checking to see if there are any folders to process in download_dir: %s' % download_dir)
|
||||||
|
# Get a list of folders in the download_dir
|
||||||
|
folders = [d for d in os.listdir(download_dir) if os.path.isdir(os.path.join(download_dir, d))]
|
||||||
|
|
||||||
|
if len(folders):
|
||||||
|
logger.info('Found %i folders: %s' % (len(folders), str(folders)))
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
logger.info('Found no folders to process in: %s' % download_dir)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Parse the folder names to get artist album info
|
||||||
|
for folder in folders:
|
||||||
|
|
||||||
|
albumpath = unicode(os.path.join(download_dir, folder))
|
||||||
|
name, album, year = helpers.extract_data(folder)
|
||||||
|
|
||||||
|
myDB = db.DBConnection()
|
||||||
|
release = myDB.action('SELECT AlbumID, ArtistName, AlbumTitle from albums WHERE ArtistName=? and AlbumTitle=?', [name, album]).fetchone()
|
||||||
|
if release:
|
||||||
|
logger.info('Found a match in the database: %s - %s. Verifying to make sure it is the correct album' % (release['ArtistName'], release['AlbumTitle']))
|
||||||
|
verify(release['AlbumID'], albumpath)
|
||||||
|
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))
|
||||||
|
if rgid:
|
||||||
|
verify(rgid, albumpath)
|
||||||
|
|
||||||
|
|
||||||
+21
-6
@@ -375,9 +375,10 @@ class WebInterface(object):
|
|||||||
else:
|
else:
|
||||||
lastfm_user_text = 'Last.FM Username'
|
lastfm_user_text = 'Last.FM Username'
|
||||||
if headphones.MUSIC_DIR:
|
if headphones.MUSIC_DIR:
|
||||||
music_dir_text = headphones.MUSIC_DIR
|
music_dir_input = '''<input type="text" value="%s" name="path" size="70" />''' % headphones.MUSIC_DIR
|
||||||
else:
|
else:
|
||||||
music_dir_text = 'Enter a directory to scan'
|
music_dir_input = '''<input type="text" value="Enter a Music Directory to scan" onfocus="if
|
||||||
|
(this.value==this.defaultValue) this.value='';" name="path" size="70" />'''
|
||||||
page = [templates._header]
|
page = [templates._header]
|
||||||
page.append(templates._logobar)
|
page.append(templates._logobar)
|
||||||
page.append(templates._nav)
|
page.append(templates._nav)
|
||||||
@@ -392,18 +393,25 @@ class WebInterface(object):
|
|||||||
<br /><br />
|
<br /><br />
|
||||||
|
|
||||||
<form action="musicScan" method="GET" align="center">
|
<form action="musicScan" method="GET" align="center">
|
||||||
<input type="text" value="%s" onfocus="if
|
%s
|
||||||
(this.value==this.defaultValue) this.value='';" name="path" size="70" />
|
|
||||||
<input type="submit" /></form><br /><br /></div></div>
|
<input type="submit" /></form><br /><br /></div></div>
|
||||||
<div class="table"><div class="config"><h1>Import Your Last.FM Artists</h1><br />
|
<div class="tableleft"><div class="config"><h1>Import Last.FM Artists</h1><br />
|
||||||
|
Enter the username whose artists you want to import:<br /><br />
|
||||||
<form action="importLastFM" method="GET" align="center">
|
<form action="importLastFM" method="GET" align="center">
|
||||||
<input type="text" value="%s" onfocus="if
|
<input type="text" value="%s" onfocus="if
|
||||||
(this.value==this.defaultValue) this.value='';" name="username" size="18" />
|
(this.value==this.defaultValue) this.value='';" name="username" size="18" />
|
||||||
<input type="submit" /></form><br /><br /></div></div>
|
<input type="submit" /></form><br /><br /></div></div>
|
||||||
|
<div class="tableright"><div class="config"><h1>Placeholder :-)</h1><br />
|
||||||
|
<br /><br />
|
||||||
|
<form action="" method="GET" align="center">
|
||||||
|
<input type="text" value="" onfocus="if
|
||||||
|
(this.value==this.defaultValue) this.value='';" name="" size="18" />
|
||||||
|
<input type="submit" /></form><br /><br /></div></div><br />
|
||||||
<div class="table"><div class="config"><h1>Force Search</h1><br />
|
<div class="table"><div class="config"><h1>Force Search</h1><br />
|
||||||
<a href="forceSearch">Force Check for Wanted Albums</a><br /><br />
|
<a href="forceSearch">Force Check for Wanted Albums</a><br /><br />
|
||||||
<a href="forceUpdate">Force Update Active Artists</a><br /><br />
|
<a href="forceUpdate">Force Update Active Artists</a><br /><br />
|
||||||
<a href="checkGithub">Check for Headphones Updates</a><br /><br /><br /></div></div>''' % (music_dir_text, lastfm_user_text))
|
<a href="forcePostProcess">Force Post-Process Albums in Download Folder</a><br /><br /><br />
|
||||||
|
<a href="checkGithub">Check for Headphones Updates</a><br /><br /><br /></div></div>''' % (music_dir_input, lastfm_user_text))
|
||||||
page.append(templates._footer % headphones.CURRENT_VERSION)
|
page.append(templates._footer % headphones.CURRENT_VERSION)
|
||||||
return page
|
return page
|
||||||
manage.exposed = True
|
manage.exposed = True
|
||||||
@@ -449,6 +457,13 @@ class WebInterface(object):
|
|||||||
raise cherrypy.HTTPRedirect("home")
|
raise cherrypy.HTTPRedirect("home")
|
||||||
forceSearch.exposed = True
|
forceSearch.exposed = True
|
||||||
|
|
||||||
|
def forcePostProcess(self):
|
||||||
|
from headphones import postprocessor
|
||||||
|
threading.Thread(target=postprocessor.forcePostProcess).start()
|
||||||
|
time.sleep(5)
|
||||||
|
raise cherrypy.HTTPRedirect("home")
|
||||||
|
forcePostProcess.exposed = True
|
||||||
|
|
||||||
def checkGithub(self):
|
def checkGithub(self):
|
||||||
from headphones import versioncheck
|
from headphones import versioncheck
|
||||||
versioncheck.checkGithub()
|
versioncheck.checkGithub()
|
||||||
|
|||||||
@@ -790,16 +790,14 @@ class MediaFile(object):
|
|||||||
albumartist = MediaField(
|
albumartist = MediaField(
|
||||||
mp3 = StorageStyle('TPE2'),
|
mp3 = StorageStyle('TPE2'),
|
||||||
mp4 = StorageStyle(
|
mp4 = StorageStyle(
|
||||||
'----:com.apple.iTunes:Album Artist',
|
'----:com.apple.iTunes:Album Artist'),
|
||||||
as_type=str),
|
|
||||||
etc = [StorageStyle('album artist'),
|
etc = [StorageStyle('album artist'),
|
||||||
StorageStyle('albumartist')]
|
StorageStyle('albumartist')]
|
||||||
)
|
)
|
||||||
albumtype = MediaField(
|
albumtype = MediaField(
|
||||||
mp3 = StorageStyle('TXXX', id3_desc=u'MusicBrainz Album Type'),
|
mp3 = StorageStyle('TXXX', id3_desc=u'MusicBrainz Album Type'),
|
||||||
mp4 = StorageStyle(
|
mp4 = StorageStyle(
|
||||||
'----:com.apple.iTunes:MusicBrainz Album Type',
|
'----:com.apple.iTunes:MusicBrainz Album Type'),
|
||||||
as_type=str),
|
|
||||||
etc = StorageStyle('musicbrainz_albumtype')
|
etc = StorageStyle('musicbrainz_albumtype')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user