mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
Fixed duplicates/US only issue. Also added latest albums to index page
This commit is contained in:
+27
-32
@@ -2,6 +2,7 @@ from webServer import database
|
||||
import musicbrainz2.webservice as ws
|
||||
import musicbrainz2.model as m
|
||||
import musicbrainz2.utils as u
|
||||
from mb import getReleaseGroup
|
||||
import sqlite3
|
||||
import time
|
||||
|
||||
@@ -26,53 +27,47 @@ def dbUpdate():
|
||||
c.execute('SELECT AlbumID from albums WHERE ArtistID="%s"' % artistid)
|
||||
albumlist = c.fetchall()
|
||||
|
||||
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), ratings=False, releaseGroups=False)
|
||||
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), releaseGroups=True)
|
||||
artist = ws.Query().getArtistById(artistid, inc)
|
||||
|
||||
for release in artist.getReleases():
|
||||
for rg in artist.getReleaseGroups():
|
||||
|
||||
releaseid = u.extractUuid(release.id)
|
||||
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)
|
||||
time.sleep(2)
|
||||
|
||||
for event in results.releaseEvents:
|
||||
|
||||
if event.country == 'US':
|
||||
if any(releaseid in x for x in albumlist):
|
||||
|
||||
if any(releaseid in x for x in albumlist):
|
||||
|
||||
logger.log(results.title + " already exists in the database. Updating ASIN, Release Date, Tracks")
|
||||
logger.log(results.title + " already exists in the database. Updating ASIN, Release Date, Tracks")
|
||||
|
||||
c.execute('UPDATE albums SET AlbumASIN="%s", ReleaseDate="%s" WHERE AlbumID="%s"' % (results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id)))
|
||||
c.execute('UPDATE albums SET AlbumASIN="%s", ReleaseDate="%s" WHERE AlbumID="%s"' % (results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id)))
|
||||
|
||||
for track in results.tracks:
|
||||
c.execute('UPDATE tracks SET TrackDuration="%s" WHERE AlbumID="%s" AND TrackID="%s"' % (track.duration, u.extractUuid(results.id), u.extractUuid(track.id)))
|
||||
conn.commit()
|
||||
for track in results.tracks:
|
||||
c.execute('UPDATE tracks SET TrackDuration="%s" WHERE AlbumID="%s" AND TrackID="%s"' % (track.duration, u.extractUuid(results.id), u.extractUuid(track.id)))
|
||||
conn.commit()
|
||||
|
||||
else:
|
||||
else:
|
||||
|
||||
logger.log(u"New album found! Adding "+results.title+"to the database...")
|
||||
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
||||
conn.commit()
|
||||
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||
|
||||
logger.log(u"New album found! Adding "+results.title+"to the database...")
|
||||
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
||||
conn.commit()
|
||||
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||
latestrelease = c.fetchall()
|
||||
|
||||
latestrelease = c.fetchall()
|
||||
|
||||
if latestrelease[0][0] > latestrelease[0][1]:
|
||||
if latestrelease[0][0] > latestrelease[0][1]:
|
||||
|
||||
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
for track in results.tracks:
|
||||
|
||||
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
||||
conn.commit()
|
||||
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||
|
||||
else:
|
||||
logger.log(results.title + " is not a US release. Skipping it for now")
|
||||
pass
|
||||
|
||||
for track in results.tracks:
|
||||
|
||||
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
||||
conn.commit()
|
||||
time.sleep(1)
|
||||
i += 1
|
||||
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user