Пример #1
0
def pre_play(nzbname, **kwargs):
    log("pre_play: nzbname: %s kwargs: %s" % (nzbname, kwargs))
    mode = kwargs.get('mode', None)
    sab_nzo_id = kwargs.get('nzo', None)
    iscanceled = False
    folder = utils.join(INCOMPLETE_FOLDER, nzbname)
    folder_one = folder + '.1'
    if utils.exists(folder_one):
        folder = folder_one
    sab_file_list = []
    multi_arch_list = []
    if sab_nzo_id is None:
        sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname)
        nzf_list = utils.dir_to_nzf_list(folder, sabnzbd)
    else:
        nzo = sabnzbd.Nzo(SABNZBD, sab_nzo_id)
        nzf_list = nzo.nzf_list()
        sab_nzo_id_history = None
    sorted_rar_nzf_list = utils.sorted_rar_nzf_file_list(nzf_list)
    # TODO
    # If we cant find any rars in the queue, we have to wait for SAB
    # and then guess the names...
    # if len(nzf_list) == 0:
        # iscanceled = get_nzf(folder, sab_nzo_id, None)
    is_movie_in_rar = True
    if len(sorted_rar_nzf_list) == 0:
        # look for other playable files
        multi_nzf_list = sorted_nzf_list = utils.sorted_movie_nzf_file_list(nzf_list)
        if len(multi_nzf_list) > 0:
            is_movie_in_rar = False
    else:
        multi_nzf_list = utils.sorted_multi_arch_nzf_list(sorted_rar_nzf_list)
        sorted_nzf_list = sorted_rar_nzf_list
        clean_sorted_nzf_list = utils.nzf_diff_list(sorted_nzf_list, multi_nzf_list)
    if len(multi_nzf_list) > 0:
        # Loop though all multi archives and add file to the 
        play_list = []
        for nzf in multi_nzf_list:
            if sab_nzo_id is not None:
                response = set_streaming(sab_nzo_id)
                log("pre_play: set_streaming: %s" % response)
                t = Thread(target=nzf_to_bottom, args=(sab_nzo_id, nzf_list, sorted_nzf_list,))
                t.start()
                iscanceled = get_nzf(folder, sab_nzo_id, nzf)
            if iscanceled:
                break
            else:
                if is_movie_in_rar:
                    # RAR ANALYSYS #
                    in_rar_file_list = utils.rar_filenames(folder, nzf.filename)
                    movie_list = utils.sort_filename(in_rar_file_list)
                    log("pre_play: folder: %s nzf.filename: %s in_rar_file_list: %s" % (folder, nzf.filename, in_rar_file_list))
                else:
                    movie_list = [os.path.join(folder, nzf.filename)]
                # Make sure we have a movie
                if not (len(movie_list) >= 1):
                    utils.notification("Not a movie!")
                    log("pre_play: no movie in movie_list")
                    break
                # Who needs sample?
                movie_no_sample_list = utils.no_sample_list(movie_list)
                # If auto play is enabled we skip samples in the play_list
                if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST:
                    for movie_file in movie_no_sample_list:
                        play_list.append(nzf.filename)
                        play_list.append(movie_file)
                else:
                    for movie_file in movie_list:
                        play_list.append(nzf.filename)
                        play_list.append(movie_file)
                # If the movie is a .mkv or .mp4 we need the last rar
                if utils.is_movie_mkv(movie_list) and sab_nzo_id and is_movie_in_rar:
                    # If we have a sample or other file, the second rar is also needed..
                    if len(in_rar_file_list) > 1:
                        second_nzf = clean_sorted_nzf_list[1]
                        iscanceled = get_nzf(folder, sab_nzo_id, second_nzf)
                    last_nzf = clean_sorted_nzf_list[-1]
                    iscanceled =  get_nzf(folder, sab_nzo_id, last_nzf)
                    if iscanceled: 
                        break 
        if iscanceled:
            log("pre_play: get_nzf: canceled")
            return
        else:
            rar_file_list = [x.filename for x in sorted_nzf_list]
            if (len(rar_file_list) >= 1) or (not is_movie_in_rar and len(movie_list) >= 1):
                if AUTO_PLAY and ( mode is None or mode is MODE_STRM):
                    video_params = dict()
                    if not mode:
                        video_params['mode'] = MODE_AUTO_PLAY
                    else:
                        video_params['mode'] = MODE_STRM
                    video_params['play_list'] = utils.quote_plus(';'.join(play_list))
                    video_params['file_list'] = utils.quote_plus(';'.join(rar_file_list))
                    video_params['folder'] = utils.quote_plus(folder)
                    return play_video(video_params)   
                else:
                    return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history)
            else:
                utils.notification("No rar\'s in the NZB!")
                log("pre_play: no rar\'s in the NZB")
                return
    else:
        utils.notification("No playable files found!")
        log("pre_play: no playable files found")
        return
Пример #2
0
def pre_play(nzbname, **kwargs):
    log("pre_play: nzbname: %s kwargs: %s" % (nzbname, kwargs))
    mode = kwargs.get('mode', None)
    sab_nzo_id = kwargs.get('nzo', None)
    iscanceled = False
    folder = utils.join(INCOMPLETE_FOLDER, os.path.join(nzbname, ''))
    folder_one = folder + '.1'
    if utils.exists(os.path.join(folder_one, '')):
        folder = folder_one
    if sab_nzo_id is None:
        sab_nzo_id_history = sabnzbd.nzo_id_history(nzbname)
        nzf_list = utils.dir_to_nzf_list(folder)
    else:
        nzo = Nzo(sab_nzo_id)
        nzf_list = nzo.nzf_list()
        sab_nzo_id_history = None
    sorted_rar_nzf_list = utils.sorted_rar_nzf_file_list(nzf_list)
    # TODO
    # If we cant find any rars in the queue, we have to wait for SAB
    # and then guess the names...
    # if len(nzf_list) == 0:
        # iscanceled = get_nzf(folder, sab_nzo_id, None)
    is_movie_in_rar = True
    if len(sorted_rar_nzf_list) == 0:
        # look for other playable files
        multi_nzf_list = sorted_nzf_list = utils.sorted_movie_nzf_file_list(nzf_list)
        if len(multi_nzf_list) > 0:
            is_movie_in_rar = False
    else:
        multi_nzf_list = utils.sorted_multi_arch_nzf_list(sorted_rar_nzf_list)
        sorted_nzf_list = sorted_rar_nzf_list
        clean_sorted_nzf_list = utils.nzf_diff_list(sorted_nzf_list, multi_nzf_list)
    if len(multi_nzf_list) > 0:
        # Loop though all multi archives and add file to the 
        play_list = []
        for nzf in multi_nzf_list:
            if sab_nzo_id is not None:
                response = set_streaming(sab_nzo_id)
                log("pre_play: set_streaming: %s" % response)
                t = Thread(target=nzf_to_bottom, args=(sab_nzo_id, nzf_list, sorted_nzf_list,))
                t.start()
                iscanceled = get_nzf(folder, sab_nzo_id, nzf)
            if iscanceled:
                break
            else:
                if is_movie_in_rar:
                    # RAR ANALYSYS #
                    in_rar_file_list = utils.rar_filenames(folder, nzf.filename)
                    movie_list = utils.sort_filename(in_rar_file_list)
                    log("pre_play: folder: %s nzf.filename: %s in_rar_file_list: %s" % (folder, nzf.filename, in_rar_file_list))
                else:
                    movie_list = [os.path.join(folder, nzf.filename)]
                # Make sure we have a movie
                if not (len(movie_list) >= 1):
                    utils.notification("Not a movie!")
                    log("pre_play: no movie in movie_list")
                    break
                # Who needs sample?
                movie_no_sample_list = utils.no_sample_list(movie_list)
                # If auto play is enabled we skip samples in the play_list
                if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST:
                    for movie_file in movie_no_sample_list:
                        play_list.append(nzf.filename)
                        play_list.append(movie_file)
                else:
                    for movie_file in movie_list:
                        play_list.append(nzf.filename)
                        play_list.append(movie_file)
                # If the movie is a .mkv or .mp4 we need the last rar
                if utils.is_movie_mkv(movie_list) and sab_nzo_id and is_movie_in_rar:
                    # If we have a sample or other file, the second rar is also needed..
                    if len(in_rar_file_list) > 1:
                        second_nzf = clean_sorted_nzf_list[1]
                        iscanceled = get_nzf(folder, sab_nzo_id, second_nzf)
                    last_nzf = clean_sorted_nzf_list[-1]
                    iscanceled =  get_nzf(folder, sab_nzo_id, last_nzf)
                    if iscanceled: 
                        break 
        if iscanceled:
            log("pre_play: get_nzf: canceled")
            return
        else:
            rar_file_list = [x.filename for x in sorted_nzf_list]
            if (len(rar_file_list) >= 1) or (not is_movie_in_rar and len(movie_list) >= 1):
                if AUTO_PLAY and ( mode is None or mode is MODE_STRM):
                    video_params = dict()
                    if not mode:
                        video_params['mode'] = MODE_AUTO_PLAY
                    else:
                        video_params['mode'] = MODE_STRM
                    video_params['play_list'] = utils.quote_plus(';'.join(play_list))
                    video_params['file_list'] = utils.quote_plus(';'.join(rar_file_list))
                    video_params['folder'] = utils.quote_plus(folder)
                    video_params['nzoid'] = sab_nzo_id
                    video_params['nzoidhistory'] = sab_nzo_id_history
                    return play_video(video_params)   
                else:
                    return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history)
            else:
                utils.notification("No rar\'s in the NZB!")
                log("pre_play: no rar\'s in the NZB")
                return
    else:
        utils.notification("No playable files found!")
        log("pre_play: no playable files found")
        #log("the_end(folder, True, sab_nzo_id, sab_nzo_id_history): %s, %s, %s" % (folder, sab_nzo_id, sab_nzo_id_history))
        the_end(folder, True, sab_nzo_id, sab_nzo_id_history)
        return
Пример #3
0
def pre_play(nzbname, mode = None):
    iscanceled = False
    folder = INCOMPLETE_FOLDER + nzbname
    sab_nzo_id = SABNZBD.nzo_id(nzbname)
    file_list = utils.list_dir(folder)
    sab_file_list = []
    multi_arch_list = []
    if sab_nzo_id is None:
        sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname)
    else:
        sab_file_list = SABNZBD.file_list(sab_nzo_id)
        file_list.extend(sab_file_list)
        sab_nzo_id_history = None
    file_list = utils.sorted_rar_file_list(file_list)
    multi_arch_list = utils.sorted_multi_arch_list(file_list)
    # Loop though all multi archives and add file to the 
    play_list = []
    for arch_rar, byte in multi_arch_list:
        if sab_nzo_id is not None:
            t = Thread(target=to_bottom, args=(sab_nzo_id, sab_file_list, file_list,))
            t.start()
            iscanceled = get_rar(folder, sab_nzo_id, arch_rar)
        if iscanceled:
            break
        else:
            if sab_nzo_id:
                set_streaming(sab_nzo_id)
            # TODO is this needed?
            time.sleep(1)
            # RAR ANALYSYS #
            in_rar_file_list = utils.rar_filenames(folder, arch_rar)
            movie_list = utils.sort_filename(in_rar_file_list)
            # Make sure we have a movie
            if not (len(movie_list) >= 1):
                xbmc.executebuiltin('Notification("NZBS","Not a movie!")')
                break
            # Who needs sample?
            movie_no_sample_list = utils.no_sample_list(movie_list)
            # If auto play is enabled we skip samples in the play_list
            if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST:
                for movie_file in movie_no_sample_list:
                    play_list.append(arch_rar)
                    play_list.append(movie_file)
            else:
                for movie_file in movie_list:
                    play_list.append(arch_rar)
                    play_list.append(movie_file)
            # If the movie is a .mkv we need the last rar
            if utils.is_movie_mkv(movie_list) and sab_nzo_id:
                # If we have a sample or other file, the second rar is also needed..
                if len(in_rar_file_list) > 1:
                    second_rar = utils.find_rar(file_list, 0)
                    iscanceled = get_rar(folder, sab_nzo_id, second_rar)
                last_rar = utils.find_rar(file_list, -1)
                iscanceled =  get_rar(folder, sab_nzo_id, last_rar)
                if iscanceled: 
                    break 
    if iscanceled:
        return
    else:
        rar_file_list = [x[0] for x in file_list]
        if (len(rar_file_list) >= 1):
            if AUTO_PLAY and ( mode is None or mode is MODE_JSONRPC):
                video_params = dict()
                if not mode:
                    video_params['mode'] = MODE_AUTO_PLAY
                else:
                    video_params['mode'] = MODE_JSONRPC
                video_params['play_list'] = urllib.quote_plus(';'.join(play_list))
                video_params['file_list'] = urllib.quote_plus(';'.join(rar_file_list))
                video_params['folder'] = urllib.quote_plus(folder)
                return play_video(video_params)   
            else:
                return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history)
        else:
            xbmc.executebuiltin('Notification("NZBS","No rar\'s in the NZB!!")')
            return
Пример #4
0
def pre_play(nzbname, mode=None):
    iscanceled = False
    folder = INCOMPLETE_FOLDER + nzbname
    sab_nzo_id = SABNZBD.nzo_id(nzbname)
    file_list = utils.list_dir(folder)
    sab_file_list = []
    multi_arch_list = []
    if sab_nzo_id is None:
        sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname)
    else:
        sab_file_list = SABNZBD.file_list(sab_nzo_id)
        file_list.extend(sab_file_list)
        sab_nzo_id_history = None
    file_list = utils.sorted_rar_file_list(file_list)
    multi_arch_list = utils.sorted_multi_arch_list(file_list)
    # Loop though all multi archives and add file to the
    play_list = []
    for arch_rar, byte in multi_arch_list:
        if sab_nzo_id is not None:
            t = Thread(target=to_bottom,
                       args=(
                           sab_nzo_id,
                           sab_file_list,
                           file_list,
                       ))
            t.start()
            iscanceled = get_rar(folder, sab_nzo_id, arch_rar)
        if iscanceled:
            break
        else:
            if sab_nzo_id:
                set_streaming(sab_nzo_id)
            # TODO is this needed?
            time.sleep(1)
            # RAR ANALYSYS #
            in_rar_file_list = utils.rar_filenames(folder, arch_rar)
            movie_list = utils.sort_filename(in_rar_file_list)
            # Make sure we have a movie
            if not (len(movie_list) >= 1):
                xbmc.executebuiltin('Notification("NZBS","Not a movie!")')
                break
            # Who needs sample?
            movie_no_sample_list = utils.no_sample_list(movie_list)
            # If auto play is enabled we skip samples in the play_list
            if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST:
                for movie_file in movie_no_sample_list:
                    play_list.append(arch_rar)
                    play_list.append(movie_file)
            else:
                for movie_file in movie_list:
                    play_list.append(arch_rar)
                    play_list.append(movie_file)
            # If the movie is a .mkv we need the last rar
            if utils.is_movie_mkv(movie_list) and sab_nzo_id:
                # If we have a sample or other file, the second rar is also needed..
                if len(in_rar_file_list) > 1:
                    second_rar = utils.find_rar(file_list, 0)
                    iscanceled = get_rar(folder, sab_nzo_id, second_rar)
                last_rar = utils.find_rar(file_list, -1)
                iscanceled = get_rar(folder, sab_nzo_id, last_rar)
                if iscanceled:
                    break
    if iscanceled:
        return
    else:
        rar_file_list = [x[0] for x in file_list]
        if (len(rar_file_list) >= 1):
            if AUTO_PLAY and (mode is None or mode is MODE_JSONRPC):
                video_params = dict()
                if not mode:
                    video_params['mode'] = MODE_AUTO_PLAY
                else:
                    video_params['mode'] = MODE_JSONRPC
                video_params['play_list'] = urllib.quote_plus(
                    ';'.join(play_list))
                video_params['file_list'] = urllib.quote_plus(
                    ';'.join(rar_file_list))
                video_params['folder'] = urllib.quote_plus(folder)
                return play_video(video_params)
            else:
                return playlist_item(play_list, rar_file_list, folder,
                                     sab_nzo_id, sab_nzo_id_history)
        else:
            xbmc.executebuiltin(
                'Notification("NZBS","No rar\'s in the NZB!!")')
            return