Exemplo n.º 1
0
 def update_thumbnails(self):
     videos = []
     videos.extend(self.downloaded_videos)
     videos.extend(self.filtered_videos)
     self.logger.info(
         "Updating thumbnails for downloaded and filtered videos")
     download_thumbnails_threaded(videos)
     UpdateVideosThread(videos, update_existing=True).start()
Exemplo n.º 2
0
 def update_thumbnails(self):
     """
     Updates thumbnails for downloaded and filtered videos.
     :return:
     """
     videos = []
     videos.extend(self.playview_videos)
     videos.extend(self.subfeed_videos)
     self.logger.info(
         "Updating thumbnails for downloaded and filtered videos")
     download_thumbnails_threaded(videos)
     UpdateVideosThread(videos, update_existing=True).start()
Exemplo n.º 3
0
 def get_single_video(self, video_url):
     """
     Fetches a specified video based on url
     :return:
     """
     self.logger.info("Fetching video: {}".format(video_url))
     reggie = re.match(YOUTUBE_URL_PATTERN, video_url)
     video_id = reggie.groups()[-1]
     self.logger.debug("{} --> ID: {}".format(video_url, video_id))
     video_d = list_uploaded_videos_videos(load_keys(1)[0], [video_id], 50)[0]
     download_thumbnails_threaded([video_d])
     DownloadViewListener.download_video(video_d,
                                         youtube_dl_finished_listener=[
                                             self.model.playback_grid_view_listener.downloadFinished],
                                         db_update_listeners=[
                                             self.model.playback_grid_view_listener.downloadedVideosChangedinDB])
Exemplo n.º 4
0
def get_new_and_updated_videos(vid_paths):
    """
    :param vid_paths: dict(video_id, vid_path)
    :return:
    """
    logger = create_logger(__name__ + ".new_and_updated")
    db_videos = get_videos_by_ids(vid_paths.keys())

    return_videos = []
    for video in db_videos:
        if not video.vid_path or not video.downloaded:
            video_d = Video.to_video_d(video)
            video_d.vid_path = vid_paths[video.video_id]
            video_d.downloaded = True
            video_d.date_downloaded = datetime.datetime.utcnow()
            logger.info("Found video needing update: {} - {}".format(
                video.video_id, video.title))

            return_videos.append(video_d)
        vid_paths.pop(video.video_id, None)

    new_videos = []
    if len(vid_paths) > 0:
        youtube_keys = load_keys(1)
        logger.info(
            "Grabbing new video(s) information from youtube for: {}".format(
                vid_paths.keys()))
        response_videos = list_uploaded_videos_videos(youtube_keys[0],
                                                      vid_paths.keys(), 30)
        for video in response_videos:
            video.vid_path = vid_paths[video.video_id]
            video.downloaded = True
            video.watched = False
            video.date_downloaded = datetime.datetime.utcnow()
            logger.info("Found new video: {} - {}".format(
                video.video_id, video.title))
            new_videos.append(video)

    return_videos.extend(new_videos)
    logger.info("Downloading thumbnails for: {}".format(return_videos))
    download_thumbnails_threaded(return_videos)
    return return_videos
Exemplo n.º 5
0
def refresh_and_get_newest_videos(limit,
                                  filter_downloaded=True,
                                  filter_discarded=True,
                                  progress_listener=None,
                                  refresh_type=LISTENER_SIGNAL_NORMAL_REFRESH):
    logger.info("Refreshing and getting newest videos")
    if progress_listener:
        progress_listener.progress_bar.setVisible(True)
        progress_listener.resetBar.emit()
    videos = refresh_uploads(progress_bar_listener=progress_listener,
                             add_to_max=2 * limit,
                             refresh_type=refresh_type)
    if filter_downloaded or filter_discarded:
        return_list = compare_db_filtered(videos,
                                          limit,
                                          discarded=filter_discarded,
                                          downloaded=filter_downloaded)
    else:
        return_list = videos[:limit]

    if refresh_type == LISTENER_SIGNAL_DEEP_REFRESH:
        return_list = check_for_new(return_list, deep_refresh=True)
    else:
        return_list = check_for_new(return_list)

    UpdateVideosThread(videos).start()
    if len(return_list) > 0:
        download_thumbnails_threaded(return_list,
                                     progress_listener=progress_listener)
        return_list = get_extra_videos_information(return_list)
        UpdateVideosExtraInfoThreaded(return_list).start()
    else:
        logger.info(
            "Skipping thumbnails download and db update as return list is empty"
        )

    if progress_listener:
        progress_listener.progress_bar.setVisible(False)
        progress_listener.resetBar.emit()
    return return_list
Exemplo n.º 6
0
 def get_single_video(self, video_url):
     """
     Fetches a specified video based on url
     :return:
     """
     self.logger.info("Fetching video: {}".format(video_url))
     video_id = video_url.split('v=')[
         -1]  # FIXME: Make a proper input sanitizer
     self.logger.debug("{} --> ID: {}".format(video_url, video_id))
     video_d = list_uploaded_videos_videos(load_keys(1)[0], [video_id],
                                           50)[0]
     download_thumbnails_threaded([video_d])
     # self.logger.debug(video_d.__dict__)
     # DownloadHandler.download_video(video_d)
     DownloadHandler.download_video(
         video_d,
         youtube_dl_finished_listener=[
             GridViewListener.static_self.downloadFinished
         ],
         db_update_listeners=[
             GridViewListener.static_self.downloadedVideosChangedinDB
         ])
Exemplo n.º 7
0
def refresh_and_get_newest_videos(limit,
                                  filter_downloaded=True,
                                  filter_discarded=True,
                                  progress_listener=None,
                                  refresh_type=LISTENER_SIGNAL_NORMAL_REFRESH):
    """
    Refresh subscription feed and get newest videos from Database.

    :param limit:               Integer value determining how many videos to return.
    :param filter_discarded:    Boolean determining whether or not to exclude discarded videos.
    :param filter_downloaded:   Boolean determining whether or not to exclude filter_downloaded videos.
    :param progress_listener:   QProgressBar listener.
    :param refresh_type:        Listener signal determining whether to do a normal or deep refresh.
    :return:
    """
    logger.info("Refreshing and getting newest videos")

    # Spawn a QProgressBar, if listener is given.
    if progress_listener:
        progress_listener.progress_bar.setVisible(True)
        progress_listener.resetBar.emit()

    try:
        # Get a list of videos by refreshing the subscription feed.
        videos = refresh_uploads(progress_bar_listener=progress_listener,
                                 add_to_max=2 * limit,
                                 refresh_type=refresh_type)

        # If filters are enabled, run the videos through a filter function.
        if filter_downloaded or filter_discarded:
            return_list = filter_videos(videos,
                                        limit,
                                        filter_discarded=filter_discarded,
                                        filter_downloaded=filter_downloaded)

        # If no filters are enabled, simply add limit amount of videos to the list.
        else:
            return_list = videos[:limit]

        # Check for new videos (modify list directly).
        return_list = check_for_new(return_list, refresh_type)

        # Update videos (threaded).
        UpdateVideosThread(videos).start()
        # Check that video list isn't empty.
        if len(return_list) > 0:
            # Download video thumbnails (threaded).
            download_thumbnails_threaded(return_list,
                                         progress_listener=progress_listener)

            # Get additional video information (threaded) that isn't included in the standard grab function.
            return_list = get_extra_videos_information(return_list)
            UpdateVideosExtraInfoThreaded(return_list).start()
        else:
            logger.info(
                "Skipping thumbnails download and db update as return list is empty"
            )

        if progress_listener:
            progress_listener.progress_bar.setVisible(False)
            progress_listener.resetBar.emit()

        return return_list

    except SaneAbortedOperation as exc_sao:
        # Clean up progress bar after aborted operation
        if progress_listener:
            progress_listener.progress_bar.setVisible(False)
            progress_listener.resetBar.emit()

            raise exc_sao
    except Exception as exc_other:
        logger.critical(
            "Unexpected exception occurred in refresh_and_get_newest_videos!",
            exc_info=exc_other)

        # raise exc_other
        pass  # FIXME: Workaround for backend errors, if they get raised the entire refresh aborts.
Exemplo n.º 8
0
    def new_file(self, vid_id, vid_path):
        vid = db_session.query(Video).get(vid_id)
        if vid:
            if not vid.downloaded:
                vid.vid_path = vid_path
                vid.date_downloaded = datetime.datetime.utcnow()
                vid.downloaded = True

                thumb_path = os.path.join(THUMBNAILS_PATH,
                                          '{}.jpg'.format(vid.video_id))
                downloaded_thumbnail = os.path.isfile(thumb_path)
                if downloaded_thumbnail and (not vid.thumbnail_path):
                    vid.thumbnail_path = thumb_path
                    self.logger.warning(
                        "Thumbnail downloaded, but path didn't exist in db, for video: {}"
                        .format(vid.__dict__))
                elif (not vid.thumbnail_path) or (not downloaded_thumbnail):
                    if not downloaded_thumbnail:
                        self.logger.warning(
                            "Thumbnail path in db, but not on disk, for video: {}"
                            .format(vid.__dict__))
                    self.logger.info("Downloading thumbnail for: {}".format(
                        vid.__dict__))
                    download_thumbnails_threaded([vid])

                self.logger.info(
                    "Updating existing record in db: {} - {}".format(
                        vid.title, vid.__dict__))
                db_session.commit()
                self.model.update_subfeed_videos_from_db()
                self.model.update_playback_videos_from_db()
            else:
                self.logger.info(
                    "File already downloaded by this system: {} - {}".format(
                        vid.title, vid.__dict__))
            db_session.remove()

        else:
            db_session.remove()
            youtube_keys = load_keys(1)
            self.logger.info(
                "Grabbing new video information from youtube: {}".format(
                    vid_id))
            response_videos = list_uploaded_videos_videos(
                youtube_keys[0], [vid_id], 1)
            if len(response_videos) > 0:
                video = response_videos[0]
                video.vid_path = vid_path
                video.downloaded = True
                video.watched = False
                video.date_downloaded = datetime.datetime.utcnow()
                self.logger.info("Downloading thumbnail: {} - {}".format(
                    video.title, video.__dict__))
                download_thumbnails_threaded([video])
                self.logger.info("Adding new file to db: {} - {}".format(
                    video.title, video.__dict__))
                UpdateVideo(video,
                            finished_listeners=[
                                self.model.playback_grid_view_listener.
                                downloadedVideosChangedinDB
                            ]).start()
            else:
                self.logger.warning(
                    "Video with id {}, not found on youtube servers".format(
                        vid_id))