Move some heavy lifting into new ingest_video.
This commit is contained in:
		
							parent
							
								
									ce028e4ebb
								
							
						
					
					
						commit
						dfa5bb2390
					
				
					 2 changed files with 30 additions and 7 deletions
				
			
		|  | @ -48,13 +48,7 @@ class Channel(Base): | |||
|         video_generator = self.ycdldb.youtube.get_playlist_videos(self.uploads_playlist) | ||||
|         for video in video_generator: | ||||
|             seen_ids.add(video.id) | ||||
|             status = self.ycdldb.insert_video(video, commit=False) | ||||
| 
 | ||||
|             video = status['video'] | ||||
|             if status['new'] and self.automark not in [None, "pending"]: | ||||
|                 if self.automark == 'downloaded': | ||||
|                     self.ycdldb.download_video(video.id, commit=False) | ||||
|                 video.mark_state(self.automark, commit=False) | ||||
|             status = self.ycdldb.ingest_video(video, commit=False) | ||||
| 
 | ||||
|             if not (force or status['new']): | ||||
|                 break | ||||
|  |  | |||
|  | @ -326,6 +326,35 @@ class YCDLDBVideoMixin: | |||
| 
 | ||||
|         return results | ||||
| 
 | ||||
|     def ingest_video(self, video, commit=True): | ||||
|         ''' | ||||
|         Call `insert_video`, and additionally use the channel's automark to | ||||
|         mark this video's state. | ||||
|         ''' | ||||
|         status = self.insert_video(video, commit=False) | ||||
| 
 | ||||
|         if not status['new']: | ||||
|             return status | ||||
| 
 | ||||
|         video = status['video'] | ||||
|         author = video.author | ||||
| 
 | ||||
|         if not author: | ||||
|             return status | ||||
| 
 | ||||
|         if author.automark in [None, 'pending']: | ||||
|             return status | ||||
| 
 | ||||
|         if author.automark == 'downloaded': | ||||
|             self.download_video(video.id, commit=False) | ||||
| 
 | ||||
|         video.mark_state(author.automark, commit=False) | ||||
| 
 | ||||
|         if commit: | ||||
|             self.commit() | ||||
| 
 | ||||
|         return status | ||||
| 
 | ||||
|     def insert_video(self, video, *, add_channel=True, commit=True): | ||||
|         if not isinstance(video, ytapi.Video): | ||||
|             video = self.youtube.get_video(video) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue