mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01: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_UID = None
|
||||||
NZBSORG_HASH = None
|
NZBSORG_HASH = None
|
||||||
|
|
||||||
|
LASTFM_USERNAME = 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:
|
||||||
@@ -149,7 +151,7 @@ def initialize():
|
|||||||
ADD_ALBUM_ART, EMBED_ALBUM_ART, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, NZB_SEARCH_INTERVAL, \
|
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, \
|
LIBRARYSCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \
|
||||||
NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \
|
NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \
|
||||||
NZBSORG, NZBSORG_UID, NZBSORG_HASH
|
NZBSORG, NZBSORG_UID, NZBSORG_HASH, LASTFM_USERNAME
|
||||||
|
|
||||||
if __INITIALIZED__:
|
if __INITIALIZED__:
|
||||||
return False
|
return False
|
||||||
@@ -217,6 +219,8 @@ def initialize():
|
|||||||
NZBSORG = bool(check_setting_int(CFG, 'NZBsorg', 'nzbsorg', 0))
|
NZBSORG = bool(check_setting_int(CFG, 'NZBsorg', 'nzbsorg', 0))
|
||||||
NZBSORG_UID = check_setting_str(CFG, 'NZBsorg', 'nzbsorg_uid', '')
|
NZBSORG_UID = check_setting_str(CFG, 'NZBsorg', 'nzbsorg_uid', '')
|
||||||
NZBSORG_HASH = check_setting_str(CFG, 'NZBsorg', 'nzbsorg_hash', '')
|
NZBSORG_HASH = check_setting_str(CFG, 'NZBsorg', 'nzbsorg_hash', '')
|
||||||
|
|
||||||
|
LASTFM_USERNAME = check_setting_str(CFG, 'General', 'lastfm_username', '')
|
||||||
|
|
||||||
if not LOG_DIR:
|
if not LOG_DIR:
|
||||||
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
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_uid'] = NZBSORG_UID
|
||||||
new_config['NZBsorg']['nzbsorg_hash'] = NZBSORG_HASH
|
new_config['NZBsorg']['nzbsorg_hash'] = NZBSORG_HASH
|
||||||
|
|
||||||
|
new_config['General']['lastfm_username'] = LASTFM_USERNAME
|
||||||
|
|
||||||
new_config.write()
|
new_config.write()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ def artistlist_to_mbids(artistlist):
|
|||||||
newValueDict = {"HaveTracks": havetracks}
|
newValueDict = {"HaveTracks": havetracks}
|
||||||
myDB.upsert("artists", newValueDict, controlValueDict)
|
myDB.upsert("artists", newValueDict, controlValueDict)
|
||||||
|
|
||||||
# Update the cloud:
|
# Update the similar artist tag cloud:
|
||||||
logger.info('Updating artist information from Last.fm')
|
logger.info('Updating artist information from Last.fm')
|
||||||
try:
|
try:
|
||||||
lastfm.getSimilar()
|
lastfm.getSimilar()
|
||||||
|
|||||||
+45
-4
@@ -3,6 +3,7 @@ from xml.dom import minidom
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
import headphones
|
||||||
from headphones import db
|
from headphones import db
|
||||||
|
|
||||||
api_key = '395e6ec6bb557382fc41fde867bce66f'
|
api_key = '395e6ec6bb557382fc41fde867bce66f'
|
||||||
@@ -32,9 +33,12 @@ def getSimilar():
|
|||||||
for node in mbidnode:
|
for node in mbidnode:
|
||||||
artist_mbid = node.data
|
artist_mbid = node.data
|
||||||
|
|
||||||
if not any(artist_mbid in x for x in results):
|
try:
|
||||||
artistlist.append((artist_name, artist_mbid))
|
if not any(artist_mbid in x for x in results):
|
||||||
|
artistlist.append((artist_name, artist_mbid))
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
count = defaultdict(int)
|
count = defaultdict(int)
|
||||||
|
|
||||||
for artist, mbid in artistlist:
|
for artist, mbid in artistlist:
|
||||||
@@ -50,4 +54,41 @@ def getSimilar():
|
|||||||
for tuple in top_list:
|
for tuple in top_list:
|
||||||
artist_name, artist_mbid = tuple[0]
|
artist_name, artist_mbid = tuple[0]
|
||||||
count = tuple[1]
|
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 = os.path.join(headphones.DESTINATION_DIR, folder)
|
||||||
destination_path = destination_path.replace('?','_')
|
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))
|
logger.info('Moving files from %s to %s' % (folder, destination_path))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -206,7 +217,7 @@ def correctMetadata(albumid, release, downloaded_track_list):
|
|||||||
return
|
return
|
||||||
|
|
||||||
distance, items, info = out_tuples[0]
|
distance, items, info = out_tuples[0]
|
||||||
|
logger.debug('Beets recommendation: %s' % rec)
|
||||||
autotag.apply_metadata(items, info)
|
autotag.apply_metadata(items, info)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|||||||
+17
-11
@@ -370,14 +370,14 @@ class WebInterface(object):
|
|||||||
upcoming.exposed = True
|
upcoming.exposed = True
|
||||||
|
|
||||||
def manage(self):
|
def manage(self):
|
||||||
if headphones.PATH_TO_XML:
|
if headphones.LASTFM_USERNAME:
|
||||||
path = headphones.PATH_TO_XML
|
lastfm_user_text = headphones.LASTFM_USERNAME
|
||||||
else:
|
else:
|
||||||
path = 'Absolute path to iTunes XML or Top-Level Music Directory'
|
lastfm_user_text = 'Last.FM Username'
|
||||||
if headphones.MUSIC_DIR:
|
if headphones.MUSIC_DIR:
|
||||||
path2 = headphones.MUSIC_DIR
|
music_dir_text = headphones.MUSIC_DIR
|
||||||
else:
|
else:
|
||||||
path2 = 'Enter a directory to scan'
|
music_dir_text = 'Enter a directory to scan'
|
||||||
page = [templates._header]
|
page = [templates._header]
|
||||||
page.append(templates._logobar)
|
page.append(templates._logobar)
|
||||||
page.append(templates._nav)
|
page.append(templates._nav)
|
||||||
@@ -395,21 +395,27 @@ class WebInterface(object):
|
|||||||
<input type="text" value="%s" onfocus="if
|
<input type="text" value="%s" onfocus="if
|
||||||
(this.value==this.defaultValue) this.value='';" name="path" size="70" />
|
(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 or Sync Your iTunes Library/Music Folder</h1><br />
|
<div class="table"><div class="config"><h1>Import Your Last.FM Artists</h1><br />
|
||||||
This is here for legacy purposes (try the Music Scanner above!) <br /><br />
|
<form action="importLastFM" method="GET" align="center">
|
||||||
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">
|
|
||||||
<input type="text" value="%s" onfocus="if
|
<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>
|
<input type="submit" /></form><br /><br /></div></div>
|
||||||
<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>''' % (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)
|
page.append(templates._footer % headphones.CURRENT_VERSION)
|
||||||
return page
|
return page
|
||||||
manage.exposed = True
|
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):
|
def importItunes(self, path):
|
||||||
headphones.PATH_TO_XML = path
|
headphones.PATH_TO_XML = path
|
||||||
headphones.config_write()
|
headphones.config_write()
|
||||||
|
|||||||
Reference in New Issue
Block a user