Exemplo n.º 1
0
def post_process(wanted_item_index, subtitle_index):
    log.info('Post processing an individual subtitle')

    # Get wanted queue lock
    if not utils.get_wanted_queue_lock():
        return False

    # Get wanted item
    wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)]
    found_subtitles = wanted_item['found_subtitles']
    subtitles = found_subtitles['subtitles']
    language = found_subtitles['language']
    single = found_subtitles['single']

    # Only execute post processing when a subtitle is present
    processed = False
    subtitle_path = _get_subtitle_path(wanted_item)
    if os.path.exists(subtitle_path):
        # Get wanted subtitle
        wanted_subtitle = _get_wanted_subtitle(subtitles, subtitle_index)

        # Handle download
        download_item = _construct_download_item(wanted_item,
                                                 [wanted_subtitle], language,
                                                 single)
        downloader = SubDownloader(download_item)
        downloader.mark_downloaded()
        processed = downloader.post_process()

        if processed:
            # Remove downloaded language from wanted languages
            wanted_item['languages'].remove(language)

            # Update wanted item if there are still wanted languages
            if len(wanted_item['languages']) > 0:
                WantedItems().update_wanted_item(wanted_item)

            # Remove wanted item if there are no more wanted languages
            else:
                # Remove wanted item
                autosubliminal.WANTEDQUEUE.pop(int(wanted_item_index))
                log.debug('Removed item from the wanted queue at index %s',
                          int(wanted_item_index))
                WantedItems().delete_wanted_item(wanted_item)
                log.debug('Removed %s from wanted_items database',
                          wanted_item['videopath'])

    else:
        log.warning('No subtitle downloaded, skipping post processing')

    # Release wanted queue lock
    utils.release_wanted_queue_lock()

    return processed
Exemplo n.º 2
0
def post_process(wanted_item_index, subtitle_index):
    log.info('Post processing an individual subtitle')

    # Get wanted queue lock
    if not get_wanted_queue_lock():
        return False

    # Get wanted item
    wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)]
    found_subtitles = wanted_item.found_subtitles
    subtitles = found_subtitles['subtitles']
    language = found_subtitles['language']
    single = found_subtitles['single']

    # Only execute post processing when a subtitle is present
    processed = False
    subtitle_path = _get_subtitle_path(wanted_item)
    if os.path.exists(subtitle_path):
        # Get wanted subtitle
        wanted_subtitle = _get_wanted_subtitle(subtitles, subtitle_index)

        # Handle download
        download_item = _construct_download_item(wanted_item, [wanted_subtitle], language, single)
        downloader = SubDownloader(download_item)
        downloader.mark_downloaded()
        processed = downloader.post_process()

        if processed:
            # Remove downloaded language from wanted languages
            wanted_item.languages.remove(language)

            # Update wanted item if there are still wanted languages
            if len(wanted_item.languages) > 0:
                WantedItemsDb().update_wanted_item(wanted_item)

            # Remove wanted item if there are no more wanted languages
            else:
                # Remove wanted item
                autosubliminal.WANTEDQUEUE.pop(int(wanted_item_index))
                log.debug('Removed item from the wanted queue at index %s', int(wanted_item_index))
                WantedItemsDb().delete_wanted_item(wanted_item)
                log.debug('Removed %s from wanted_items database', wanted_item.videopath)

    else:
        log.warning('No subtitle downloaded, skipping post processing')

    # Release wanted queue lock
    release_wanted_queue_lock()

    return processed
Exemplo n.º 3
0
def save_subtitle(wanted_item_index, subtitle_index):
    log.info('Saving an individual subtitle')

    # Get wanted queue lock
    if not get_wanted_queue_lock():
        return False

    # Get wanted item
    wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)]
    found_subtitles = wanted_item.found_subtitles
    subtitles = found_subtitles['subtitles']
    language = found_subtitles['language']
    single = found_subtitles['single']

    # Get wanted subtitle
    wanted_subtitle = _get_wanted_subtitle(subtitles, subtitle_index)

    # Save subtitle (skip notify and post_process)
    download_item = _construct_download_item(wanted_item, [wanted_subtitle], language, single)
    downloaded = SubDownloader(download_item).save()

    # Release wanted queue lock
    release_wanted_queue_lock()

    return downloaded
Exemplo n.º 4
0
    def run(self, force_run):
        log.info("Starting round of subtitle checking")
        to_delete_wanted_queue = []

        # Wait for internet connection
        utils.wait_for_internet_connection()

        # Get wanted queue lock
        if not utils.get_wanted_queue_lock():
            return False

        # Show info message (only when run was forced manually)
        if force_run:
            utils.add_notification_message("Checking subtitles...")

        # Process all items in wanted queue
        for index, wanted_item in enumerate(autosubliminal.WANTEDQUEUE):
            # Scan wanted_item for video, skip when no video could be determined
            video = _scan_wanted_item_for_video(wanted_item)
            if not video:
                continue

            # Check subtitles for each language
            langs = wanted_item['lang']
            for lang in langs[:]:
                # Search the best subtitle with the minimal score
                subtitles, language, single = _search_subtitles(
                    video, lang, True)

                # Save when a subtitle is found for the video
                if subtitles[video]:
                    download_item = _construct_download_item(
                        wanted_item, subtitles, language, single)
                    SubDownloader(download_item).run()

                    # Remove from wanted queue if needed (if no additional languages are still needed)
                    langs.remove(lang)
                    if len(langs) == 0:
                        to_delete_wanted_queue.append(index)

        # Cleanup wanted queue
        i = len(to_delete_wanted_queue) - 1
        while i >= 0:
            log.debug("Removed item from the wanted queue at index %s" %
                      to_delete_wanted_queue[i])
            autosubliminal.WANTEDQUEUE.pop(to_delete_wanted_queue[i])
            i -= 1

        # Release wanted queue lock
        log.info("Finished round of subtitle checking")
        utils.release_wanted_queue_lock()

        return True
Exemplo n.º 5
0
def post_process(wanted_item_index, subtitle_index):
    log.info("Post processing an individual subtitle")

    # Get wanted queue lock
    if not utils.get_wanted_queue_lock():
        return False

    # Get wanted item
    wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)]
    found_subtitles = wanted_item['found_subtitles']
    subtitles = found_subtitles['subtitles']
    language = found_subtitles['language']
    single = found_subtitles['single']

    # Only execute post processing when a subtitle is present
    processed = False
    subtitle_path = _get_subtitle_path(wanted_item)
    if os.path.exists(subtitle_path):
        # Get selected subtitle
        wanted_subtitles = _get_wanted_subtitle(subtitles, subtitle_index)

        # Post process only
        download_item = _construct_download_item(wanted_item, wanted_subtitles,
                                                 language, single)
        processed = SubDownloader(download_item).post_process()

        # Remove from wanted queue is downloaded
        if processed:
            autosubliminal.WANTEDQUEUE.pop(int(wanted_item_index))
    else:
        log.warning("No subtitle downloaded, skipping post processing")

    # Release wanted queue lock
    utils.release_wanted_queue_lock()

    return processed
Exemplo n.º 6
0
    def run(self, force_run):
        log.info('Starting round of subtitle checking')

        # Wait for internet connection
        wait_for_internet_connection()

        # Show info message (only when run was forced manually)
        if force_run:
            send_websocket_notification('Checking subtitles...')

        to_delete_wanted_queue = []

        # Setup provider pool
        provider_pool = _get_provider_pool()
        if provider_pool:
            log.info('Searching subtitles with providers: %s', ', '.join(provider_pool.providers))

            # Process all items in wanted queue
            db = WantedItemsDb()
            for index, wanted_item in enumerate(autosubliminal.WANTEDQUEUE):
                log.info('Searching subtitles for video: %s', wanted_item.videopath)

                # Check if the search is currently active for the wanted_item
                if not wanted_item.is_search_active:
                    log.info('Search not active in this run for video: %s', wanted_item.videopath)
                    continue

                # Scan wanted_item for video, skip when no video could be determined
                video = _scan_wanted_item_for_video(wanted_item)
                if not video:
                    continue

                # Clear discarded providers for each new wanted_item
                provider_pool.discarded_providers.clear()

                # Check subtitles for each language
                languages = wanted_item.languages
                for lang in languages[:]:
                    # Search the best subtitle with the minimal score
                    try:
                        subtitles, language, single = _search_subtitles(video, lang, True, provider_pool)
                    except Exception:
                        log.exception('Error while searching subtitles for video %r', wanted_item.videopath)
                        continue

                    # Subtitle is found for the video
                    if subtitles:
                        # Handle download
                        download_item = _construct_download_item(wanted_item, subtitles, language, single)
                        SubDownloader(download_item).run()

                        # Remove downloaded language from wanted languages
                        languages.remove(lang)

                        # Update wanted item if there are still wanted languages
                        if len(languages) > 0:
                            db.update_wanted_item(wanted_item)

                        # Mark wanted item as deleted if there are no more wanted languages
                        else:
                            to_delete_wanted_queue.append(index)

            # Cleanup wanted item(s)
            i = len(to_delete_wanted_queue) - 1
            while i >= 0:
                wanted_item_to_delete = autosubliminal.WANTEDQUEUE.pop(to_delete_wanted_queue[i])
                log.debug('Removed item from the wanted queue at index %s', to_delete_wanted_queue[i])
                db.delete_wanted_item(wanted_item_to_delete)
                log.debug('Removed %s from wanted_items database', wanted_item_to_delete.videopath)
                i -= 1

        else:
            log.info('No subliminal providers configured, skipping')

        # Send home page reload event
        send_websocket_event(PAGE_RELOAD, data={'name': 'home'})

        log.info('Finished round of subtitle checking')