Exemplo n.º 1
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.º 2
0
 def merge_two_videos_list_grab_info(self, high_prio_list, low_prio_list):
     high_prio_dict = {video.video_id: video for video in high_prio_list}
     low_prio_dict = {video.video_id: video for video in low_prio_list}
     output_list = []
     low_prio_unique_ids = []
     for video in high_prio_dict.values():
         if video.video_id in low_prio_dict:
             video.grab_methods.extend(low_prio_dict[video.video_id].grab_methods)
         output_list.append(video)
     for video in low_prio_dict.values():
         if video.video_id in high_prio_dict:
             continue
         else:
             low_prio_unique_ids.append(video.video_id)
     if len(low_prio_unique_ids) > 0:
         self.logger.info("Requesting additional information for search items: {}".format(low_prio_unique_ids))
         output_list.extend(list_uploaded_videos_videos(self.youtube, low_prio_unique_ids, 50))
     return output_list
Exemplo n.º 3
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.º 4
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.º 5
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))