diff --git a/webServer.py b/webServer.py
index 80e901a6..9b581918 100644
--- a/webServer.py
+++ b/webServer.py
@@ -13,22 +13,15 @@ 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):
-
- filename = os.path.join(self.templatePath,"index.tmpl")
- template = Template(file=filename)
- template.rootPath = "."
- template.appPath = "."
+ page = [templates._header]
+ page.append(templates._logobar)
+ page.append(templates._nav)
#Display Database if it exists:
if os.path.exists(database):
#logger.log(u"Loading artists from the database...")
@@ -37,71 +30,129 @@ class Headphones:
c.execute('SELECT ArtistName, ArtistID, Status from artists order by ArtistSortName collate nocase')
results = c.fetchall()
i = 0
- template.artists = []
+ page.append('''
+
+ | Artist Name |
+ Status |
+ Upcoming Albums |
+ |
+
''')
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:
- 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])
+ 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))
i = i+1
c.close()
- return str(template)
+ page.append('''
''')
+
+ else:
+ page.append("""Add some artists to the database!
""")
+ page.append(templates._footer)
+ return page
index.exposed = True
+
def artistPage(self, ArtistID):
- filename = os.path.join(self.templatePath,"artistPage.tmpl")
- template = Template(file=filename)
- template.rootPath = "."
- template.appPath = "."
- template.artistID = ArtistID
+ page = [templates._header]
+ page.append(templates._logobar)
+ page.append(templates._nav)
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
- template.albums = []
+ page.append('''
+ %s
+
+ |
+ Album Name |
+ Release Date |
+ Status |
+ |
+
''' % (artistname[0]))
while i < len(results):
- template.albums.append(results[i])
+ 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))
i = i+1
- return str(template)
+ page.append('''
''')
+ page.append(templates._footer)
+ return page
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):
- track = list(results[i])
- track.append(i+1)
- template.tracks.append(track)
+ 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))
i = i+1
+ page.append('''
''')
- return str(template)
+
+ page.append(templates._footer)
+ return page
+
albumPage.exposed = True
@@ -131,17 +182,15 @@ class Headphones:
findArtist.exposed = True
def artistInfo(self, artistid):
-
- filename = os.path.join(self.templatePath,"artistInfo.tmpl")
- template = Template(file=filename)
- template.rootPath = "."
- template.appPath = "."
+ page = [templates._header]
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), releaseGroups=True)
artist = ws.Query().getArtistById(artistid, inc)
- template.artistName = artist.name
- template.artistUuid = artistid
- template.releaseGroups = artist.getReleaseGroups()
- return str(template)
+ 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
+
artistInfo.exposed = True
def addArtist(self, artistid):
@@ -259,25 +308,38 @@ class Headphones:
unqueueAlbum.exposed = True
def upcoming(self):
- filename = os.path.join(self.templatePath,"upcoming.tmpl")
- template = Template(file=filename)
- template.rootPath = "."
- template.appPath = "."
- return str(template)
+ page = [templates._header]
+ page.append(templates._logobar)
+ page.append(templates._nav)
+ page.append(templates._footer)
+ return page
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'
- template.path = path
- return str(template)
+ 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
manage.exposed = True
def importItunes(self, path):
@@ -303,19 +365,21 @@ class Headphones:
def history(self):
- filename = os.path.join(self.templatePath,"history.tmpl")
- template = Template(file=filename)
- template.rootPath = "."
- template.appPath = "."
- return str(template)
+ page = [templates._header]
+ page.append(templates._logobar)
+ page.append(templates._nav)
+ page.append(templates._footer)
+ return page
history.exposed = True
def config(self):
- filename = os.path.join(self.templatePath,"config.tmpl")
- template = Template(file=filename)
- template.rootPath = "."
- template.appPath = "."
- return str(template)
+ page = [templates._header]
+ page.append(templates._logobar)
+ page.append(templates._nav)
+ page.append(config.form)
+ page.append(templates._footer)
+ return page
+
config.exposed = True
@@ -381,4 +445,4 @@ class Headphones:
python = sys.executable
os.execl(python, python, * sys.argv)
- restart.exposed = True
+ restart.exposed = True
\ No newline at end of file