mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-21 12:19:27 +00:00
added itunes xml import
This commit is contained in:
@@ -15,7 +15,6 @@ import os
|
||||
|
||||
FULL_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
config_file = os.path.join(FULL_PATH, 'config.ini')
|
||||
db = os.path.join(FULL_PATH, 'headphones.db')
|
||||
|
||||
|
||||
if os.path.exists(config_file):
|
||||
@@ -77,7 +76,7 @@ def serverstart():
|
||||
|
||||
#Start threads
|
||||
threadtool(cherrypy.engine).subscribe()
|
||||
|
||||
cherrypy.engine.timeout_monitor.unsubscribe()
|
||||
cherrypy.quickstart(webServer.Headphones(), config = conf)
|
||||
|
||||
|
||||
|
||||
61
itunesimport.py
Normal file
61
itunesimport.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from pyItunes import *
|
||||
from configobj import ConfigObj
|
||||
import musicbrainz2.webservice as ws
|
||||
import musicbrainz2.model as m
|
||||
import musicbrainz2.utils as u
|
||||
import string
|
||||
import time
|
||||
import os
|
||||
import sqlite3
|
||||
from headphones import FULL_PATH
|
||||
|
||||
database = os.path.join(FULL_PATH, 'headphones.db')
|
||||
|
||||
|
||||
def itunesImport(pathtoxml):
|
||||
pl = XMLLibraryParser(pathtoxml)
|
||||
l = Library(pl.dictionary)
|
||||
lst = []
|
||||
for song in l.songs:
|
||||
lst.append(song.artist)
|
||||
rawlist = {}.fromkeys(lst).keys()
|
||||
artistlist = [f for f in rawlist if f != None]
|
||||
for name in artistlist:
|
||||
artistResults = ws.Query().getArtists(ws.ArtistFilter(string.replace(name, '&', '%38'), limit=1))
|
||||
for result in artistResults:
|
||||
artistid = u.extractUuid(result.artist.id)
|
||||
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), ratings=False, releaseGroups=False)
|
||||
artist = ws.Query().getArtistById(artistid, inc)
|
||||
conn=sqlite3.connect(database)
|
||||
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 tracks (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, AlbumID TEXT, TrackTitle TEXT, TrackDuration TEXT, TrackID TEXT)')
|
||||
c.execute('SELECT ArtistID from artists')
|
||||
artistlist = c.fetchall()
|
||||
if any(artistid in x for x in artistlist):
|
||||
pass
|
||||
else:
|
||||
c.execute('INSERT INTO artists VALUES( ?, ?, ?, CURRENT_DATE, ?)', (artistid, artist.name, artist.sortName, 'Active'))
|
||||
for release in artist.getReleases():
|
||||
releaseid = u.extractUuid(release.id)
|
||||
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
||||
results = ws.Query().getReleaseById(releaseid, inc)
|
||||
time.sleep(1)
|
||||
for event in results.releaseEvents:
|
||||
if event.country == 'US':
|
||||
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()
|
||||
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.close()
|
||||
else:
|
||||
pass
|
||||
|
||||
@@ -30,8 +30,9 @@ else:
|
||||
|
||||
def searchNZB(albumid=None):
|
||||
|
||||
conn=sqlite3.connect(database)
|
||||
c=conn.cursor()
|
||||
if os.path.exists(database):
|
||||
conn=sqlite3.connect(database)
|
||||
c=conn.cursor()
|
||||
|
||||
if albumid:
|
||||
c.execute('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" AND AlbumID="%s"' % albumid)
|
||||
|
||||
@@ -31,5 +31,7 @@ class threadtool(SimplePlugin):
|
||||
def run(self):
|
||||
import updater
|
||||
import searcher
|
||||
self.sched.add_cron_job(updater.dbUpdate, hour=3)
|
||||
self.sched.add_interval_job(searcher.searchNZB, hours=18)
|
||||
import mover
|
||||
#self.sched.add_cron_job(updater.dbUpdate, hour=3)
|
||||
#self.sched.add_interval_job(searcher.searchNZB, hours=18)
|
||||
#self.sched.add_interval_job(mover.moveFiles, minutes=10)
|
||||
|
||||
15
webServer.py
15
webServer.py
@@ -286,10 +286,25 @@ class Headphones:
|
||||
page = [templates._header]
|
||||
page.append(templates._logobar)
|
||||
page.append(templates._nav)
|
||||
page.append('''<div class="table"><div class="config"><h1>Import or Sync Your iTunes Library</h1><br />
|
||||
Enter the full path to your iTunes XML file.
|
||||
i.e. /Users/"username"/Music/iTunes/iTunes Music Library.xml<br />
|
||||
note: This process can take a LONG time!<br /><br /><br />
|
||||
<form action="importItunes" method="GET" align="center">
|
||||
<input type="text" value="Absolute Path to Itunes XML" onfocus="if
|
||||
(this.value==this.defaultValue) this.value='';" name="path" size="70" />
|
||||
<input type="submit" /></form><br /><br /><br /></div></div>''')
|
||||
page.append(templates._footer)
|
||||
return page
|
||||
manage.exposed = True
|
||||
|
||||
def importItunes(self, path):
|
||||
import itunesimport
|
||||
itunesimport.itunesImport(path)
|
||||
raise cherrypy.HTTPRedirect("/")
|
||||
importItunes.exposed = True
|
||||
|
||||
|
||||
def history(self):
|
||||
page = [templates._header]
|
||||
page.append(templates._logobar)
|
||||
|
||||
Reference in New Issue
Block a user