mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-08 04:39:29 +01:00
Added XBMC library updates & notifications to post processing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@ logs/*
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store?
|
||||
.DS_Store
|
||||
ehthumbs.db
|
||||
Icon?
|
||||
Thumbs.db
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<td>
|
||||
<h3>HTTP Host:</h3>
|
||||
<input type="text" name="http_host" value="${config['http_host']}" size="30" maxlength="40"><br>
|
||||
<i class="smalltext">i.e. localhost or 0.0.0.0</i>
|
||||
<i class="smalltext">e.g. localhost or 0.0.0.0</i>
|
||||
</td>
|
||||
<td>
|
||||
<h3>HTTP Username:</h3>
|
||||
@@ -90,7 +90,7 @@
|
||||
<h3>Music Download Directory:</h3><input type="text" name="download_dir" value="${config['download_dir']}" size="50"><br>
|
||||
|
||||
<i class="smalltext">Full path to the directory where SAB downloads your music<br>
|
||||
i.e. /Users/name/Downloads/music</i>
|
||||
e.g. /Users/name/Downloads/music</i>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<h3>Music Download Directory:</h3><input type="text" name="download_torrent_dir" value="${config['download_torrent_dir']}" size="50"><br>
|
||||
|
||||
<i class="smalltext">Full path to the directory where your torrent client downloads your music<br>
|
||||
i.e. /Users/name/Downloads/music</i>
|
||||
e.g. /Users/name/Downloads/music</i>
|
||||
</td>
|
||||
|
||||
<td></td>
|
||||
@@ -178,7 +178,7 @@
|
||||
<td>
|
||||
<h3>Newznab Host: </h3>
|
||||
<input type="text" name="newznab_host" value="${config['newznab_host']}" size="30" maxlength="40"><br>
|
||||
<i class="smalltext">i.e. http://nzb.su</i>
|
||||
<i class="smalltext">e.g. http://nzb.su</i>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
@@ -280,7 +280,7 @@
|
||||
|
||||
<h3>Path to Destination folder:</h3><input type="text" name="destination_dir" value="${config['dest_dir']}" size="50">
|
||||
<br>
|
||||
<i class="smalltext">i.e. /Users/name/Music/iTunes or /Volumes/share/music</i>
|
||||
<i class="smalltext">e.g. /Users/name/Music/iTunes or /Volumes/share/music</i>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -421,12 +421,21 @@
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<h2>Prowl Notification:</h2><br>
|
||||
<h2>Notifications:</h2><br>
|
||||
<h3><input type="checkbox" name="prowl_enabled" id="prowl" value="1" ${config['prowl_enabled']} />Enable Prowl Notifications</h3><br>
|
||||
<div id="prowloptions">
|
||||
<h3>API key:</h3><input type="text" name="prowl_keys" value="${config['prowl_keys']}" size="50"><br><br>
|
||||
<h3><input type="checkbox" name="prowl_onsnatch" value="1" ${config['prowl_onsnatch']} />Notify on snatch?</h3><br>
|
||||
<h3>Priority (-2,-1,0,1 or 2):</h3><input type="text" name="prowl_priority" value="${config['prowl_priority']}" size="2">
|
||||
<h3>Priority (-2,-1,0,1 or 2):</h3><input type="text" name="prowl_priority" value="${config['prowl_priority']}" size="2"><br><br>
|
||||
</div>
|
||||
<h3><input type="checkbox" name="xbmc_enabled" id="xbmc" value="1" ${config['xbmc_enabled']} />Enable XBMC Updates</h3><br>
|
||||
<div id="xbmcoptions">
|
||||
<h3>XBMC Host:Port:</h3><input type="text" name="xbmc_host" value="${config['xbmc_host']}" size="30"><br>
|
||||
<i class="smalltext">e.g. http://localhost:8080</i><br>
|
||||
<h3>XBMC Username:</h3><input type="text" name="xbmc_username" value="${config['xbmc_username']}" size="30"><br><br>
|
||||
<h3>XBMC Password:</h3><input type="password" name="xbmc_password" value="${config['xbmc_password']}" size="30"><br><br>
|
||||
<h3><input type="checkbox" name="xbmc_update" value="1" ${config['xbmc_update']} />Update XBMC Library</h3><br>
|
||||
<h3><input type="checkbox" name="xbmc_notify" value="1" ${config['xbmc_notify']} />Send Notification to XBMC</h3><br>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -527,6 +536,26 @@
|
||||
$("#prowloptions").hide("fast");
|
||||
}
|
||||
});
|
||||
|
||||
if ($("#xbmc").is(":checked"))
|
||||
{
|
||||
$("#xbmcoptions").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#xbmcoptions").hide();
|
||||
}
|
||||
|
||||
$("#xbmc").click(function(){
|
||||
if ($("#xbmc").is(":checked"))
|
||||
{
|
||||
$("#xbmcoptions").show("fast");
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#xbmcoptions").hide("fast");
|
||||
}
|
||||
});
|
||||
|
||||
$("#mirror").change(handleNewSelection);
|
||||
handleNewSelection.apply($("#mirror"));
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<td>
|
||||
<h3>HTTP Host:</h3>
|
||||
<input type="text" name="http_host" value="${config['http_host']}" size="30" maxlength="40"><br>
|
||||
<i class="smalltext">i.e. localhost or 0.0.0.0</i>
|
||||
<i class="smalltext">e.g. localhost or 0.0.0.0</i>
|
||||
</td>
|
||||
<td>
|
||||
<h3>HTTP Username:</h3>
|
||||
@@ -90,7 +90,7 @@
|
||||
<h3>Music Download Directory:</h3><input type="text" name="download_dir" value="${config['download_dir']}" size="50"><br>
|
||||
|
||||
<i class="smalltext">Full path to the directory where SAB downloads your music<br>
|
||||
i.e. /Users/name/Downloads/music</i>
|
||||
e.g. /Users/name/Downloads/music</i>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<h3>Music Download Directory:</h3><input type="text" name="download_torrent_dir" value="${config['download_torrent_dir']}" size="50"><br>
|
||||
|
||||
<i class="smalltext">Full path to the directory where your torrent client downloads your music<br>
|
||||
i.e. /Users/name/Downloads/music</i>
|
||||
e.g. /Users/name/Downloads/music</i>
|
||||
</td>
|
||||
|
||||
<td></td>
|
||||
@@ -178,7 +178,7 @@
|
||||
<td>
|
||||
<h3>Newznab Host: </h3>
|
||||
<input type="text" name="newznab_host" value="${config['newznab_host']}" size="30" maxlength="40"><br>
|
||||
<i class="smalltext">i.e. http://nzb.su</i>
|
||||
<i class="smalltext">e.g. http://nzb.su</i>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
@@ -280,7 +280,7 @@
|
||||
|
||||
<h3>Path to Destination folder:</h3><input type="text" name="destination_dir" value="${config['dest_dir']}" size="50">
|
||||
<br>
|
||||
<i class="smalltext">i.e. /Users/name/Music/iTunes or /Volumes/share/music</i>
|
||||
<i class="smalltext">e.g. /Users/name/Music/iTunes or /Volumes/share/music</i>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -421,12 +421,21 @@
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<h2>Prowl Notification:</h2><br>
|
||||
<h2>Notifications:</h2><br>
|
||||
<h3><input type="checkbox" name="prowl_enabled" id="prowl" value="1" ${config['prowl_enabled']} />Enable Prowl Notifications</h3><br>
|
||||
<div id="prowloptions">
|
||||
<h3>API key:</h3><input type="text" name="prowl_keys" value="${config['prowl_keys']}" size="50"><br><br>
|
||||
<h3><input type="checkbox" name="prowl_onsnatch" value="1" ${config['prowl_onsnatch']} />Notify on snatch?</h3><br>
|
||||
<h3>Priority (-2,-1,0,1 or 2):</h3><input type="text" name="prowl_priority" value="${config['prowl_priority']}" size="2">
|
||||
<h3>Priority (-2,-1,0,1 or 2):</h3><input type="text" name="prowl_priority" value="${config['prowl_priority']}" size="2"><br><br>
|
||||
</div>
|
||||
<h3><input type="checkbox" name="xbmc_enabled" id="xbmc" value="1" ${config['xbmc_enabled']} />Enable XBMC Updates</h3><br>
|
||||
<div id="xbmcoptions">
|
||||
<h3>XBMC Host:Port:</h3><input type="text" name="xbmc_host" value="${config['xbmc_host']}" size="30"><br>
|
||||
<i class="smalltext">e.g. http://localhost:8080</i><br>
|
||||
<h3>XBMC Username:</h3><input type="text" name="xbmc_username" value="${config['xbmc_username']}" size="30"><br><br>
|
||||
<h3>XBMC Password:</h3><input type="password" name="xbmc_password" value="${config['xbmc_password']}" size="30"><br><br>
|
||||
<h3><input type="checkbox" name="xbmc_update" value="1" ${config['xbmc_update']} />Update XBMC Library</h3><br>
|
||||
<h3><input type="checkbox" name="xbmc_notify" value="1" ${config['xbmc_notify']} />Send Notification to XBMC</h3><br>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -527,6 +536,26 @@
|
||||
$("#prowloptions").hide("fast");
|
||||
}
|
||||
});
|
||||
|
||||
if ($("#xbmc").is(":checked"))
|
||||
{
|
||||
$("#xbmcoptions").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#xbmcoptions").hide();
|
||||
}
|
||||
|
||||
$("#xbmc").click(function(){
|
||||
if ($("#xbmc").is(":checked"))
|
||||
{
|
||||
$("#xbmcoptions").show("fast");
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#xbmcoptions").hide("fast");
|
||||
}
|
||||
});
|
||||
|
||||
$("#mirror").change(handleNewSelection);
|
||||
handleNewSelection.apply($("#mirror"));
|
||||
|
||||
@@ -134,6 +134,12 @@ PROWL_ENABLED = True
|
||||
PROWL_PRIORITY = 1
|
||||
PROWL_KEYS = None
|
||||
PROWL_ONSNATCH = True
|
||||
XBMC_ENABLED = False
|
||||
XBMC_HOST = None
|
||||
XBMC_USERNAME = None
|
||||
XBMC_PASSWORD = None
|
||||
XBMC_UPDATE = False
|
||||
XBMC_NOTIFY = False
|
||||
MIRRORLIST = ["musicbrainz.org","headphones","tbueter.com","custom"]
|
||||
MIRROR = None
|
||||
CUSTOMHOST = None
|
||||
@@ -203,7 +209,7 @@ def initialize():
|
||||
NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \
|
||||
ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, ENCODE, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRCBR, \
|
||||
ENCODERLOSSLESS, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, MIRRORLIST, MIRROR, CUSTOMHOST, CUSTOMPORT, \
|
||||
CUSTOMSLEEP, HPUSER, HPPASS
|
||||
CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, XBMC_NOTIFY
|
||||
|
||||
if __INITIALIZED__:
|
||||
return False
|
||||
@@ -216,6 +222,7 @@ def initialize():
|
||||
CheckSection('NZBsorg')
|
||||
CheckSection('Newzbin')
|
||||
CheckSection('Prowl')
|
||||
CheckSection('XBMC')
|
||||
|
||||
# Set global variables based on config file or use defaults
|
||||
try:
|
||||
@@ -309,6 +316,14 @@ def initialize():
|
||||
PROWL_ONSNATCH = bool(check_setting_int(CFG, 'Prowl', 'prowl_onsnatch', 0))
|
||||
PROWL_PRIORITY = check_setting_int(CFG, 'Prowl', 'prowl_priority', 0)
|
||||
|
||||
XBMC_ENABLED = bool(check_setting_int(CFG, 'XBMC', 'xbmc_enabled', 0))
|
||||
XBMC_HOST = check_setting_str(CFG, 'XBMC', 'xbmc_host', '')
|
||||
XBMC_USERNAME = check_setting_str(CFG, 'XBMC', 'xbmc_username', '')
|
||||
XBMC_PASSWORD = check_setting_str(CFG, 'XBMC', 'xbmc_password', '')
|
||||
XBMC_UPDATE = bool(check_setting_int(CFG, 'XBMC', 'xbmc_update', 0))
|
||||
XBMC_NOTIFY = bool(check_setting_int(CFG, 'XBMC', 'xbmc_notify', 0))
|
||||
|
||||
|
||||
MIRROR = check_setting_str(CFG, 'General', 'mirror', 'musicbrainz.org')
|
||||
CUSTOMHOST = check_setting_str(CFG, 'General', 'customhost', 'localhost')
|
||||
CUSTOMPORT = check_setting_int(CFG, 'General', 'customport', 5000)
|
||||
@@ -502,6 +517,14 @@ def config_write():
|
||||
new_config['Prowl']['prowl_onsnatch'] = int(PROWL_ONSNATCH)
|
||||
new_config['Prowl']['prowl_priority'] = int(PROWL_PRIORITY)
|
||||
|
||||
new_config['XBMC'] = {}
|
||||
new_config['XBMC']['xbmc_enabled'] = int(XBMC_ENABLED)
|
||||
new_config['XBMC']['xbmc_host'] = XBMC_HOST
|
||||
new_config['XBMC']['xbmc_username'] = XBMC_USERNAME
|
||||
new_config['XBMC']['xbmc_password'] = XBMC_PASSWORD
|
||||
new_config['XBMC']['xbmc_update'] = int(XBMC_UPDATE)
|
||||
new_config['XBMC']['xbmc_notify'] = int(XBMC_NOTIFY)
|
||||
|
||||
new_config['General']['lastfm_username'] = LASTFM_USERNAME
|
||||
new_config['General']['interface'] = INTERFACE
|
||||
new_config['General']['folder_permissions'] = FOLDER_PERMISSIONS
|
||||
|
||||
@@ -61,3 +61,69 @@ class PROWL:
|
||||
self.priority = priority
|
||||
|
||||
self.notify('ZOMG Lazors Pewpewpew!', 'Test Message')
|
||||
|
||||
class XBMC:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.host = headphones.XBMC_HOST
|
||||
self.username = headphones.XBMC_USERNAME
|
||||
self.password = headphones.XBMC_PASSWORD
|
||||
|
||||
def _send(self, command):
|
||||
|
||||
host = self.host
|
||||
username = self.username
|
||||
password = self.password
|
||||
|
||||
url_command = urllib.urlencode(command)
|
||||
|
||||
url = host + '/xbmcCmds/xbmcHttp/?' + url_command
|
||||
|
||||
req = urllib2.Request(url)
|
||||
|
||||
if password:
|
||||
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
|
||||
req.add_header("Authorization", "Basic %s" % base64string)
|
||||
|
||||
logger.info('XBMC url: %s' % url)
|
||||
|
||||
try:
|
||||
handle = urllib2.urlopen(req)
|
||||
except Exception, e:
|
||||
logger.warn('Error opening XBMC url: ' % e)
|
||||
return
|
||||
|
||||
response = handle.read().decode(headphones.SYS_ENCODING)
|
||||
|
||||
return response
|
||||
|
||||
def update(self):
|
||||
|
||||
# From what I read you can't update the music library on a per directory or per path basis
|
||||
# so need to update the whole thing
|
||||
|
||||
updatecommand = {'command': 'ExecBuiltIn', 'parameter': 'XBMC.updatelibrary(music)'}
|
||||
|
||||
logger.info('Sending library update command to XBMC')
|
||||
request = self._send(updatecommand)
|
||||
|
||||
if not request:
|
||||
logger.warn('Error sending update request to XBMC')
|
||||
|
||||
def notify(self, artist, album, albumartpath):
|
||||
|
||||
header = "Headphones"
|
||||
message = "%s - %s added to your library" % (artist, album)
|
||||
time = "3000" # in ms
|
||||
|
||||
|
||||
notification = header + "," + message + "," + time + "," + albumartpath
|
||||
|
||||
notifycommand = {'command': 'ExecBuiltIn', 'parameter': 'Notification(' + notification + ')' }
|
||||
|
||||
logger.info('Sending notification command to XMBC')
|
||||
request = self._send(notifycommand)
|
||||
|
||||
if not request:
|
||||
logger.warn('Error sending notification request to XBMC')
|
||||
@@ -2,8 +2,7 @@ import os
|
||||
import time
|
||||
import encode
|
||||
import urllib, shutil, re
|
||||
from headphones import prowl
|
||||
from headphones.prowl import PROWL
|
||||
from headphones import notifiers
|
||||
import lib.beets as beets
|
||||
from lib.beets import autotag
|
||||
from lib.beets.mediafile import MediaFile
|
||||
@@ -207,8 +206,9 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list)
|
||||
if headphones.ENCODE:
|
||||
downloaded_track_list=encode.encode(albumpath)
|
||||
|
||||
album_art_path = albumart.getAlbumArt(albumid)
|
||||
|
||||
if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
|
||||
album_art_path = albumart.getAlbumArt(albumid)
|
||||
artwork = urllib.urlopen(album_art_path).read()
|
||||
if len(artwork) < 100:
|
||||
artwork = False
|
||||
@@ -256,13 +256,19 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list)
|
||||
updateHave(albumpath)
|
||||
|
||||
logger.info('Post-processing for %s - %s complete' % (release['ArtistName'], release['AlbumTitle']))
|
||||
if headphones.PROWL_ONSNATCH:
|
||||
pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
|
||||
logger.info(u"Prowl request")
|
||||
prowl = PROWL()
|
||||
prowl.notify(pushmessage,"Download and Postprocessing completed")
|
||||
|
||||
|
||||
|
||||
if headphones.PROWL_ONSNATCH:
|
||||
pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
|
||||
logger.info(u"Prowl request")
|
||||
prowl = notifiers.PROWL()
|
||||
prowl.notify(pushmessage,"Download and Postprocessing completed")
|
||||
|
||||
if headphones.XBMC_ENABLED:
|
||||
xbmc = notifiers.XBMC()
|
||||
if headphones.XBMC_UPDATE:
|
||||
xbmc.update()
|
||||
if headphones.XBMC_NOTIFY:
|
||||
xbmc.notify(release['ArtistName'], release['AlbumTitle'], album_art_path)
|
||||
|
||||
def embedAlbumArt(artwork, downloaded_track_list):
|
||||
logger.info('Embedding album art')
|
||||
|
||||
@@ -25,8 +25,7 @@ import urllib2, cookielib
|
||||
|
||||
from headphones.common import USER_AGENT
|
||||
from headphones import logger
|
||||
from headphones import prowl
|
||||
from headphones.prowl import PROWL
|
||||
from headphones import notifiers
|
||||
|
||||
def sendNZB(nzb):
|
||||
|
||||
@@ -119,7 +118,7 @@ def sendNZB(nzb):
|
||||
logger.info(u"NZB sent to SAB successfully")
|
||||
if headphones.PROWL_ONSNATCH:
|
||||
logger.info(u"Prowl request")
|
||||
prowl = PROWL()
|
||||
prowl = notifiers.PROWL()
|
||||
prowl.notify(nzb.name,"Download started")
|
||||
|
||||
return True
|
||||
|
||||
@@ -383,6 +383,12 @@ class WebInterface(object):
|
||||
"prowl_onsnatch": checked(headphones.PROWL_ONSNATCH),
|
||||
"prowl_keys": headphones.PROWL_KEYS,
|
||||
"prowl_priority": headphones.PROWL_PRIORITY,
|
||||
"xbmc_enabled": checked(headphones.XBMC_ENABLED),
|
||||
"xbmc_host": headphones.XBMC_HOST,
|
||||
"xbmc_username": headphones.XBMC_USERNAME,
|
||||
"xbmc_password": headphones.XBMC_PASSWORD,
|
||||
"xbmc_update": checked(headphones.XBMC_UPDATE),
|
||||
"xbmc_notify": checked(headphones.XBMC_NOTIFY),
|
||||
"mirror_list": headphones.MIRRORLIST,
|
||||
"mirror": headphones.MIRROR,
|
||||
"customhost": headphones.CUSTOMHOST,
|
||||
@@ -402,7 +408,8 @@ class WebInterface(object):
|
||||
torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0,
|
||||
rename_files=0, correct_metadata=0, cleanup_files=0, add_album_art=0, embed_album_art=0, embed_lyrics=0, destination_dir=None, folder_format=None, file_format=None, include_extras=0, interface=None, log_dir=None,
|
||||
encode=0, encoder=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0,
|
||||
prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None):
|
||||
prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, xbmc_enabled=0, xbmc_host=None, xbmc_username=None, xbmc_password=None, xbmc_update=0, xbmc_notify=0,
|
||||
mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None):
|
||||
|
||||
headphones.HTTP_HOST = http_host
|
||||
headphones.HTTP_PORT = http_port
|
||||
@@ -466,6 +473,12 @@ class WebInterface(object):
|
||||
headphones.PROWL_ONSNATCH = prowl_onsnatch
|
||||
headphones.PROWL_KEYS = prowl_keys
|
||||
headphones.PROWL_PRIORITY = prowl_priority
|
||||
headphones.XBMC_ENABLED = xbmc_enabled
|
||||
headphones.XBMC_HOST = xbmc_host
|
||||
headphones.XBMC_USERNAME = xbmc_username
|
||||
headphones.XBMC_PASSWORD = xbmc_password
|
||||
headphones.XBMC_UPDATE = xbmc_update
|
||||
headphones.XBMC_NOTIFY = xbmc_notify
|
||||
headphones.MIRROR = mirror
|
||||
headphones.CUSTOMHOST = customhost
|
||||
headphones.CUSTOMPORT = customport
|
||||
|
||||
Reference in New Issue
Block a user