From 77fdbe4ceea0f818feda3c290dc2a9c67c936635 Mon Sep 17 00:00:00 2001 From: Remy Date: Mon, 23 May 2011 20:56:28 -0700 Subject: [PATCH] added sabnzbd & nzbmatrix support --- config.py | 15 ++++--- data/css/style.css | 2 +- data/images/blank.gif | Bin 49 -> 0 bytes data/images/bottom.png | Bin 431 -> 0 bytes data/images/shadow.gif | Bin 46 -> 0 bytes data/images/top.png | Bin 417 -> 0 bytes findArtist.py | 30 -------------- headphones.py | 87 +++++++++++++++++++++++++++++++++++++---- search.py | 29 -------------- server.conf | 19 --------- templates.py | 4 +- webServer.py | 39 ++++++++++-------- 12 files changed, 115 insertions(+), 110 deletions(-) delete mode 100755 data/images/blank.gif delete mode 100755 data/images/bottom.png delete mode 100755 data/images/shadow.gif delete mode 100755 data/images/top.png delete mode 100644 findArtist.py delete mode 100644 search.py delete mode 100644 server.conf diff --git a/config.py b/config.py index 39480787..6030ffc5 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,8 @@ import os from configobj import ConfigObj +from headphones import config_file -config = ConfigObj(os.path.join(os.path.dirname(__file__), 'config.ini')) +config = ConfigObj(config_file) General = config['General'] http_host = General['http_host'] @@ -11,9 +12,11 @@ http_password = General['http_password'] launch_browser = General['launch_browser'] usenet_retention = General['usenet_retention'] include_lossless = General['include_lossless'] +flac_to_mp3 = General['flac_to_mp3'] move_to_itunes = General['move_to_itunes'] path_to_itunes = General['path_to_itunes'] rename_mp3s = General['rename_mp3s'] +cleanup = General['cleanup'] add_album_art = General['add_album_art'] music_download_dir = General['music_download_dir'] NZBMatrix = config['NZBMatrix'] @@ -74,18 +77,20 @@ form = '''

Quality & Post Processing

+ Include lossless + Convert lossless to mp3 + Rename & add metadata

+ Delete leftover files

Album Quality:

- Include lossless

iTunes:

Move downloads to iTunes

Path to iTunes folder:


i.e. Music/iTunes or /Users/name/Music/iTunes

Renaming & Metadata:

- Rename & add metadata

Album Art:

Add album art

''' % (http_host, http_username, http_port, http_password, var_to_chk(launch_browser), sab_host, sab_username, sab_apikey, sab_password, sab_category, music_download_dir, usenet_retention, var_to_chk(nzbmatrix), nzbmatrix_username, nzbmatrix_apikey, - var_to_chk(include_lossless), var_to_chk(move_to_itunes), path_to_itunes, var_to_chk(rename_mp3s), - var_to_chk(add_album_art)) \ No newline at end of file + var_to_chk(include_lossless), var_to_chk(flac_to_mp3), var_to_chk(move_to_itunes), path_to_itunes, var_to_chk(rename_mp3s), + var_to_chk(cleanup), var_to_chk(add_album_art)) \ No newline at end of file diff --git a/data/css/style.css b/data/css/style.css index 81d9832e..a7a47ea5 100644 --- a/data/css/style.css +++ b/data/css/style.css @@ -67,7 +67,7 @@ h1{ } .nav{ padding: 2px; - font-size:20px; + font-size:19px; color: grey; background-color: #bbbbbb; width: 95%; diff --git a/data/images/blank.gif b/data/images/blank.gif deleted file mode 100755 index 75b945d2553848b8b6f41fe5e24599c0687b8472..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49 zcmZ?wbhEHbWMp7unE0RJ|Ns9C3=9Vj8~~DvKUo+V7?>DzfNY>Fh|Ltj$Y2csQN9XW diff --git a/data/images/bottom.png b/data/images/bottom.png deleted file mode 100755 index 7f46c801164ad4f707fe7de82f9272c61cf60a59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 431 zcmV;g0Z{&lP)RKUW!4NZRDHmSsK+O*|*L0S0`}y&GgxDJ4ytl+vEdmY15m<+bLz z<*jb7;at1+Qt#gb002BksadxyHS?C+mXDhEx}C$hcI|#&+2z6DwJzwF!Qy_cgK}2_ zF7>=30002bEdp&_9?QV3X09dR779SSw!}fX8#pQhv3V?^0K^h7DFOfha9R;4gE9~c z!KehpqE4epPZK>_e<0001-Uk27Yg6!4dWl#G004mV%RuTD z`(;o7%4o>Zqe0U_bMWmy008{mV(`fRun44kt>NHvg#Z8mezySp`24j0p%?%F@V|Tt ZFaVS#nT1#k1`GfI002ovPDHLkV1l%@vLyfj diff --git a/data/images/shadow.gif b/data/images/shadow.gif deleted file mode 100755 index 026d52a3b07c8c7b20c6056853353dfce8d70f40..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 46 ycmZ?wbhEHbWM^PvXkcVGbLPzd|Nj+#vM@3*Ff!;c00Bsbfr+(+f1xxhgEasr_6mOh diff --git a/data/images/top.png b/data/images/top.png deleted file mode 100755 index 48749b74789158b666268cd6156d81416eb897b5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 417 zcmeAS@N?(olHy`uVBq!ia0y~yU}gfcxj5K>Bs=>{4NRNq^clROok?zfl8%3cdJ^uM?Lo-0w`=dI+Q$H>5NJga{W z@8O1j(r0U9Z-zGl<^TCGWZ3hv{dIHRzwOv9ZdL|{1D_8$#3WxW5xalB=|J4)`%6o; zMSu#=^D=I{cX^icfpCc%vpJ4Dt6vd(<9UDr4^YGVmWCUD_)Dd$Kg)2LsWYjzHt4lB z*tIsU(@|#uN`G`*u=JUIdxHd<*Gzwoux5vSd?j3p59Tl(T&c618LU9z->rJ-*SahX znmj(|uWy*o+E{Z`-H+*<_EdG2%jFCV4arXh3|JdpN0^%a`^kUg`}yl?Oh2tIT=)@h z_c}F3Kh;jLBk@28(3O3cPZbFj$R0lM`o`@1)`peu>{uii(yJ1hRD8HV5y0T->gTe~ HDWM4fvM!>l diff --git a/findArtist.py b/findArtist.py deleted file mode 100644 index b0a1626b..00000000 --- a/findArtist.py +++ /dev/null @@ -1,30 +0,0 @@ -import sys -from musicbrainz2.webservice import Query, ArtistFilter, WebServiceError - -def findArtist(self, name): - - if len(name) < 2: - return '''Please enter an artist''' - - q = Query() - - try: - f = ArtistFilter(name, limit=5) - artistResults = q.getArtists(f) - - except WebServiceError, e: - print 'Error:', e - sys.exit(1) - - for result in artistResults: - artist = result.artist - return ''' - Score = %s - Id = %s - Name = %s - Sort Name = %s - ''' % result.score, artist.id, artist.name, artist.sortName - - - - diff --git a/headphones.py b/headphones.py index 30abb612..2dd37c2f 100755 --- a/headphones.py +++ b/headphones.py @@ -1,13 +1,84 @@ #!/usr/bin/env python -import os import cherrypy -from webServer import Headphones - - +from cherrypy.process.plugins import Daemonizer +from optparse import OptionParser +from configobj import ConfigObj +from configcreate import configCreate +import webServer +import time +from threadtools import threadtool +import os + + + +#set up paths + +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): + pass +else: + configCreate(config_file) + +settings = ConfigObj(config_file)['General'] + + +def serverstart(): + + parser = OptionParser() + parser.add_option("-d", "--daemonize", action="store_true", dest="daemonize") + parser.add_option("-q", "--quiet", action="store_true", dest="quiet") + + (options, args) = parser.parse_args() + + if options.quiet or options.daemonize: + cherrypy.config.update({'log.screen': False}) + + cherrypy.config.update({ + 'server.thread_pool': 10, + 'server.socket_port': int(settings['http_port']), + 'server.socket_host': settings['http_host'] + }) + + conf = { + '/': { + 'tools.staticdir.root': FULL_PATH + }, + '/data/images':{ + 'tools.staticdir.on': True, + 'tools.staticdir.dir': "data/images" + }, + '/data/css':{ + 'tools.staticdir.on': True, + 'tools.staticdir.dir': "data/css" + }, + '/data/js':{ + 'tools.staticdir.on': True, + 'tools.staticdir.dir': "data/js" + } + } + + + if settings['http_password'] != "": + conf['/'].update({ + 'tools.auth_basic.on': True, + 'tools.auth_basic.realm': 'mordor', + 'tools.auth_basic.checkpassword': cherrypy.lib.auth_basic.checkpassword_dict( + {settings['http_username']:settings['http_password']}) + }) + + if options.daemonize: + Daemonizer(cherrypy.engine).subscribe() + + + #Start threads + threadtool(cherrypy.engine).subscribe() + + cherrypy.quickstart(webServer.Headphones(), config = conf) -#path to config_file -config_file = os.path.join(os.path.dirname(__file__), 'server.conf') if __name__ == '__main__': - cherrypy.quickstart(Headphones(), config=config_file) - + serverstart() diff --git a/search.py b/search.py deleted file mode 100644 index 5adea6d0..00000000 --- a/search.py +++ /dev/null @@ -1,29 +0,0 @@ -import sys -import musicbrainz2.webservice as ws -import musicbrainz2.model as m - -def findArtist(name): - - if len(name) == 0 or name == 'Add an artist': - return '''

Please enter an artist

''' - - q = ws.Query() - - f = ws.ArtistFilter(name, limit=5) - artistResults = ws.Query().getArtists(ws.ArtistFilter(name, limit=5)) - - if len(artistResults) > 1: - - return '''We found a few different artists. Which one did you want?

''' - - for result in artistResults: - artist = result.artist - return ''' %s
''' % (artist.id, artist.name) - - elif len(artistRestuls) == 1: - - return '''Ok, we're going to add %s''' % artist.name - - else: - - return '''We couldn't find any artists!''' \ No newline at end of file diff --git a/server.conf b/server.conf deleted file mode 100644 index 74a48353..00000000 --- a/server.conf +++ /dev/null @@ -1,19 +0,0 @@ -[global] -server.socket_host = "0.0.0.0" -server.socket_port = 8181 -server.thread_pool = 10 - -[/] -tools.staticdir.root = os.getcwd() - -[/data/images] -tools.staticdir.on = True -tools.staticdir.dir = "data/images" - -[/data/css] -tools.staticdir.on = True -tools.staticdir.dir = "data/css" - -[/data/js] -tools.staticdir.on = True -tools.staticdir.dir = "data/js" \ No newline at end of file diff --git a/templates.py b/templates.py index 11218fe1..b768b94c 100644 --- a/templates.py +++ b/templates.py @@ -1,8 +1,10 @@ _header = ''' - headphones + Headphones + +
''' diff --git a/webServer.py b/webServer.py index f6eddc17..cb6edeb2 100644 --- a/webServer.py +++ b/webServer.py @@ -1,7 +1,6 @@ import templates import config import cherrypy -import search import musicbrainz2.webservice as ws import musicbrainz2.model as m import musicbrainz2.utils as u @@ -11,10 +10,9 @@ import time import sqlite3 import sys import configobj +from headphones import FULL_PATH, config_file - - -database = os.path.join(os.path.dirname(__file__), 'headphones.db') +database = os.path.join(FULL_PATH, 'headphones.db') class Headphones: @@ -32,7 +30,7 @@ class Headphones: i = 0 page.append('''
- + @@ -41,7 +39,7 @@ class Headphones: c.execute('''SELECT AlbumTitle, ReleaseDate, DateAdded, AlbumID from albums WHERE ArtistName="%s" order by ReleaseDate DESC''' % results[i][0]) latestalbum = c.fetchall() if latestalbum[0][1] > latestalbum[0][2]: - newalbumName = '%s' % (latestalbum[0][3], latestalbum[0][0]) + newalbumName = '%s' % (latestalbum[0][3], latestalbum[0][0]) releaseDate = '(%s)' % latestalbum[0][1] else: newalbumName = 'None' @@ -50,10 +48,10 @@ class Headphones: newStatus = '''%s(resume)''' % (results[i][2], results[i][1]) else: newStatus = '''%s(pause)''' % (results[i][2], results[i][1]) - page.append(''' - ''' % (results[i][1], results[i][0], results[i][1], results[i][1], newStatus, newalbumName, releaseDate)) + ''' % (results[i][1], results[i][0], results[i][1], results[i][1], newStatus, newalbumName, releaseDate)) i = i+1 page.append('''
Artist NameArtist Name Status Upcoming Albums
%s + page.append('''
%s (link) [delete] %s%s %s
%s %s
''') else: @@ -89,6 +87,8 @@ class Headphones: 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(''' @@ -257,7 +257,10 @@ class Headphones: c.execute('UPDATE albums SET status = "Wanted" WHERE AlbumID="%s"' % AlbumID) conn.commit() c.close() + import searcher + searcher.searchNZB(AlbumID) raise cherrypy.HTTPRedirect("/artistPage?ArtistID=%s" % ArtistID) + queueAlbum.exposed = True @@ -271,9 +274,6 @@ class Headphones: unqueueAlbum.exposed = True - - - def upcoming(self): page = [templates._header] page.append(templates._logobar) @@ -308,15 +308,16 @@ class Headphones: config.exposed = True - def configUpdate(self, http_host='localhost', http_username=None, http_port=8181, http_password=None, launch_browser=0, + + def configUpdate(self, http_host='127.0.0.1', http_username=None, http_port=8181, http_password=None, launch_browser=0, sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, sab_category=None, music_download_dir=None, usenet_retention=None, nzbmatrix=0, nzbmatrix_username=None, nzbmatrix_apikey=None, include_lossless=0, - move_to_itunes=0, path_to_itunes=None, rename_mp3s=0, add_album_art=0): + flac_to_mp3=0, move_to_itunes=0, path_to_itunes=None, rename_mp3s=0, cleanup=0, add_album_art=0): - configs = configobj.ConfigObj(os.path.join(os.path.dirname(__file__), 'config.ini')) + configs = configobj.ConfigObj(config_file) SABnzbd = configs['SABnzbd'] General = configs['General'] - NZBMatrix = configs['NZBMatrix'] + NZBMatrix = configs['NZBMatrix'] General['http_host'] = http_host General['http_port'] = http_port General['http_username'] = http_username @@ -333,12 +334,15 @@ class Headphones: NZBMatrix['nzbmatrix_username'] = nzbmatrix_username NZBMatrix['nzbmatrix_apikey'] = nzbmatrix_apikey General['include_lossless'] = include_lossless + General['flac_to_mp3'] = flac_to_mp3 General['move_to_itunes'] = move_to_itunes General['path_to_itunes'] = path_to_itunes General['rename_mp3s'] = rename_mp3s + General['cleanup'] = cleanup General['add_album_art'] = add_album_art configs.write() + reload(config) raise cherrypy.HTTPRedirect("/config") @@ -346,5 +350,6 @@ class Headphones: configUpdate.exposed = True def shutdown(self): - sys.exit('Headphones is shutting down') - shutdown.exposed = True \ No newline at end of file + sys.exit() + + shutdown.exposed = True