Example #1
0
def play_video(params):
    log("play_video: params: %s" % params)
    get = params.get
    mode = get("mode")
    file_list = get("file_list")
    file_list = utils.unquote_plus(file_list).split(";")
    play_list = get("play_list")
    play_list = utils.unquote_plus(play_list).split(";")
    folder = get("folder")
    folder = utils.unquote_plus(folder)
    # We might have deleted the path
    if utils.exists_incomplete(folder):
        if len(file_list) > 0 and not play_list[1].endswith(play_list[0]):
            # we trick xbmc to play avi by creating empty rars if the download is only partial
            utils.write_fake(file_list, folder)
            # Prepare potential file stacking
            if (len(play_list) > 2):
                rar = []
                for arch_rar, movie_file in zip(play_list[0::2], play_list[1::2]):
                    raruri = "rar://" + utils.rarpath_fixer(folder, arch_rar) + "/" + movie_file
                    rar.append(raruri)
                    raruri = 'stack://' + ' , '.join(rar)
            else:
                raruri = "rar://" + utils.rarpath_fixer(folder, play_list[0]) + "/" + play_list[1]
            uri = raruri
        else:
            # we have a plain file
            if (len(play_list) > 2):
                uri = "stack://%s" % ' , '.join(play_list[1::2])
            else:
                uri = play_list[1]
        log("play_video: uri: %s" % uri)
        info = nfo.NfoLabels()
        item = xbmcgui.ListItem(info.info_labels['title'], iconImage='DefaultVideo.png', thumbnailImage=info.thumbnail)
        item.setInfo(type="Video", infoLabels=info.info_labels)
        item.setPath(uri)
        item.setProperty("IsPlayable", "true")
        xbmcplugin.setContent(HANDLE, 'movies')
        wait = 0
        player = xbmcplayer.XBMCPlayer(xbmc.PLAYER_CORE_AUTO)
        player.sleep(1000)
        if mode == MODE_AUTO_PLAY or mode == MODE_LIST_PLAY:
            player.play( uri, item )
            log("play_video: player.play uri: %s" % uri)
        else:
            xbmcplugin.setResolvedUrl(handle=HANDLE, succeeded=True, listitem=item)
            log("play_video: setResolvedUrl uri: %s" % uri)
        removed_fake = False
        while player.is_active:
            player.sleep(500)
            wait+= 1
            if player.is_playing and not removed_fake:
                utils.remove_fake(file_list, folder)
                removed_fake = True
            if player.is_stopped:
                the_end(folder, player.is_stopped, params.get("nzoid"), params.get("nzoidhistory"))
                player.is_active = False
            elif player.is_ended:
                time.sleep(1)
                log("rassi: player.is_ended, player.is_stopped %s" % player.is_stopped)
                the_end(folder, True, params.get("nzoid"), params.get("nzoidhistory"))
                player.is_active = False
            elif wait >= 6000 and not player.isPlayingVideo():
                utils.notification("Error playing file!")
                break
        if not removed_fake:
            utils.remove_fake(file_list, folder)
    else:
        utils.notification("File deleted")
        time.sleep(1)
        xbmc.executebuiltin("Action(ParentDir)")
    return
Example #2
0
def play_video(params):
    log("play_video: params: %s" % params)
    get = params.get
    mode = get("mode")
    file_list = get("file_list")
    file_list = utils.unquote_plus(file_list).split(";")
    play_list = get("play_list")
    play_list = utils.unquote_plus(play_list).split(";")
    folder = get("folder")
    folder = utils.unquote_plus(folder)
    # We might have deleted the path
    if utils.exists_incomplete(folder):
        if len(file_list) > 0 and not play_list[1].endswith(play_list[0]):
            # we trick xbmc to play avi by creating empty rars if the download is only partial
            utils.write_fake(file_list, folder)
            # Prepare potential file stacking
            if (len(play_list) > 2):
                rar = []
                for arch_rar, movie_file in zip(play_list[0::2], play_list[1::2]):
                    raruri = "rar://" + utils.rarpath_fixer(folder, arch_rar) + "/" + movie_file
                    rar.append(raruri)
                    raruri = 'stack://' + ' , '.join(rar)
            else:
                raruri = "rar://" + utils.rarpath_fixer(folder, play_list[0]) + "/" + play_list[1]
            uri = raruri
        else:
            # we have a plain file
            if (len(play_list) > 2):
                uri = "stack://%s" % ' , '.join(play_list[1::2])
            else:
                uri = play_list[1]
        log("play_video: uri: %s" % uri)
        info = nfo.NfoLabels()
        item = xbmcgui.ListItem(info.info_labels['title'], iconImage='DefaultVideo.png', thumbnailImage=info.thumbnail)
        item.setInfo(type="Video", infoLabels=info.info_labels)
        item.setPath(uri)
        item.setProperty("IsPlayable", "true")
        xbmcplugin.setContent(HANDLE, 'movies')
        wait = 0
        player = xbmcplayer.XBMCPlayer(xbmc.PLAYER_CORE_AUTO)
        player.sleep(1000)
        if mode == MODE_AUTO_PLAY or mode == MODE_LIST_PLAY:
            player.play( uri, item )
            log("play_video: player.play uri: %s" % uri)
        else:
            xbmcplugin.setResolvedUrl(handle=HANDLE, succeeded=True, listitem=item)
            log("play_video: setResolvedUrl uri: %s" % uri)
        removed_fake = False
        while player.is_active:
            player.sleep(500)
            wait+= 1
            if player.is_playing and not removed_fake:
                utils.remove_fake(file_list, folder)
                removed_fake = True
            if player.is_stopped:
                the_end(folder, player.is_stopped, params.get("nzoid"), params.get("nzoidhistory"))
                player.is_active = False
            elif player.is_ended:
                the_end(folder, False, params.get("nzoid"), params.get("nzoidhistory"))
                player.is_active = False
            elif wait >= 6000 and not player.isPlayingVideo():
                utils.notification("Error playing file!")
                break
        if not removed_fake:
            utils.remove_fake(file_list, folder)
    else:
        utils.notification("File deleted")
        time.sleep(1)
        xbmc.executebuiltin("Action(ParentDir)")
    return
Example #3
0
def is_nzb_home(params):
    log("is_nzb_home: params: %s" % params)
    get = params.get
    nzb = utils.unquote_plus(get("nzb"))
    nzbname = m_nzb.Nzbname(utils.unquote_plus(get("nzbname"))).final_name
    folder = utils.join(INCOMPLETE_FOLDER, os.path.join(nzbname, ''))
    iscanceled = False
    type = get('type', 'addurl')
    sab_nzo_id = sabnzbd.nzo_id(nzbname, nzb)
    log("is_nzb_home: folder: %s sab_nzo_id: %s" %(folder, sab_nzo_id))
    if sab_nzo_id is None:
        nzo_id = sabnzbd.nzo_id_history(nzbname)
    else:
        nzo_id = sab_nzo_id
    log("is_nzb_home: nzo_id: %s" % nzo_id)
    if not utils.dir_exists(folder, nzo_id):
        progressDialog = xbmcgui.DialogProgress()
        progressDialog.create('Pneumatic', 'Sending request to SABnzbd')
        category = get_category()
        # correct wrong type mode
        if nzb.startswith('http'):
            type = "addurl"
            log("is_nzb_home: type changed to addurl")
        elif type == 'addurl':
            type = 'add_file'
            log("is_nzb_home: type changed to add_file")
        if type == 'addurl':
            type, nzb = nzb_cache(type, nzb, nzbname)
        # SABnzbd and URI should be latin-1 encoded
        if type == 'addurl':
            response = sabnzbd.addurl(nzb.encode('latin-1'), nzbname, category=category)
        # add_local will not work on remote shares, thus add_file
        elif type == 'add_file' or type == 'add_local':
            response = sabnzbd.add_file(nzb.encode('latin-1'), category=category)
        log("is_nzb_home: type: %s response: %s" %(type, response))
        if "ok" in response:
            progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download')
            seconds = 0
            timer = 0
            #SABnzbd uses nzb url as name until it has downloaded the nzb file
            sab_nzo_id_init = sabnzbd.nzo_id(nzbname, nzb)
            log("is_nzb_home: sab_nzo_id_init: %s" % sab_nzo_id_init)
            while not (sab_nzo_id and utils.exists_incomplete(folder)):
                # Ask user what incomplete dir is right every 10s
                if timer > 9:
                    timer = 0
                    folder, nzbname = find_incomplete(folder, nzbname)
                sab_nzo_id = sabnzbd.nzo_id(nzbname)
                label = str(seconds) + " seconds"
                log("is_nzb_home: waiting for nzb: sab_nzo_id: %s for: %s" % (sab_nzo_id, label))
                progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download', label)
                if progressDialog.iscanceled():
                    progressDialog.close()
                    log("is_nzb_home: waiting for nzb: canceled")
                    # Fix for hang when playing .strm
                    time.sleep(1)
                    xbmc.Player().stop()
                    if sab_nzo_id is None and sab_nzo_id_init is not None:
                        sab_nzo_id = sab_nzo_id_init
                    #Trying to delete both the queue and history
                    if sab_nzo_id is not None:
                        pause = sabnzbd.nzo_pause(sab_nzo_id)
                        #log("rassi pause")
                        log("is_nzb_home: pause: sab_nzo_id: %s msg: %s" % (sab_nzo_id, pause))
                        time.sleep(3)
                        #log("rassi before delete")
                        delete_msg = sabnzbd.nzo_delete_files(sab_nzo_id)
                        log("is_nzb_home: delete_queue: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg))
                        if not "ok" in delete_msg:
                            delete_msg = sabnzbd.nzo_delete_history_files(sab_nzo_id)
                            log("is_nzb_home: delete_history: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg))
                        #log("rassi after delete")
                    else:
                        log("is_nzb_home: failed removing %s from the queue" % nzbname)
                    iscanceled = True
                    break
                time.sleep(1)
                seconds += 1
                timer += 1
            if not iscanceled:
                switch = sabnzbd.nzo_switch(sab_nzo_id, 0).replace('\n', '')
                log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch))
                if not "0" in switch:
                    progressDialog.update(0, 'Failed to prioritize the nzb!')
                    time.sleep(1)
                # Dont add meta data for local nzb's
                if type == 'addurl':
                    t = Thread(target=save_nfo, args=(folder,))
                    t.start()
                progressDialog.close()
                return True, sab_nzo_id
            else:
                progressDialog.close()
                return False, sab_nzo_id
        else:
            progressDialog.close()
            log("is_nzb_home: failed adding nzb to SAB")
            # Fix for hang when playing .strm
            xbmc.Player().stop()            
            utils.notification("Request to SABnzbd failed!")
            return False, sab_nzo_id
    else:
        switch = sabnzbd.nzo_switch(sab_nzo_id, 0).replace('\n', '')
        log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch))
        if not "0" in switch:
            utils.notification("Failed to prioritize the nzb!")
        # TODO make sure there is also a NZB in the queue
        return True, sab_nzo_id
Example #4
0
def is_nzb_home(params):
    log("is_nzb_home: params: %s" % params)
    get = params.get
    nzb = utils.unquote_plus(get("nzb"))
    nzbname = m_nzb.Nzbname(utils.unquote_plus(get("nzbname"))).final_name
    folder = utils.join(INCOMPLETE_FOLDER, os.path.join(nzbname, ''))
    iscanceled = False
    type = get('type', 'addurl')
    sab_nzo_id = sabnzbd.nzo_id(nzbname, nzb)
    log("is_nzb_home: folder: %s sab_nzo_id: %s" %(folder, sab_nzo_id))
    if sab_nzo_id is None:
        nzo_id = sabnzbd.nzo_id_history(nzbname)
    else:
        nzo_id = sab_nzo_id
    log("is_nzb_home: nzo_id: %s" % nzo_id)
    if not utils.dir_exists(folder, nzo_id):
        progressDialog = xbmcgui.DialogProgress()
        progressDialog.create('Pneumatic', 'Sending request to SABnzbd')
        category = get_category()
        # correct wrong type mode
        if nzb.startswith('http'):
            type = "addurl"
            log("is_nzb_home: type changed to addurl")
        elif type == 'addurl':
            type = 'add_file'
            log("is_nzb_home: type changed to add_file")
        if type == 'addurl':
            type, nzb = nzb_cache(type, nzb, nzbname)
        # SABnzbd and URI should be latin-1 encoded
        if type == 'addurl':
            response = sabnzbd.addurl(nzb.encode('latin-1'), nzbname, category=category)
        # add_local will not work on remote shares, thus add_file
        elif type == 'add_file' or type == 'add_local':
            response = sabnzbd.add_file(nzb.encode('latin-1'), category=category)
        log("is_nzb_home: type: %s response: %s" %(type, response))
        if "ok" in response:
            progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download')
            seconds = 0
            timer = 0
            #SABnzbd uses nzb url as name until it has downloaded the nzb file
            sab_nzo_id_init = sabnzbd.nzo_id(nzbname, nzb)
            log("is_nzb_home: sab_nzo_id_init: %s" % sab_nzo_id_init)
            while not (sab_nzo_id and utils.exists_incomplete(folder)):
                # Ask user what incomplete dir is right every 10s
                if timer > 9:
                    timer = 0
                    folder, nzbname = find_incomplete(folder, nzbname)
                sab_nzo_id = sabnzbd.nzo_id(nzbname)
                label = str(seconds) + " seconds"
                log("is_nzb_home: waiting for nzb: sab_nzo_id: %s for: %s" % (sab_nzo_id, label))
                progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download', label)
                if progressDialog.iscanceled():
                    progressDialog.close()
                    log("is_nzb_home: waiting for nzb: canceled")
                    # Fix for hang when playing .strm
                    time.sleep(1)
                    xbmc.Player().stop()
                    if sab_nzo_id is None and sab_nzo_id_init is not None:
                        sab_nzo_id = sab_nzo_id_init
                    #Trying to delete both the queue and history
                    if sab_nzo_id is not None:
                        pause = sabnzbd.nzo_pause(sab_nzo_id)
                        log("is_nzb_home: pause: sab_nzo_id: %s msg: %s" % (sab_nzo_id, pause))
                        time.sleep(3)
                        delete_msg = sabnzbd.nzo_delete_files(sab_nzo_id)
                        log("is_nzb_home: delete_queue: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg))
                        if not "ok" in delete_msg:
                            delete_msg = sabnzbd.nzo_delete_history_files(sab_nzo_id)
                            log("is_nzb_home: delete_history: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg))
                    else:
                        log("is_nzb_home: failed removing %s from the queue" % nzbname)
                    iscanceled = True
                    break
                time.sleep(1)
                seconds += 1
                timer += 1
            if not iscanceled:
                switch = sabnzbd.nzo_switch(sab_nzo_id, 0).replace('\n', '')
                log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch))
                if not "0" in switch:
                    progressDialog.update(0, 'Failed to prioritize the nzb!')
                    time.sleep(1)
                # Dont add meta data for local nzb's
                if type == 'addurl':
                    t = Thread(target=save_nfo, args=(folder,))
                    t.start()
                progressDialog.close()
                return True, sab_nzo_id
            else:
                progressDialog.close()
                return False, sab_nzo_id
        else:
            progressDialog.close()
            log("is_nzb_home: failed adding nzb to SAB")
            # Fix for hang when playing .strm
            xbmc.Player().stop()            
            utils.notification("Request to SABnzbd failed!")
            return False, sab_nzo_id
    else:
        switch = sabnzbd.nzo_switch(sab_nzo_id, 0).replace('\n', '')
        log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch))
        if not "0" in switch:
            utils.notification("Failed to prioritize the nzb!")
        # TODO make sure there is also a NZB in the queue
        return True, sab_nzo_id