Ejemplo n.º 1
0
    def run(self, force_run):
        paths = autosubliminal.LIBRARYPATHS
        log.info('Starting round of library scanning at %r', paths)

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

        # Check if a path exists to scan
        if not one_path_exists(paths):
            log.error('None of the configured library paths (%r) exists, aborting...', paths)
            return

        # Clear failed shows/movies before starting a full scan
        FailedShowsDb().flush_failed_shows()
        FailedMoviesDb().flush_failed_movies()

        # Walk through paths and store info in db
        path_scanner = LibraryPathScanner()
        for path in paths:
            try:
                path_scanner.scan_path(path)
            except Exception:
                log.exception('Could not scan the path (%s), skipping it', path)

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

        log.info('Finished round of library scanning')
Ejemplo n.º 2
0
def test_send_websocket_event_page_reload(monkeypatch):
    monkeypatch.setattr('autosubliminal.WEBSOCKETMESSAGEQUEUE', [])
    message = {
        'type': 'EVENT',
        'event': {
            'type': 'PAGE_RELOAD',
            'data': {
                'name': 'home'
            }
        }
    }
    send_websocket_event(PAGE_RELOAD, data={'name': 'home'})
    assert len(autosubliminal.WEBSOCKETMESSAGEQUEUE) == 1
    assert autosubliminal.WEBSOCKETMESSAGEQUEUE.pop(0) == message
Ejemplo n.º 3
0
def test_send_websocket_event_process_started(monkeypatch):
    monkeypatch.setattr('autosubliminal.WEBSOCKETMESSAGEQUEUE', [])
    message = {
        'type': 'EVENT',
        'event': {
            'type': 'PROCESS_STARTED',
            'data': {
                'name': 'MyProcess'
            }
        }
    }
    send_websocket_event(PROCESS_STARTED, data={'name': 'MyProcess'})
    assert len(autosubliminal.WEBSOCKETMESSAGEQUEUE) == 1
    assert autosubliminal.WEBSOCKETMESSAGEQUEUE.pop(0) == message
Ejemplo n.º 4
0
    def run(self, force_run):
        paths = autosubliminal.VIDEOPATHS
        log.info('Starting round of local disk checking at %r', paths)

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

        # Check if a path exists to scan
        if not one_path_exists(paths):
            log.error(
                'None of the configured video paths (%r) exists, aborting...',
                paths)
            return

        # Walk through paths to search for wanted items
        new_wanted_items = []
        old_wanted_items = self.wanted_db.get_wanted_items()
        for path in paths:
            try:
                new_wanted_items.extend(self._scan_path(path))
            except Exception:
                log.exception(
                    'Could not scan the video path (%s), skipping it', path)

        # Cleanup wanted items that have been removed from disk manually but are still stored in the db
        log.debug(
            'Checking for non existing wanted items in wanted_items database')
        for item in old_wanted_items:
            if item not in new_wanted_items:
                self.wanted_db.delete_wanted_item(item)
                log.debug('Deleted non existing wanted item: %s',
                          item.videopath)

        # Populate WANTEDQUEUE with all items from wanted_items database
        log.info('Listing videos with missing subtitles:')
        autosubliminal.WANTEDQUEUE = []
        for item in self.wanted_db.get_wanted_items():
            log.info('%s %s', item.videopath, item.languages)
            autosubliminal.WANTEDQUEUE.append(item)

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

        log.info('Finished round of local disk checking')
Ejemplo n.º 5
0
def test_send_websocket_event_process_finished(monkeypatch):
    monkeypatch.setattr('autosubliminal.WEBSOCKETMESSAGEQUEUE', [])
    next_run = time.time()
    message = {
        'type': 'EVENT',
        'event': {
            'type': 'PROCESS_FINISHED',
            'data': {
                'name': 'MyProcess',
                'next_run': next_run
            }
        }
    }
    send_websocket_event(PROCESS_FINISHED,
                         data={
                             'name': 'MyProcess',
                             'next_run': next_run
                         })
    assert len(autosubliminal.WEBSOCKETMESSAGEQUEUE) == 1
    assert autosubliminal.WEBSOCKETMESSAGEQUEUE.pop(0) == message
Ejemplo n.º 6
0
    def run(self, force_run):
        paths = autosubliminal.VIDEOPATHS
        log.info('Starting round of local disk checking at %r', paths)

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

        # Check if a path exists to scan
        if not one_path_exists(paths):
            log.error('None of the configured video paths (%r) exists, aborting...', paths)
            return

        # Walk through paths to search for wanted items
        new_wanted_items = []
        old_wanted_items = self.wanted_db.get_wanted_items()
        for path in paths:
            try:
                new_wanted_items.extend(self._scan_path(path))
            except Exception:
                log.exception('Could not scan the video path (%s), skipping it', path)

        # Cleanup wanted items that have been removed from disk manually but are still stored in the db
        log.debug('Checking for non existing wanted items in wanted_items database')
        for item in old_wanted_items:
            if item not in new_wanted_items:
                self.wanted_db.delete_wanted_item(item)
                log.debug('Deleted non existing wanted item: %s', item.videopath)

        # Populate WANTEDQUEUE with all items from wanted_items database
        log.info('Listing videos with missing subtitles:')
        autosubliminal.WANTEDQUEUE = []
        for item in self.wanted_db.get_wanted_items():
            log.info('%s %s', item.videopath, item.languages)
            autosubliminal.WANTEDQUEUE.append(item)

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

        log.info('Finished round of local disk checking')
Ejemplo n.º 7
0
    def _run_process(self, current_time):
        # Check if the run needs a lock
        run_lock = self.process.force_run_lock if self._force_run else self.process.run_lock

        # Delay process if lock cannot be acquired
        if run_lock and not get_wanted_queue_lock():
            # Increase delay with 1 second each time the process cannot yet run
            self._delay += 1
            return

        try:
            # Mark as running
            self.process.running = True
            send_websocket_event(PROCESS_STARTED, data=self.to_json())

            log.debug('Running %s thread process', self.name)
            self.process.run(self._force_run)

            # Update process properties after process run
            self.last_run = current_time
            self._delay = 0
            if self._force_run:
                self._force_run = False

            # Mark as finished
            self.process.running = False
            send_websocket_event(PROCESS_FINISHED, data=self.to_json())

        except:
            print(traceback.format_exc())
            self.process.running = False
            os._exit(1)

        finally:
            # Release lock if needed
            if run_lock:
                release_wanted_queue_lock()
Ejemplo n.º 8
0
    def _run_process(self, current_time):
        # Check if the run needs a lock
        run_lock = self.process.force_run_lock if self._force_run else self.process.run_lock

        # Delay process if lock cannot be acquired
        if run_lock and not get_wanted_queue_lock():
            # Increase delay with 1 second each time the process cannot yet run
            self._delay += 1
            return

        try:
            # Mark as running
            self.process.running = True
            send_websocket_event(PROCESS_STARTED, data=self.to_json())

            log.debug('Running %s thread process', self.name)
            self.process.run(self._force_run)

            # Update process properties after process run
            self.last_run = current_time
            self._delay = 0
            if self._force_run:
                self._force_run = False

            # Mark as finished
            self.process.running = False
            send_websocket_event(PROCESS_FINISHED, data=self.to_json())

        except:
            print(traceback.format_exc())
            self.process.running = False
            os._exit(1)

        finally:
            # Release lock if needed
            if run_lock:
                release_wanted_queue_lock()
Ejemplo n.º 9
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')