mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-25 06:09:26 +00:00
Import Last.FM artists, post-processor folder bug fix
This commit is contained in:
@@ -92,6 +92,8 @@ NZBSORG = False
|
||||
NZBSORG_UID = None
|
||||
NZBSORG_HASH = None
|
||||
|
||||
LASTFM_USERNAME = None
|
||||
|
||||
def CheckSection(sec):
|
||||
""" Check if INI section exists, if not create it """
|
||||
try:
|
||||
@@ -149,7 +151,7 @@ def initialize():
|
||||
ADD_ALBUM_ART, EMBED_ALBUM_ART, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, NZB_SEARCH_INTERVAL, \
|
||||
LIBRARYSCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \
|
||||
NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \
|
||||
NZBSORG, NZBSORG_UID, NZBSORG_HASH
|
||||
NZBSORG, NZBSORG_UID, NZBSORG_HASH, LASTFM_USERNAME
|
||||
|
||||
if __INITIALIZED__:
|
||||
return False
|
||||
@@ -217,6 +219,8 @@ def initialize():
|
||||
NZBSORG = bool(check_setting_int(CFG, 'NZBsorg', 'nzbsorg', 0))
|
||||
NZBSORG_UID = check_setting_str(CFG, 'NZBsorg', 'nzbsorg_uid', '')
|
||||
NZBSORG_HASH = check_setting_str(CFG, 'NZBsorg', 'nzbsorg_hash', '')
|
||||
|
||||
LASTFM_USERNAME = check_setting_str(CFG, 'General', 'lastfm_username', '')
|
||||
|
||||
if not LOG_DIR:
|
||||
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
||||
@@ -376,6 +380,8 @@ def config_write():
|
||||
new_config['NZBsorg']['nzbsorg_uid'] = NZBSORG_UID
|
||||
new_config['NZBsorg']['nzbsorg_hash'] = NZBSORG_HASH
|
||||
|
||||
new_config['General']['lastfm_username'] = LASTFM_USERNAME
|
||||
|
||||
new_config.write()
|
||||
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ def artistlist_to_mbids(artistlist):
|
||||
newValueDict = {"HaveTracks": havetracks}
|
||||
myDB.upsert("artists", newValueDict, controlValueDict)
|
||||
|
||||
# Update the cloud:
|
||||
# Update the similar artist tag cloud:
|
||||
logger.info('Updating artist information from Last.fm')
|
||||
try:
|
||||
lastfm.getSimilar()
|
||||
|
||||
@@ -3,6 +3,7 @@ from xml.dom import minidom
|
||||
from collections import defaultdict
|
||||
import random
|
||||
|
||||
import headphones
|
||||
from headphones import db
|
||||
|
||||
api_key = '395e6ec6bb557382fc41fde867bce66f'
|
||||
@@ -32,9 +33,12 @@ def getSimilar():
|
||||
for node in mbidnode:
|
||||
artist_mbid = node.data
|
||||
|
||||
if not any(artist_mbid in x for x in results):
|
||||
artistlist.append((artist_name, artist_mbid))
|
||||
|
||||
try:
|
||||
if not any(artist_mbid in x for x in results):
|
||||
artistlist.append((artist_name, artist_mbid))
|
||||
except:
|
||||
continue
|
||||
|
||||
count = defaultdict(int)
|
||||
|
||||
for artist, mbid in artistlist:
|
||||
@@ -50,4 +54,41 @@ def getSimilar():
|
||||
for tuple in top_list:
|
||||
artist_name, artist_mbid = tuple[0]
|
||||
count = tuple[1]
|
||||
myDB.action('INSERT INTO lastfmcloud VALUES( ?, ?, ?)', [artist_name, artist_mbid, count])
|
||||
myDB.action('INSERT INTO lastfmcloud VALUES( ?, ?, ?)', [artist_name, artist_mbid, count])
|
||||
|
||||
def getArtists():
|
||||
|
||||
myDB = db.DBConnection()
|
||||
results = myDB.select('SELECT ArtistID from artists')
|
||||
|
||||
if not headphones.LASTFM_USERNAME:
|
||||
return
|
||||
|
||||
else:
|
||||
username = headphones.LASTFM_USERNAME
|
||||
|
||||
url = 'http://ws.audioscrobbler.com/2.0/?method=library.getartists&limit=10000&api_key=%s&user=%s' % (api_key, username)
|
||||
data = urllib.urlopen(url).read()
|
||||
d = minidom.parseString(data)
|
||||
artists = d.getElementsByTagName("artist")
|
||||
|
||||
artistlist = []
|
||||
|
||||
for artist in artists:
|
||||
mbidnode = artist.getElementsByTagName("mbid")[0].childNodes
|
||||
|
||||
for node in mbidnode:
|
||||
artist_mbid = node.data
|
||||
|
||||
try:
|
||||
if not any(artist_mbid in x for x in results):
|
||||
artistlist.append(artist_mbid)
|
||||
except:
|
||||
continue
|
||||
|
||||
from headphones import importer
|
||||
|
||||
for artistid in artistlist:
|
||||
importer.addArtisttoDB(artistid)
|
||||
|
||||
|
||||
@@ -165,6 +165,17 @@ def moveFiles(albumpath, release, tracks):
|
||||
destination_path = os.path.join(headphones.DESTINATION_DIR, folder)
|
||||
destination_path = destination_path.replace('?','_')
|
||||
|
||||
if os.path.exists(destination_path):
|
||||
i = 1
|
||||
while True:
|
||||
new_folder_name = destination_path + '[%i]' % i
|
||||
if os.path.exists(new_folder_name):
|
||||
i += 1
|
||||
else:
|
||||
destination_path = new_folder_name
|
||||
break
|
||||
|
||||
|
||||
logger.info('Moving files from %s to %s' % (folder, destination_path))
|
||||
|
||||
try:
|
||||
@@ -206,7 +217,7 @@ def correctMetadata(albumid, release, downloaded_track_list):
|
||||
return
|
||||
|
||||
distance, items, info = out_tuples[0]
|
||||
|
||||
logger.debug('Beets recommendation: %s' % rec)
|
||||
autotag.apply_metadata(items, info)
|
||||
|
||||
for item in items:
|
||||
|
||||
@@ -370,14 +370,14 @@ class WebInterface(object):
|
||||
upcoming.exposed = True
|
||||
|
||||
def manage(self):
|
||||
if headphones.PATH_TO_XML:
|
||||
path = headphones.PATH_TO_XML
|
||||
if headphones.LASTFM_USERNAME:
|
||||
lastfm_user_text = headphones.LASTFM_USERNAME
|
||||
else:
|
||||
path = 'Absolute path to iTunes XML or Top-Level Music Directory'
|
||||
lastfm_user_text = 'Last.FM Username'
|
||||
if headphones.MUSIC_DIR:
|
||||
path2 = headphones.MUSIC_DIR
|
||||
music_dir_text = headphones.MUSIC_DIR
|
||||
else:
|
||||
path2 = 'Enter a directory to scan'
|
||||
music_dir_text = 'Enter a directory to scan'
|
||||
page = [templates._header]
|
||||
page.append(templates._logobar)
|
||||
page.append(templates._nav)
|
||||
@@ -395,21 +395,27 @@ class WebInterface(object):
|
||||
<input type="text" value="%s" onfocus="if
|
||||
(this.value==this.defaultValue) this.value='';" name="path" size="70" />
|
||||
<input type="submit" /></form><br /><br /></div></div>
|
||||
<div class="table"><div class="config"><h1>Import or Sync Your iTunes Library/Music Folder</h1><br />
|
||||
This is here for legacy purposes (try the Music Scanner above!) <br /><br />
|
||||
If you'd rather import an iTunes .xml file, you can enter the full path here. <br /><br />
|
||||
<form action="importItunes" method="GET" align="center">
|
||||
<div class="table"><div class="config"><h1>Import Your Last.FM Artists</h1><br />
|
||||
<form action="importLastFM" method="GET" align="center">
|
||||
<input type="text" value="%s" onfocus="if
|
||||
(this.value==this.defaultValue) this.value='';" name="path" size="70" />
|
||||
(this.value==this.defaultValue) this.value='';" name="username" size="18" />
|
||||
<input type="submit" /></form><br /><br /></div></div>
|
||||
<div class="table"><div class="config"><h1>Force Search</h1><br />
|
||||
<a href="forceSearch">Force Check for Wanted Albums</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>''' % (path2, path))
|
||||
<a href="checkGithub">Check for Headphones Updates</a><br /><br /><br /></div></div>''' % (music_dir_text, lastfm_user_text))
|
||||
page.append(templates._footer % headphones.CURRENT_VERSION)
|
||||
return page
|
||||
manage.exposed = True
|
||||
|
||||
def importLastFM(self, username):
|
||||
headphones.LASTFM_USERNAME = username
|
||||
headphones.config_write()
|
||||
threading.Thread(target=lastfm.getArtists).start()
|
||||
time.sleep(10)
|
||||
raise cherrypy.HTTPRedirect("home")
|
||||
importLastFM.exposed = True
|
||||
|
||||
def importItunes(self, path):
|
||||
headphones.PATH_TO_XML = path
|
||||
headphones.config_write()
|
||||
|
||||
Reference in New Issue
Block a user