mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-11 06:09:29 +01:00
Added Remixes, Compilations, EPs, Live Albums and Singles!
This commit is contained in:
@@ -99,9 +99,18 @@ h1{
|
||||
font-size: 16px;
|
||||
margin-left: 100px;
|
||||
}
|
||||
.mediumcentered{
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
.bluecenter{
|
||||
color: #0000FF;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
}
|
||||
.logtext{
|
||||
font-size: 14px;
|
||||
padding: 4px
|
||||
white-space: normal;
|
||||
}
|
||||
.bigtext{
|
||||
font-size: 22px;
|
||||
|
||||
@@ -385,12 +385,22 @@ def dbcheck():
|
||||
|
||||
conn=sqlite3.connect(DB_FILE)
|
||||
c=conn.cursor()
|
||||
c.execute('CREATE TABLE IF NOT EXISTS artists (ArtistID TEXT UNIQUE, ArtistName TEXT, ArtistSortName TEXT, DateAdded TEXT, Status TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS albums (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS artists (ArtistID TEXT UNIQUE, ArtistName TEXT, ArtistSortName TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS albums (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status TEXT, Type TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS tracks (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, AlbumID TEXT, TrackTitle TEXT, TrackDuration, TrackID TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS snatched (AlbumID TEXT, Title TEXT, Size INTEGER, URL TEXT, DateAdded TEXT, Status TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS extras (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS have (ArtistName TEXT, AlbumTitle TEXT, TrackNumber TEXT, TrackTitle TEXT, TrackLength TEXT, BitRate TEXT, Genre TEXT, Date TEXT, TrackID TEXT)')
|
||||
|
||||
try:
|
||||
c.execute('SELECT IncludeExtras from artists')
|
||||
except sqlite3.OperationalError:
|
||||
c.execute('ALTER TABLE artists ADD COLUMN IncludeExtras INTEGER DEFAULT 0')
|
||||
|
||||
try:
|
||||
c.execute('SELECT Type from albums')
|
||||
except sqlite3.OperationalError:
|
||||
c.execute('ALTER TABLE albums ADD COLUMN Type TEXT DEFAULT "Album"')
|
||||
|
||||
conn.commit()
|
||||
c.close()
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ def artistlist_to_mbids(artistlist):
|
||||
addArtisttoDB(artistid)
|
||||
|
||||
|
||||
def addArtisttoDB(artistid):
|
||||
def addArtisttoDB(artistid, extrasonly=False):
|
||||
|
||||
# Can't add various artists - throws an error from MB
|
||||
if artistid == various_artists_mbid:
|
||||
@@ -130,7 +130,7 @@ def addArtisttoDB(artistid):
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
artist = mb.getArtist(artistid)
|
||||
artist = mb.getArtist(artistid, extrasonly)
|
||||
|
||||
if not artist:
|
||||
return
|
||||
@@ -189,6 +189,7 @@ def addArtisttoDB(artistid):
|
||||
"AlbumASIN": release['asin'],
|
||||
"ReleaseDate": release_dict['releasedate'],
|
||||
"DateAdded": helpers.today(),
|
||||
"Type": rg['type']
|
||||
}
|
||||
|
||||
if release['date'] > helpers.today():
|
||||
@@ -218,4 +219,5 @@ def addArtisttoDB(artistid):
|
||||
controlValueDict = {"ArtistID": artistid}
|
||||
newValueDict = {"Status": "Active"}
|
||||
|
||||
myDB.upsert("artists", newValueDict, controlValueDict)
|
||||
myDB.upsert("artists", newValueDict, controlValueDict)
|
||||
logger.info(u"Updating complete for: " + artist['artist_name'])
|
||||
@@ -66,7 +66,7 @@ def findArtist(name, limit=1):
|
||||
|
||||
return artistlist
|
||||
|
||||
def getArtist(artistid):
|
||||
def getArtist(artistid, extrasonly=False):
|
||||
|
||||
with mb_lock:
|
||||
|
||||
@@ -101,14 +101,54 @@ def getArtist(artistid):
|
||||
|
||||
releasegroups = []
|
||||
|
||||
for rg in artist.getReleaseGroups():
|
||||
if not extrasonly:
|
||||
|
||||
for rg in artist.getReleaseGroups():
|
||||
|
||||
releasegroups.append({
|
||||
'title': rg.title,
|
||||
'id': u.extractUuid(rg.id),
|
||||
'url': rg.id,
|
||||
'type': u.getReleaseTypeName(rg.type)
|
||||
})
|
||||
|
||||
# See if we need to grab extras
|
||||
myDB = db.DBConnection()
|
||||
|
||||
try:
|
||||
includeExtras = myDB.select('SELECT IncludeExtras from artists WHERE ArtistID=?', [artistid])[0][0]
|
||||
except IndexError:
|
||||
includeExtras = False
|
||||
|
||||
if includeExtras:
|
||||
includes = [m.Release.TYPE_COMPILATION, m.Release.TYPE_REMIX, m.Release.TYPE_SINGLE, m.Release.TYPE_LIVE, m.Release.TYPE_EP]
|
||||
for include in includes:
|
||||
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, include), releaseGroups=True)
|
||||
|
||||
artist = None
|
||||
attempt = 0
|
||||
|
||||
releasegroups.append({
|
||||
'title': rg.title,
|
||||
'id': u.extractUuid(rg.id),
|
||||
'url': rg.id,
|
||||
'type': u.getReleaseTypeName(rg.type)
|
||||
})
|
||||
while attempt < 5:
|
||||
|
||||
try:
|
||||
artist = q.getArtistById(artistid, inc)
|
||||
break
|
||||
except WebServiceError, e:
|
||||
logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s. Sleeping 10 seconds' % artistid)
|
||||
attempt += 1
|
||||
time.sleep(5)
|
||||
|
||||
if not artist:
|
||||
continue
|
||||
|
||||
for rg in artist.getReleaseGroups():
|
||||
|
||||
releasegroups.append({
|
||||
'title': rg.title,
|
||||
'id': u.extractUuid(rg.id),
|
||||
'url': rg.id,
|
||||
'type': u.getReleaseTypeName(rg.type)
|
||||
})
|
||||
|
||||
artist_dict['releasegroups'] = releasegroups
|
||||
|
||||
@@ -266,25 +306,4 @@ def findArtistbyAlbum(name):
|
||||
artist_dict['score'] = result.score
|
||||
|
||||
return artist_dict
|
||||
|
||||
def getExtras(artistid):
|
||||
|
||||
types = [m.Release.TYPE_EP, m.Release.TYPE_SINGLE, m.Release.TYPE_LIVE, m.Release.TYPE_REMIX,
|
||||
m.Release.TYPE_COMPILATION]
|
||||
|
||||
for type in types:
|
||||
|
||||
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, type), releaseGroups=True)
|
||||
artist = q.getArtistById(artistid, inc)
|
||||
|
||||
for rg in artist.getReleaseGroups():
|
||||
|
||||
rgid = u.extractUuid(rg.id)
|
||||
releaseid = getReleaseGroup(rgid)
|
||||
|
||||
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
||||
results = ws.Query().getReleaseById(releaseid, inc)
|
||||
|
||||
print results.title
|
||||
print u.getReleaseTypeName(results.releaseGroup.type)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from headphones import db
|
||||
|
||||
_header = '''
|
||||
<html>
|
||||
<head>
|
||||
@@ -16,13 +18,13 @@ _shutdownheader = '''
|
||||
<link rel="stylesheet" type="text/css" href="css/style.css" />
|
||||
<link rel="icon" type="image/x-icon" href="images/favicon.ico" />
|
||||
<link rel="apple-touch-icon" href="images/headphoneslogo.png" />
|
||||
<meta http-equiv="refresh" content="%s;url=index"></head>
|
||||
<meta http-equiv="refresh" content="%s;url=index">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">'''
|
||||
|
||||
_logobar = '''
|
||||
<div class="logo"><a href="home"><img src="images/headphoneslogo.png" border="0">headphones<a></div>
|
||||
<div class="logo"><a href="home"><img src="images/headphoneslogo.png" border="0">headphones</a></div>
|
||||
<div class="search"><form action="findArtist" method="GET">
|
||||
<input type="text" value="Add an artist" onfocus="if
|
||||
(this.value==this.defaultValue) this.value='';" name="name" />
|
||||
@@ -301,4 +303,63 @@ configform = form = '''
|
||||
(Web Interface changes require a restart to take effect)</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>'''
|
||||
</div>'''
|
||||
|
||||
|
||||
def displayAlbums(ArtistID, Type=None):
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
results = myDB.select('SELECT AlbumTitle, ReleaseDate, AlbumID, Status, ArtistName, AlbumASIN from albums WHERE ArtistID=? AND Type=? order by ReleaseDate DESC', [ArtistID, Type])
|
||||
|
||||
if not len(results):
|
||||
return
|
||||
|
||||
typeheadings = {'Album' : 'Official Albums',
|
||||
'Compilation': 'Compilations',
|
||||
'EP': 'EPs',
|
||||
'Live': 'Live Albums',
|
||||
'Remix': 'Remixes',
|
||||
'Single': 'Singles'}
|
||||
|
||||
page = ['''<p class="mediumcentered">%s</p>
|
||||
<table border="0" cellpadding="3">
|
||||
<tr>
|
||||
<th align="left" width="30"></th>
|
||||
<th align="left" width="120">Album Name</th>
|
||||
<th align="center" width="100">Release Date</th>
|
||||
<th align="center" width="180">Status</th>
|
||||
<th align="center">Have</th>
|
||||
</tr>''' % typeheadings[Type]]
|
||||
i = 0
|
||||
while i < len(results):
|
||||
totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE AlbumID=?', [results[i][2]]))
|
||||
havetracks = len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ? AND AlbumTitle like ?', [results[i][4], results[i][0]]))
|
||||
try:
|
||||
percent = (havetracks*100)/totaltracks
|
||||
if percent > 100:
|
||||
percent = 100
|
||||
except ZeroDivisionError:
|
||||
percent = 100
|
||||
if results[i][3] == 'Skipped':
|
||||
newStatus = '''%s [<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">want</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Wanted':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="unqueueAlbum?AlbumID=%s&ArtistID=%s">skip</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Downloaded':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Snatched':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>][<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s&new=True">new</a>]''' % (results[i][3], results[i][2], ArtistID, results[i][2], ArtistID)
|
||||
else:
|
||||
newStatus = '%s' % (results[i][3])
|
||||
page.append('''<tr>
|
||||
<td align="left"><img src="http://ec1.images-amazon.com/images/P/%s.01.MZZZZZZZ.jpg" height="50" width="50"></td>
|
||||
<td align="left" width="240"><a href="albumPage?AlbumID=%s">%s</a>
|
||||
(<A class="external" href="http://musicbrainz.org/release-group/%s.html">link</a>)</td>
|
||||
<td align="center" width="160">%s</td>
|
||||
<td align="center">%s</td>
|
||||
<td><div class="progress-container"><div style="width: %s%%"><div class="smalltext3">%s/%s</div></div></div></td>
|
||||
</tr>''' % (results[i][5], results[i][2], results[i][0], results[i][2], results[i][1], newStatus, percent, havetracks, totaltracks))
|
||||
i = i+1
|
||||
page.append('</table><br />')
|
||||
|
||||
return ''.join(page)
|
||||
@@ -97,47 +97,25 @@ class WebInterface(object):
|
||||
page.append(templates._nav)
|
||||
myDB = db.DBConnection()
|
||||
|
||||
artist = myDB.select('SELECT ArtistName from artists WHERE ArtistID=?', [ArtistID])
|
||||
results = myDB.select('SELECT AlbumTitle, ReleaseDate, AlbumID, Status, ArtistName, AlbumASIN from albums WHERE ArtistID=? order by ReleaseDate DESC', [ArtistID])
|
||||
artist = myDB.select('SELECT ArtistName, IncludeExtras from artists WHERE ArtistID=?', [ArtistID])
|
||||
|
||||
i = 0
|
||||
page.append('''<div class="table"><table border="0" cellpadding="3">
|
||||
<tr><p align="center">%s <br /></p></tr>
|
||||
<tr>
|
||||
<th align="left" width="30"></th>
|
||||
<th align="left" width="120">Album Name</th>
|
||||
<th align="center" width="100">Release Date</th>
|
||||
<th align="center" width="180">Status</th>
|
||||
<th align="center">Have</th>
|
||||
</tr>''' % artist[0][0])
|
||||
while i < len(results):
|
||||
totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE AlbumID=?', [results[i][2]]))
|
||||
havetracks = len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ? AND AlbumTitle like ?', [results[i][4], results[i][0]]))
|
||||
try:
|
||||
percent = (havetracks*100)/totaltracks
|
||||
if percent > 100:
|
||||
percent = 100
|
||||
except ZeroDivisionError:
|
||||
percent = 100
|
||||
if results[i][3] == 'Skipped':
|
||||
newStatus = '''%s [<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">want</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Wanted':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="unqueueAlbum?AlbumID=%s&ArtistID=%s">skip</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Downloaded':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Snatched':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>][<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s&new=True">new</a>]''' % (results[i][3], results[i][2], ArtistID, results[i][2], ArtistID)
|
||||
else:
|
||||
newStatus = '%s' % (results[i][3])
|
||||
page.append('''<tr><td align="left"><img src="http://ec1.images-amazon.com/images/P/%s.01.MZZZZZZZ.jpg" height="50" width="50"></td>
|
||||
<td align="left" width="240"><a href="albumPage?AlbumID=%s">%s</a>
|
||||
(<A class="external" href="http://musicbrainz.org/release-group/%s.html">link</a>)</td>
|
||||
<td align="center" width="160">%s</td>
|
||||
<td align="center">%s</td>
|
||||
<td><div class="progress-container"><div style="width: %s%%"><div class="smalltext3">%s/%s</div></div></div></td></tr>''' % (results[i][5], results[i][2], results[i][0], results[i][2], results[i][1], newStatus, percent, havetracks, totaltracks))
|
||||
i = i+1
|
||||
page.append('''<div class="table"><table><p align="center">%s</p>
|
||||
''' % artist[0][0])
|
||||
|
||||
page.append(templates.displayAlbums(ArtistID, 'Album'))
|
||||
|
||||
releasetypes = ['Compilation', 'EP', 'Single', 'Live', 'Remix']
|
||||
|
||||
for type in releasetypes:
|
||||
if templates.displayAlbums(ArtistID, type):
|
||||
page.append(templates.displayAlbums(ArtistID, type))
|
||||
|
||||
page.append('</table>')
|
||||
|
||||
if not artist[0][1]:
|
||||
page.append('''<br /><div class="bluecenter"><a href="getExtras?ArtistID=%s">Get Extras for %s!</a></div>'''
|
||||
% (ArtistID, artist[0][0]))
|
||||
|
||||
page.append('''</table></div>''')
|
||||
page.append(templates._footer % headphones.CURRENT_VERSION)
|
||||
return page
|
||||
artistPage.exposed = True
|
||||
@@ -247,6 +225,19 @@ class WebInterface(object):
|
||||
|
||||
addArtist.exposed = True
|
||||
|
||||
def getExtras(self, ArtistID):
|
||||
|
||||
myDB = db.DBConnection()
|
||||
controlValueDict = {'ArtistID': ArtistID}
|
||||
newValueDict = {'IncludeExtras': 1}
|
||||
myDB.upsert("artists", newValueDict, controlValueDict)
|
||||
|
||||
threading.Thread(target=importer.addArtisttoDB, args=[ArtistID, True]).start()
|
||||
time.sleep(10)
|
||||
raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID)
|
||||
|
||||
getExtras.exposed = True
|
||||
|
||||
def pauseArtist(self, ArtistID):
|
||||
|
||||
logger.info(u"Pausing artist: " + ArtistID)
|
||||
|
||||
Reference in New Issue
Block a user