diff --git a/headphones.py b/headphones.py
index 0dc8a3c6..64d2ab32 100755
--- a/headphones.py
+++ b/headphones.py
@@ -106,8 +106,9 @@ def serverstart():
cherrypy.engine.subscribe('start', browser, priority=90)
logger.log(u"Starting Headphones on port:" + settings['http_port'])
- cherrypy.quickstart(webServer.Headphones(), config = conf)
-
+ root = webServer.Headphones("data/interfaces/default/")
+ cherrypy.quickstart(root, config = conf)
+
if __name__ == '__main__':
serverstart()
diff --git a/webServer.py b/webServer.py
index c75ff37d..5efab693 100644
--- a/webServer.py
+++ b/webServer.py
@@ -13,15 +13,22 @@ import sys
import configobj
from headphones import FULL_PATH, config_file
import logger
+from Cheetah.Template import Template
database = os.path.join(FULL_PATH, 'headphones.db')
class Headphones:
+
+ def __init__(self,templatePath):
+ """docstring for __init__"""
+ self.templatePath = templatePath
def index(self):
- page = [templates._header]
- page.append(templates._logobar)
- page.append(templates._nav)
+
+ filename = os.path.join(self.templatePath,"index.tmpl")
+ template = Template(file=filename)
+ template.rootPath = "."
+ template.appPath = "."
#Display Database if it exists:
if os.path.exists(database):
#logger.log(u"Loading artists from the database...")
@@ -30,129 +37,71 @@ class Headphones:
c.execute('SELECT ArtistName, ArtistID, Status from artists order by ArtistSortName collate nocase')
results = c.fetchall()
i = 0
- page.append('''
-
- | Artist Name |
- Status |
- Upcoming Albums |
- |
-
''')
+ template.artists = []
while i < len(results):
c.execute('''SELECT AlbumTitle, ReleaseDate, DateAdded, AlbumID from albums WHERE ArtistID='%s' order by ReleaseDate DESC''' % results[i][1])
latestalbum = c.fetchall()
today = datetime.date.today()
- if len(latestalbum) > 0:
- if latestalbum[0][1] > datetime.date.isoformat(today):
- newalbumName = '%s' % (latestalbum[0][3], latestalbum[0][0])
- releaseDate = '(%s)' % latestalbum[0][1]
- else:
- newalbumName = 'None'
- releaseDate = ""
if len(latestalbum) == 0:
- newalbumName = 'None'
- releaseDate = ""
- if results[i][2] == 'Paused':
- newStatus = '''%s(resume)''' % (results[i][2], results[i][1])
- else:
- newStatus = '''%s(pause)''' % (results[i][2], results[i][1])
- page.append('''| %s
- (link) [delete] |
- %s |
- %s %s |
''' % (results[i][1], results[i][0], results[i][1], results[i][1], newStatus, newalbumName, releaseDate))
+ results[i][3] = 'None'
+ results[i][4] = ""
+ elif latestalbum[0][1] > datetime.date.isoformat(today):
+ results[i][3] = '%s' % (latestalbum[0][3], latestalbum[0][0])
+ results[i][4] = '(%s)' % latestalbum[0][1]
+
+ template.artists.append(results[i])
i = i+1
c.close()
- page.append('''
''')
-
- else:
- page.append("""Add some artists to the database!
""")
- page.append(templates._footer)
- return page
+ return str(template)
index.exposed = True
-
def artistPage(self, ArtistID):
- page = [templates._header]
- page.append(templates._logobar)
- page.append(templates._nav)
+ filename = os.path.join(self.templatePath,"artistPage.tmpl")
+ template = Template(file=filename)
+ template.rootPath = "."
+ template.appPath = "."
+ template.artistID = ArtistID
conn=sqlite3.connect(database)
c=conn.cursor()
c.execute('''SELECT ArtistName from artists WHERE ArtistID="%s"''' % ArtistID)
artistname = c.fetchall()
+ template.artistName = artistname[0]
c.execute('''SELECT AlbumTitle, ReleaseDate, AlbumID, Status, ArtistName, AlbumASIN from albums WHERE ArtistID="%s" order by ReleaseDate DESC''' % ArtistID)
results = c.fetchall()
c.close()
i = 0
- page.append('''
- %s
-
- |
- Album Name |
- Release Date |
- Status |
- |
-
''' % (artistname[0]))
+ template.albums = []
while i < len(results):
- if results[i][3] == 'Skipped':
- newStatus = '''%s [want]''' % (results[i][3], results[i][2], ArtistID)
- elif results[i][3] == 'Wanted':
- newStatus = '''%s[skip]''' % (results[i][3], results[i][2], ArtistID)
- elif results[i][3] == 'Downloaded':
- newStatus = '''%s[retry]''' % (results[i][3], results[i][2], ArtistID)
- elif results[i][3] == 'Snatched':
- newStatus = '''%s[retry]''' % (results[i][3], results[i][2], ArtistID)
- else:
- newStatus = '%s' % (results[i][3])
- page.append(''' |
- %s
- (link) |
- %s |
- %s |
''' % (results[i][5], results[i][2], results[i][0], results[i][2], results[i][1], newStatus))
+ template.albums.append(results[i])
i = i+1
- page.append('''
''')
- page.append(templates._footer)
- return page
+ return str(template)
artistPage.exposed = True
def albumPage(self, AlbumID):
- page = [templates._header]
- page.append(templates._logobar)
- page.append(templates._nav)
+ filename = os.path.join(self.templatePath,"albumPage.tmpl")
+ template = Template(file=filename)
+ template.rootPath = "."
+ template.appPath = "."
conn=sqlite3.connect(database)
c=conn.cursor()
c.execute('''SELECT ArtistID, ArtistName, AlbumTitle, TrackTitle, TrackDuration, TrackID, AlbumASIN from tracks WHERE AlbumID="%s"''' % AlbumID)
results = c.fetchall()
- if results[0][6]:
- albumart = '''

''' % results[0][6]
- else:
- albumart = ''
c.close()
+ template.albumASIN = results[0][6]
+ template.artistID = results[0][0]
+ template.artistName = results[0][1]
+ template.albumTitle = results[0][2]
+ template.tracks = []
i = 0
- page.append('''
- %s - %s
- Download
%s
-
- | Track # |
- Track Title |
- Duration |
- |
-
''' % (results[0][0], results[0][1], results[0][2], AlbumID, results[0][0], albumart))
while i < len(results):
- if results[i][4]:
- duration = time.strftime("%M:%S", time.gmtime(int(results[i][4])/1000))
- else:
- duration = 'n/a'
- page.append('''| %s |
- %s (link) |
- %s |
''' % (i+1, results[i][3], results[i][5], duration))
+ track = list(results[i])
+ track.append(i+1)
+ template.tracks.append(track)
i = i+1
- page.append('''
''')
-
- page.append(templates._footer)
- return page
-
+ return str(template)
albumPage.exposed = True
@@ -182,15 +131,17 @@ class Headphones:
findArtist.exposed = True
def artistInfo(self, artistid):
- page = [templates._header]
+
+ filename = os.path.join(self.templatePath,"artistInfo.tmpl")
+ template = Template(file=filename)
+ template.rootPath = "."
+ template.appPath = "."
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), releaseGroups=True)
artist = ws.Query().getArtistById(artistid, inc)
- page.append('''Artist Name: %s ''' % artist.name)
- page.append('''Unique ID: %s Albums:
''' % u.extractUuid(artist.id))
- for rg in artist.getReleaseGroups():
- page.append('''%s
''' % rg.title)
- return page
-
+ template.artistName = artist.name
+ template.artistUuid = artistid
+ template.releaseGroups = artist.getReleaseGroups()
+ return str(template)
artistInfo.exposed = True
def addArtist(self, artistid):
@@ -316,30 +267,17 @@ class Headphones:
upcoming.exposed = True
def manage(self):
+ filename = os.path.join(self.templatePath,"manage.tmpl")
+ template = Template(file=filename)
+ template.rootPath = "."
+ template.appPath = "."
config = configobj.ConfigObj(config_file)
try:
path = config['General']['path_to_xml']
except:
path = 'Absolute path to iTunes XML or Top-Level Music Directory'
- page = [templates._header]
- page.append(templates._logobar)
- page.append(templates._nav)
- page.append('''Import or Sync Your iTunes Library/Music Folder
- Enter the full path to your iTunes XML file or music folder
- i.e. /Users/"username"/Music/iTunes/iTunes Music Library.xml
- or /Users/"username"/Music/iTunes/iTunes Media/Music
(artists should have their own directories for folder import to work)
-
note: This process can take a LONG time!
- Once you click "Submit" you can navigate away from this
- page while the process runs.
-
- ''' % path)
- page.append(templates._footer)
- return page
+ template.path = path
+ return str(template)
manage.exposed = True
def importItunes(self, path):