mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-24 05:39:27 +00:00
Scheduling part 2
Remove job if interval changed to 0 Plus, fixup os x notify registering not working with yosemite and also show album image in notification
This commit is contained in:
@@ -271,39 +271,39 @@ def initialize_scheduler():
|
||||
|
||||
with SCHED_LOCK:
|
||||
|
||||
# Only start scheduler if (re-)starting headphones
|
||||
# Check if scheduler should be started
|
||||
start_jobs = not len(SCHED.get_jobs())
|
||||
|
||||
# Regular jobs
|
||||
if CONFIG.SEARCH_INTERVAL > 0:
|
||||
minutes = CONFIG.SEARCH_INTERVAL
|
||||
schedule_job(searcher.searchforalbum, 'Search for Wanted', hours=0, minutes=minutes)
|
||||
minutes = CONFIG.SEARCH_INTERVAL
|
||||
schedule_job(searcher.searchforalbum, 'Search for Wanted', hours=0, minutes=minutes)
|
||||
|
||||
if CONFIG.DOWNLOAD_SCAN_INTERVAL > 0:
|
||||
minutes = CONFIG.DOWNLOAD_SCAN_INTERVAL
|
||||
schedule_job(postprocessor.checkFolder, 'Download Scan', hours=0, minutes=minutes)
|
||||
minutes = CONFIG.DOWNLOAD_SCAN_INTERVAL
|
||||
schedule_job(postprocessor.checkFolder, 'Download Scan', hours=0, minutes=minutes)
|
||||
|
||||
if CONFIG.LIBRARYSCAN_INTERVAL > 0:
|
||||
hours = CONFIG.LIBRARYSCAN_INTERVAL
|
||||
schedule_job(librarysync.libraryScan, 'Library Scan', hours=hours, minutes=0)
|
||||
hours = CONFIG.LIBRARYSCAN_INTERVAL
|
||||
schedule_job(librarysync.libraryScan, 'Library Scan', hours=hours, minutes=0)
|
||||
|
||||
if CONFIG.UPDATE_DB_INTERVAL > 0:
|
||||
hours = CONFIG.UPDATE_DB_INTERVAL
|
||||
schedule_job(updater.dbUpdate, 'MusicBrainz Update', hours=hours, minutes=0)
|
||||
hours = CONFIG.UPDATE_DB_INTERVAL
|
||||
schedule_job(updater.dbUpdate, 'MusicBrainz Update', hours=hours, minutes=0)
|
||||
|
||||
# Update check
|
||||
if CONFIG.CHECK_GITHUB and CONFIG.CHECK_GITHUB_INTERVAL > 0:
|
||||
#Update check
|
||||
if CONFIG.CHECK_GITHUB_INTERVAL:
|
||||
minutes = CONFIG.CHECK_GITHUB_INTERVAL
|
||||
schedule_job(versioncheck.checkGithub, 'Check GitHub for updates', hours=0, minutes=minutes)
|
||||
else:
|
||||
minutes = 0
|
||||
schedule_job(versioncheck.checkGithub, 'Check GitHub for updates', hours=0, minutes=minutes)
|
||||
|
||||
# Remove Torrent + data if Post Processed and finished Seeding
|
||||
if CONFIG.TORRENT_REMOVAL_INTERVAL > 0:
|
||||
minutes = CONFIG.TORRENT_REMOVAL_INTERVAL
|
||||
schedule_job(torrentfinished.checkTorrentFinished, 'Torrent removal check', hours=0, minutes=minutes)
|
||||
minutes = CONFIG.TORRENT_REMOVAL_INTERVAL
|
||||
schedule_job(torrentfinished.checkTorrentFinished, 'Torrent removal check', hours=0, minutes=minutes)
|
||||
|
||||
# Start scheduler (only if (re-)starting headphones)
|
||||
# Start scheduler
|
||||
if start_jobs and len(SCHED.get_jobs()):
|
||||
SCHED.start()
|
||||
try:
|
||||
SCHED.start()
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
# Debug
|
||||
#SCHED.print_jobs()
|
||||
@@ -312,16 +312,21 @@ def initialize_scheduler():
|
||||
def schedule_job(function, name, hours=0, minutes=0):
|
||||
"""
|
||||
Start scheduled job if starting or restarting headphones.
|
||||
Re-schedule job if Interval Settings have changed.
|
||||
Reschedule job if Interval Settings have changed.
|
||||
Remove job if if Interval Settings changed to 0
|
||||
|
||||
"""
|
||||
|
||||
job = SCHED.get_job(name)
|
||||
if job:
|
||||
if job.trigger.interval != datetime.timedelta(hours=hours, minutes=minutes):
|
||||
if hours == 0 and minutes == 0:
|
||||
SCHED.remove_job(name)
|
||||
logger.info("Removed background task: %s", name)
|
||||
elif job.trigger.interval != datetime.timedelta(hours=hours, minutes=minutes):
|
||||
SCHED.reschedule_job(name, trigger=IntervalTrigger(
|
||||
hours=hours, minutes=minutes))
|
||||
logger.info("Re-scheduled background task: %s", name)
|
||||
else:
|
||||
elif hours > 0 or minutes > 0:
|
||||
SCHED.add_job(function, id=name, trigger=IntervalTrigger(
|
||||
hours=hours, minutes=minutes))
|
||||
logger.info("Scheduled background task: %s", name)
|
||||
|
||||
@@ -725,6 +725,7 @@ class OSX_NOTIFY(object):
|
||||
def __init__(self):
|
||||
try:
|
||||
self.objc = __import__("objc")
|
||||
self.AppKit = __import__("AppKit")
|
||||
except:
|
||||
return False
|
||||
|
||||
@@ -737,7 +738,7 @@ class OSX_NOTIFY(object):
|
||||
signature=old_IMP.signature)
|
||||
self.objc.classAddMethod(cls, SEL, new_IMP)
|
||||
|
||||
def notify(self, title, subtitle=None, text=None, sound=True):
|
||||
def notify(self, title, subtitle=None, text=None, sound=True, image=None):
|
||||
|
||||
try:
|
||||
self.swizzle(self.objc.lookUpClass('NSBundle'),
|
||||
@@ -761,6 +762,10 @@ class OSX_NOTIFY(object):
|
||||
notification.setInformativeText_(text)
|
||||
if sound:
|
||||
notification.setSoundName_("NSUserNotificationDefaultSoundName")
|
||||
if image:
|
||||
source_img = self.AppKit.NSImage.alloc().initByReferencingFile_(image)
|
||||
notification.setContentImage_(source_img)
|
||||
#notification.set_identityImage_(source_img)
|
||||
notification.setHasActionButton_(False)
|
||||
|
||||
notification_center = NSUserNotificationCenter.defaultUserNotificationCenter()
|
||||
|
||||
@@ -488,11 +488,15 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list,
|
||||
twitter.notify_download(pushmessage)
|
||||
|
||||
if headphones.CONFIG.OSX_NOTIFY_ENABLED:
|
||||
from headphones import cache
|
||||
c = cache.Cache()
|
||||
album_art = c.get_artwork_from_cache(None, release['AlbumID'])
|
||||
logger.info(u"Sending OS X notification")
|
||||
osx_notify = notifiers.OSX_NOTIFY()
|
||||
osx_notify.notify(release['ArtistName'],
|
||||
release['AlbumTitle'],
|
||||
statusmessage)
|
||||
statusmessage,
|
||||
image=album_art)
|
||||
|
||||
if headphones.CONFIG.BOXCAR_ENABLED:
|
||||
logger.info(u"Sending Boxcar2 notification")
|
||||
|
||||
@@ -932,9 +932,15 @@ def send_to_downloader(data, bestqual, album):
|
||||
pushalot = notifiers.PUSHALOT()
|
||||
pushalot.notify(name, "Download started")
|
||||
if headphones.CONFIG.OSX_NOTIFY_ENABLED and headphones.CONFIG.OSX_NOTIFY_ONSNATCH:
|
||||
from headphones import cache
|
||||
c = cache.Cache()
|
||||
album_art = c.get_artwork_from_cache(None, rgid)
|
||||
logger.info(u"Sending OS X notification")
|
||||
osx_notify = notifiers.OSX_NOTIFY()
|
||||
osx_notify.notify(artist, albumname, 'Snatched: ' + provider + '. ' + name)
|
||||
osx_notify.notify(artist,
|
||||
albumname,
|
||||
'Snatched: ' + provider + '. ' + name,
|
||||
image=album_art)
|
||||
if headphones.CONFIG.BOXCAR_ENABLED and headphones.CONFIG.BOXCAR_ONSNATCH:
|
||||
logger.info(u"Sending Boxcar2 notification")
|
||||
b2msg = 'From ' + provider + '<br></br>' + name
|
||||
|
||||
@@ -9,9 +9,7 @@ import subprocess
|
||||
def registerapp(app):
|
||||
|
||||
# don't do any of this unless >= 10.8
|
||||
v, _, _ = platform.mac_ver()
|
||||
v = float('.'.join(v.split('.')[:2]))
|
||||
if v < 10.8:
|
||||
if not [int(n) for n in platform.mac_ver()[0].split('.')] >= [10, 8]:
|
||||
return None, 'Registering requires OS X version >= 10.8'
|
||||
|
||||
app_path = None
|
||||
|
||||
Reference in New Issue
Block a user