Ejemplo n.º 1
0
    def cleanLibrary(self,media_type):
        #check if we should verify paths
        if(utils.getSetting("verify_paths") == 'true'):
            response = eval(xbmc.executeJSONRPC('{ "jsonrpc" : "2.0", "method" : "Files.GetSources", "params":{"media":"' + media_type + '"}, "id": 1}'))

            if(response.has_key('error')):
                utils.log("Error " + response['error']['data']['method'] + " - " + response['error']['message'],xbmc.LOGDEBUG)
                return
            
            for source in response['result']['sources']:
                if not self._sourceExists(source['file']):
                    #let the user know this failed, if they subscribe to notifications
                    if(utils.getSetting('notify_next_run') == 'true'):
                        utils.showNotification(utils.getString(30050),"Source " + source['label'] + " does not exist")

                    utils.log("Path " + source['file'] + " does not exist")
                    return

        #also check if we should verify with user first
        if(utils.getSetting('user_confirm_clean') == 'true'):
            #user can decide 'no' here and exit this
            runClean = xbmcgui.Dialog().yesno(utils.getString(30000),utils.getString(30052),utils.getString(30053))
            if(not runClean):
                return
                
        #run the clean operation
        utils.log("Cleaning Database")
        xbmc.executebuiltin("CleanLibrary(" + media_type + ")")

        #write last run time, will trigger notifications
        self.writeLastRun()
Ejemplo n.º 2
0
    def start(self):
        while(not xbmc.abortRequested):
            current_enabled = utils.getSetting("enable_scheduler")
            
            if(current_enabled == "true" and self.enabled == "false"):
                #scheduler was just turned on
                self.enabled = current_enabled
                self.setup()
            elif (current_enabled == "false" and self.enabled == "true"):
                #schedule was turn off
                self.enabled = current_enabled
            elif(self.enabled == "true"):
                #scheduler is still on
                now = time.time()

                if(self.next_run <= now):
                    if(utils.getSetting('run_silent') == 'false'):
                        utils.showNotification(utils.getString(30053))
                    #run the job in backup mode, hiding the dialog box
                    backup = XbmcBackup()
                    backup.run(XbmcBackup.Backup,True)
                    
                self.findNextRun(now)

            time.sleep(10)
    def findNextRun(self, now):
        progress_mode = int(utils.getSetting('progress_mode'))

        #find the cron expression and get the next run time
        cron_exp = self.parseSchedule()

        cron_ob = croniter(cron_exp, datetime.datetime.fromtimestamp(now))
        new_run_time = cron_ob.get_next(float)

        if (new_run_time != self.next_run):
            self.next_run = new_run_time
            utils.log("scheduler will run again on " +
                      datetime.datetime.fromtimestamp(self.next_run).strftime(
                          '%m-%d-%Y %H:%M'))

            #write the next time to a file
            fh = xbmcvfs.File(self.next_run_path, 'w')
            fh.write(str(self.next_run))
            fh.close()

            #only show when not in silent mode
            if (progress_mode != 2):
                utils.showNotification(
                    utils.getString(30081) + " " +
                    datetime.datetime.fromtimestamp(self.next_run).strftime(
                        '%m-%d-%Y %H:%M'))
Ejemplo n.º 4
0
    def cleanLibrary(self,media_type):
        #check if we should verify paths
        if(utils.getSetting("verify_paths") == 'true'):
            response = eval(xbmc.executeJSONRPC('{ "jsonrpc" : "2.0", "method" : "Files.GetSources", "params":{"media":"' + media_type + '"}, "id": 1}'))

            if(response.has_key('error')):
                utils.log("Error " + response['error']['data']['method'] + " - " + response['error']['message'],xbmc.LOGDEBUG)
                return
            
            for source in response['result']['sources']:
                if not self._sourceExists(source['file']):
                    #let the user know this failed, if they subscribe to notifications
                    if(utils.getSetting('notify_next_run') == 'true'):
                        utils.showNotification(utils.getString(30050),"Source " + source['label'] + " does not exist")

                    utils.log("Path " + source['file'] + " does not exist")
                    return

        #also check if we should verify with user first
        if(utils.getSetting('user_confirm_clean') == 'true'):
            #user can decide 'no' here and exit this
            runClean = xbmcgui.Dialog().yesno(utils.getString(30000),utils.getString(30052),utils.getString(30053))
            if(not runClean):
                return
                
        #run the clean operation
        utils.log("Cleaning Database")
        xbmc.executebuiltin("CleanLibrary(" + media_type + ")")

        #write last run time, will trigger notifications
        self.writeLastRun()
Ejemplo n.º 5
0
    def start(self):

        #check if a backup should be resumed
        resumeRestore = self._resumeCheck()

        if(resumeRestore):
            restore = XbmcBackup()
            restore.selectRestore(self.restore_point)
            #skip the advanced settings check
            restore.skipAdvanced()
            restore.run(XbmcBackup.Restore)
        
        while(not xbmc.abortRequested):
            
            if(self.enabled == "true"):
                #scheduler is still on
                now = time.time()

                if(self.next_run <= now):
                    if(utils.getSetting('run_silent') == 'false'):
                        utils.showNotification(utils.getString(30053))
                    #run the job in backup mode, hiding the dialog box
                    backup = XbmcBackup()
                    backup.run(XbmcBackup.Backup,True)

                    #check if we should shut the computer down
                    if(utils.getSetting("cron_shutdown") == 'true'):
                        #wait 10 seconds to make sure all backup processes and files are completed
                        time.sleep(10)
                        xbmc.executebuiltin('ShutDown()')
                    else:
                        #find the next run time like normal
                        self.findNextRun(now)

            xbmc.sleep(500)
Ejemplo n.º 6
0
 def findNextRun(self,now):
     #find the cron expression and get the next run time
     cron_exp = self.parseSchedule()
     cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now))
     new_run_time = cron_ob.get_next(float)
     # utils.log('new run time' +  str(new_run_time))
     # utils.log('next run time' + str(self.next_run))
     if(new_run_time != self.next_run):
         self.next_run = new_run_time
         utils.showNotification('EPG Updater', 'Next Update: ' + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
         utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
Ejemplo n.º 7
0
    def start(self):

        #check if a backup should be resumed
        resumeRestore = self._resumeCheck()

        if (resumeRestore):
            restore = XbmcBackup()
            restore.selectRestore(self.restore_point)
            #skip the advanced settings check
            restore.skipAdvanced()
            restore.run(XbmcBackup.Restore)

        while (not xbmc.abortRequested):

            if (self.enabled == "true"):
                #scheduler is still on
                now = time.time()

                if (self.next_run <= now):
                    progress_mode = int(utils.getSetting('progress_mode'))
                    if (progress_mode != 2):
                        utils.showNotification(utils.getString(30053))

                    backup = XbmcBackup()

                    if (backup.remoteConfigured()):

                        if (int(utils.getSetting('progress_mode')) in [0, 1]):
                            backup.run(XbmcBackup.Backup, True)
                        else:
                            backup.run(XbmcBackup.Backup, False)

                        #check if this is a "one-off"
                        if (int(utils.getSetting("schedule_interval")) == 0):
                            #disable the scheduler after this run
                            self.enabled = "false"
                            utils.setSetting('enable_scheduler', 'false')
                    else:
                        utils.showNotification(utils.getString(30045))

                    #check if we should shut the computer down
                    if (utils.getSetting("cron_shutdown") == 'true'):
                        #wait 10 seconds to make sure all backup processes and files are completed
                        time.sleep(10)
                        xbmc.executebuiltin('ShutDown()')
                    else:
                        #find the next run time like normal
                        self.findNextRun(now)

            xbmc.sleep(500)

        #delete monitor to free up memory
        del self.monitor
Ejemplo n.º 8
0
    def start(self):

        #check if a backup should be resumed
        resumeRestore = self._resumeCheck()

        if(resumeRestore):
            restore = XbmcBackup()
            restore.selectRestore(self.restore_point)
            #skip the advanced settings check
            restore.skipAdvanced()
            restore.run(XbmcBackup.Restore)
        
        while(not xbmc.abortRequested):
            
            if(self.enabled == "true"):
                #scheduler is still on
                now = time.time()

                if(self.next_run <= now):
                    progress_mode = int(utils.getSetting('progress_mode'))
                    if(progress_mode != 2):
                        utils.showNotification(utils.getString(30053))
                    
                    backup = XbmcBackup()

                    if(backup.remoteConfigured()):

                        if(int(utils.getSetting('progress_mode')) in [0,1]):
                            backup.run(XbmcBackup.Backup,True)
                        else:
                            backup.run(XbmcBackup.Backup,False)

                        #check if this is a "one-off"
                        if(int(utils.getSetting("schedule_interval")) == 0):
                            #disable the scheduler after this run
                            self.enabled = "false"
                            utils.setSetting('enable_scheduler','false')
                    else:
                        utils.showNotification(utils.getString(30045))
                        
                    #check if we should shut the computer down
                    if(utils.getSetting("cron_shutdown") == 'true'):
                        #wait 10 seconds to make sure all backup processes and files are completed
                        time.sleep(10)
                        xbmc.executebuiltin('ShutDown()')
                    else:
                        #find the next run time like normal
                        self.findNextRun(now)

            xbmc.sleep(500)

        #delete monitor to free up memory
        del self.monitor
Ejemplo n.º 9
0
    def showNotify(self,displayToScreen = True):
        #go through and find the next schedule to run
        next_run_time = CronSchedule()
        for cronJob in self.schedules:
            if(cronJob.next_run < next_run_time.next_run or next_run_time.next_run == 0):
                next_run_time = cronJob

        inWords = self.nextRunCountdown(next_run_time.next_run)
        #show the notification (if applicable)
        if(next_run_time.next_run > time.time() and utils.getSetting('notify_next_run') == 'true' and displayToScreen == True):
            utils.showNotification(utils.getString(30000),next_run_time.name + " - " + inWords)
                                   
        return inWords    
Ejemplo n.º 10
0
    def showNotify(self,displayToScreen = True):
        #go through and find the next schedule to run
        next_run_time = CronSchedule()
        for cronJob in self.schedules:
            if(cronJob.next_run < next_run_time.next_run or next_run_time.next_run == 0):
                next_run_time = cronJob

        inWords = self.nextRunCountdown(next_run_time.next_run)
        #show the notification (if applicable)
        if(next_run_time.next_run > time.time() and utils.getSetting('notify_next_run') == 'true' and displayToScreen == True):
            utils.showNotification(utils.getString(30000),next_run_time.name + " - " + inWords)
                                   
        return inWords    
Ejemplo n.º 11
0
    def findNextRun(self, now):
        #find the cron expression and get the next run time
        cron_exp = self.parseSchedule()

        cron_ob = croniter(cron_exp, datetime.datetime.fromtimestamp(now))
        new_run_time = cron_ob.get_next(float)

        if (new_run_time != self.next_run):
            self.next_run = new_run_time
            utils.showNotification(
                utils.getString(30081) + " " + datetime.datetime.fromtimestamp(
                    self.next_run).strftime('%m-%d-%Y %H:%M'))
            utils.log("scheduler will run again on " +
                      datetime.datetime.fromtimestamp(self.next_run).strftime(
                          '%m-%d-%Y %H:%M'))
    def doScheduledBackup(self, progress_mode):
        if (progress_mode != 2):
            utils.showNotification(utils.getString(30053))

        backup = XbmcBackup()

        if (backup.remoteConfigured()):

            if (int(utils.getSetting('progress_mode')) in [0, 1]):
                backup.run(XbmcBackup.Backup, True)
            else:
                backup.run(XbmcBackup.Backup, False)

            #check if this is a "one-off"
            if (int(utils.getSetting("schedule_interval")) == 0):
                #disable the scheduler after this run
                self.enabled = "false"
                utils.setSetting('enable_scheduler', 'false')
        else:
            utils.showNotification(utils.getString(30045))
Ejemplo n.º 13
0
 def doScheduledBackup(self,progress_mode):
     if(progress_mode != 2):
         utils.showNotification(utils.getString(30053))
     
     backup = XbmcBackup()
     
     if(backup.remoteConfigured()):
         
         if(int(utils.getSetting('progress_mode')) in [0,1]):
             backup.run(XbmcBackup.Backup,True)
         else:
             backup.run(XbmcBackup.Backup,False)
         
         #check if this is a "one-off"
         if(int(utils.getSetting("schedule_interval")) == 0):
             #disable the scheduler after this run
             self.enabled = "false"
             utils.setSetting('enable_scheduler','false')
     else:
         utils.showNotification(utils.getString(30045))
Ejemplo n.º 14
0
    def findNextRun(self,now):
        progress_mode = int(utils.getSetting('progress_mode'))
        
        #find the cron expression and get the next run time
        cron_exp = self.parseSchedule()

        cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now))
        new_run_time = cron_ob.get_next(float)

        if(new_run_time != self.next_run):
            self.next_run = new_run_time
            utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))

            #write the next time to a file
            fh = xbmcvfs.File(self.next_run_path, 'w')
            fh.write(str(self.next_run))
            fh.close()

            #only show when not in silent mode
            if(progress_mode != 2):                        
                utils.showNotification(utils.getString(30081) + " " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
Ejemplo n.º 15
0
    def updateM3u(self):
        if self.rocketstreams_addon is None:
            utils.log("rocketstreams addon missing")
            return
        if self.pvriptvsimple_addon is None:
            utils.log("pvriptvsimple addon missing")
            return

        utils.log("Updating m3u file")
        username = self.rocketstreams_addon.getSetting('kasutajanimi')
        password = self.rocketstreams_addon.getSetting('salasona')
        updater_path = os.path.join(xbmc.translatePath('special://userdata'),
                                    'addon_data/plugin.video.rocketstreams')

        cm_path = os.path.join(
            xbmc.translatePath('special://home'),
            'addons/service.rocketstreamsEpgUpdate/channel_guide_map.txt')

        channel_map = {}
        if os.path.isfile(cm_path):
            utils.log('Adding mapped guide ids')
            with open(cm_path) as f:
                for line in f:
                    channel_name, guide_id = line.rstrip().split("\t")
                    channel_map[channel_name] = guide_id

        panel_url = "http://stream-two.doc123.nl:8000/panel_api.php?username={0}&password={1}".format(
            username, password)
        u = urllib2.urlopen(panel_url)
        j = json.loads(u.read())

        if j['user_info']['auth'] == 0:
            utils.showNotification("EPG Updater",
                                   "Error: Couldn't login to rocketstreams")
            self.enabled = False
            utils.setSetting("enable_scheduler", "False")
            return

        Channel = namedtuple(
            'Channel',
            ['tvg_id', 'tvg_name', 'tvg_logo', 'group_title', 'channel_url'])
        channels = []

        group_idx = {}
        for idx, group in enumerate(self.groups):
            group_idx[group] = idx

        for ts_id, info in j["available_channels"].iteritems():
            channel_url = "http://stream-two.doc123.nl:8000/live/{0}/{1}/{2}.ts".format(
                username, password, ts_id)
            tvg_id = ""
            tvg_name = info['name']
            if tvg_name.endswith(' - NEW'):
                tvg_name = tvg_name[:-6]
            #if info['epg_channel_id'] and info['epg_channel_id'].endswith(".com"):
            #    tvg_id = info['epg_channel_id']
            if tvg_name in channel_map:
                tvg_id = 'tvg-id="{0}"'.format(channel_map[tvg_name])
            else:
                tvg_id = ""
            tvg_id = ""
            tvg_logo = ""
            #if info['stream_icon']:
            #  tvg_logo = info['stream_icon']
            group_title = info['category_name']
            if group_title == None:
                group_title = 'None'
            channels.append(
                Channel(tvg_id, tvg_name, tvg_logo, group_title, channel_url))

        wanted_channels = [c for c in channels if c.group_title in self.groups]
        wanted_channels.sort(key=lambda c: "{0}-{1}".format(
            group_idx[c.group_title], c.tvg_name))

        with open("{0}/rocketstreams.m3u".format(updater_path), "w") as m3u_f:
            m3u_f.write("#EXTM3U\n")
            for c in wanted_channels:
                m3u_f.write(
                    '#EXTINF:-1 tvg-name="{0}" {1} tvg-logo="{2}" group-title="{3}",{0}\n{4}\n'
                    .format(c.tvg_name, c.tvg_id, c.tvg_logo, c.group_title,
                            c.channel_url))

        self.checkAndUpdatePVRIPTVSetting("epgCache", "false")
        self.checkAndUpdatePVRIPTVSetting("epgPathType", "0")
        self.checkAndUpdatePVRIPTVSetting(
            "epgPath", updater_path + '/rocketstreams_xmltv.xml.gz')
        self.checkAndUpdatePVRIPTVSetting("m3uPathType", "0")
        self.checkAndUpdatePVRIPTVSetting(
            "m3uPath", "{0}/rocketstreams.m3u".format(updater_path))
Ejemplo n.º 16
0
            utils.exitFailed('MakeMKV {failed}'.format(
                    failed = utils.getString(30059)), e.output)
    utils.logDebug(ripoutput)

    # Eject if we need to
    # 30027 == Rip
    if profiledict['ejectafter'] == utils.getStringLow(30027):
        xbmc.executebuiltin('EjectTray()')

    # Display notification/dialog if we need to. A notification is a
    # toast that auto-dismisses after a few seconds, whereas a dialog
    # requires the user to press ok.
    # 30065 == Notification
    if profiledict['notifyafterrip'] == utils.getStringLow(30065):
        utils.showNotification('{rip} {completedsuccessfully}'.format(
                rip = utils.getString(30027),
                completedsuccessfully = utils.getString(30058)))
    # 30066 == Dialog
    elif profiledict['notifyafterrip'] == utils.getStringLow(30066):
        utils.showOK('{rip} {completedsuccessfully}'.format(
                rip = utils.getString(30027),
                completedsuccessfully = utils.getString(30058)))

    # Some people may want to just rip movies, and not encode them.
    # If that's the case, we are done here.
    if profiledict['encodeafterrip'] == 'false':
        return 0

    filestoencode = glob.glob(os.path.join(profiledict['tempfolder'], '*.mkv'))
    for f in filestoencode:
        command = buildHandBrakeCLICommand(profiledict, f)
Ejemplo n.º 17
0
__remotedebug__ = False
# append pydev remote debugger
if __remotedebug__:
    utils.log("Initialize remote debugging.")
    # Make pydev debugger works for auto reload.
    try:
        import pydevd
        pydevd.settrace('localhost',
                        port=60678,
                        stdoutToServer=True,
                        stderrToServer=True)
    except ImportError:
        sys.stderr.write(
            "Error: " +
            "You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
        utils.showNotification('WatchedList Error',
                               'remote debug could not be imported.')
        sys.exit(1)
    except:
        utils.showNotification(
            'WatchedList Error',
            'remote debug in pydev is activated, but remote server not responding.'
        )
        sys.exit(1)

# Create WatchedList Class
WL = WatchedList()

if (not utils.getSetting("autostart") == 'true') or xbmcgui.Dialog().yesno(
        utils.getString(32101), utils.getString(32001)):
    # Check if we should run updates (only ask if autostart is on)
    # run the program
Ejemplo n.º 18
0
            pointNames = []
            folderNames = []
            
            for aDir in restorePoints:
                pointNames.append(aDir[1])
                folderNames.append(aDir[0])

            selectedRestore = -1

            if("archive" in params):
                #check that the user give archive exists
                if(params['archive'] in folderNames):
                    #set the index
                    selectedRestore = folderNames.index(params['archive'])
                    utils.log(str(selectedRestore) + " : " + params['archive'])
                else:
                    utils.showNotification(utils.getString(30045))
                    utils.log(params['archive'] + ' is not a valid restore point')
            else:
                #allow user to select the backup to restore from
                selectedRestore = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30021),pointNames)

            if(selectedRestore != -1):
                backup.selectRestore(restorePoints[selectedRestore][0])
                    
        backup.run(mode)
    else:
        #can't go any further
        xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045))
        utils.openSettings()
Ejemplo n.º 19
0
"""
This file is entry point for automatic start via XBMC
"""

import resources.lib.utils as utils
from service import WatchedList
import xbmc

__remotedebug__ = False
# Append pydev remote debugger
if __remotedebug__:
    utils.log("Initialize remote debugging.")
    # Make pydev debugger works for auto reload.
    try:
        import pydevd
        pydevd.settrace('localhost', port=60678, stdoutToServer=True, stderrToServer=True)
    except ImportError:
        sys.stderr.write("Error: " +
            "You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
        utils.showNotification('WatchedList Error', 'remote debug could not be imported.')
        sys.exit(1)
    except:
        utils.showNotification('WatchedList Error', 'remote debug in pydev is activated, but remote server not responding.')
        sys.exit(1)

# Run the program
xbmc.sleep(1500) # wait 1.5 seconds to prevent import-errors
utils.log("WatchedList Database Service starting...")
WatchedList().runProgram()
            folderNames = []

            for aDir in restorePoints:
                pointNames.append(aDir[1])
                folderNames.append(aDir[0])

            selectedRestore = -1

            if ("archive" in params):
                #check that the user give archive exists
                if (params['archive'] in folderNames):
                    #set the index
                    selectedRestore = folderNames.index(params['archive'])
                    utils.log(str(selectedRestore) + " : " + params['archive'])
                else:
                    utils.showNotification(utils.getString(30045))
                    utils.log(params['archive'] +
                              ' is not a valid restore point')
            else:
                #allow user to select the backup to restore from
                selectedRestore = xbmcgui.Dialog().select(
                    utils.getString(30010) + " - " + utils.getString(30021),
                    pointNames)

            if (selectedRestore != -1):
                backup.selectRestore(restorePoints[selectedRestore][0])

        backup.run(mode)
    else:
        #can't go any further
        xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30045))
Ejemplo n.º 21
0
            utils.exitFailed('MakeMKV {failed}'.format(
                    failed = utils.getString(30059)), e.output)
    utils.logDebug(ripoutput)

    # Eject if we need to
    # 30027 == Rip
    if profiledict['ejectafter'] == utils.getStringLow(30027):
        xbmc.executebuiltin('EjectTray()')

    # Display notification/dialog if we need to. A notification is a
    # toast that auto-dismisses after a few seconds, whereas a dialog
    # requires the user to press ok.
    # 30065 == Notification
    if profiledict['notifyafterrip'] == utils.getStringLow(30065):
        utils.showNotification('{rip} {completedsuccessfully}'.format(
                rip = utils.getString(30027),
                completedsuccessfully = utils.getString(30058)))
    # 30066 == Dialog
    elif profiledict['notifyafterrip'] == utils.getStringLow(30066):
        utils.showOK('{rip} {completedsuccessfully}'.format(
                rip = utils.getString(30027),
                completedsuccessfully = utils.getString(30058)))

    # Some people may want to just rip movies, and not encode them.
    # If that's the case, we are done here.
    if profiledict['encodeafterrip'] == 'false':
        return 0

    filestoencode = glob.glob(os.path.join(profiledict['tempfolder'], '*.mkv'))
    for f in filestoencode:
        # makemkvcon doesn't allow to customize the output filename