def forwards(self, orm): # Setting the video ID for vlog in orm["main.VideoLog"].objects.all(): video = get_video_from_youtube_id(vlog.youtube_id) vlog.video_id = video.get( "id", vlog.youtube_id) if video else vlog.youtube_id vlog.save()
def save(self, *args, **kwargs): # To deal with backwards compatibility, # check video_id, whether imported or not. if not self.video_id: assert kwargs.get( "imported", False), "video_id better be set by internal code." assert self.youtube_id, "If not video_id, you better have set youtube_id!" video = get_video_from_youtube_id(self.youtube_id) self.video_id = video.get( "id", self.youtube_id ) if video else self.youtube_id # for unknown videos, default to the youtube_id if not kwargs.get("imported", False): self.full_clean() try: UserLog.update_user_activity( self.user, activity_type="login", update_datetime=(self.completion_timestamp or datetime.now()), language=self.language) except ValidationError as e: logging.error("Failed to update userlog during video: %s" % e) super(VideoLog, self).save(*args, **kwargs)
def download_progress_callback(self, videofile, percent): video_changed = (not self.video) or self.video.get( "youtube_id") != videofile.get("youtube_id") video_done = self.video and percent == 100 video_error = self.video and not video_changed and ( percent - self.video.get("percent_complete", 0) > 50) if self.video and ( percent - self.video.get("percent_complete", 0) ) < 1 and not video_done and not video_changed and not video_error: return self.video = videofile video_queue = VideoQueue() try: if not video_queue.count(): raise DownloadCancelled() else: if video_error: self.video["percent_complete"] = 0 return elif (percent - self.video.get("percent_complete", 0) ) >= 1 or video_done or video_changed: # Update to output (saved in chronograph log, so be a bit more efficient if int(percent) % 5 == 0 or percent == 100: self.stdout.write("%d\n" % percent) self.video["percent_complete"] = percent # update progress data video_node = get_video_from_youtube_id( self.video.get("youtube_id")) video_title = (video_node and video_node.get("title") ) or self.video.get("title") # Calling update_stage, instead of next_stage when stage changes, will auto-call next_stage appropriately. self.update_stage(stage_name=self.video.get("youtube_id"), stage_percent=percent / 100., notes=_("Downloading '%(video_title)s'") % {"video_title": _(video_title)}) if percent == 100: self.video = {} except DownloadCancelled as de: if self.video: self.stdout.write(_("Download cancelled!") + "\n") self.video = {} # Progress info will be updated when this exception is caught. raise
def download_progress_callback(self, videofile, percent): video_changed = (not self.video) or self.video.get("youtube_id") != videofile.get("youtube_id") video_done = self.video and percent == 100 video_error = self.video and not video_changed and (percent - self.video.get("percent_complete", 0) > 50) if self.video and (percent - self.video.get("percent_complete", 0)) < 1 and not video_done and not video_changed and not video_error: return self.video = videofile video_queue = VideoQueue() try: if not video_queue.count(): raise DownloadCancelled() else: if video_error: self.video["percent_complete"] = 0 return elif (percent - self.video.get("percent_complete", 0)) >= 1 or video_done or video_changed: # Update to output (saved in chronograph log, so be a bit more efficient if int(percent) % 5 == 0 or percent == 100: self.stdout.write("%d\n" % percent) self.video["percent_complete"] = percent # update progress data video_node = get_video_from_youtube_id(self.video.get("youtube_id")) video_title = (video_node and video_node.get("title")) or self.video.get("title") # Calling update_stage, instead of next_stage when stage changes, will auto-call next_stage appropriately. self.update_stage(stage_name=self.video.get("youtube_id"), stage_percent=percent/100., notes=_("Downloading '%(video_title)s'") % {"video_title": _(video_title)}) if percent == 100: self.video = {} except DownloadCancelled as de: if self.video: self.stdout.write(_("Download cancelled!") + "\n") self.video = {} # Progress info will be updated when this exception is caught. raise
def save(self, *args, **kwargs): # To deal with backwards compatibility, # check video_id, whether imported or not. if not self.video_id: assert kwargs.get("imported", False), "video_id better be set by internal code." assert self.youtube_id, "If not video_id, you better have set youtube_id!" video = get_video_from_youtube_id(self.youtube_id) self.video_id = video.get("id", self.youtube_id) if video else self.youtube_id # for unknown videos, default to the youtube_id if not kwargs.get("imported", False): self.full_clean() try: UserLog.update_user_activity(self.user, activity_type="login", update_datetime=(self.completion_timestamp or datetime.now()), language=self.language) except ValidationError as e: logging.error("Failed to update userlog during video: %s" % e) super(VideoLog, self).save(*args, **kwargs)
def forwards(self, orm): # Setting the video ID for vlog in orm["main.VideoLog"].objects.all(): video = get_video_from_youtube_id(vlog.youtube_id) vlog.video_id = video.get("id", vlog.youtube_id) if video else vlog.youtube_id vlog.save()