From d0bfbaadfefa6c028dda04385429f70cfe0e24ca Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 17 Mar 2020 20:53:18 -0700 Subject: [PATCH] Add method insert_playlist. --- ycdl/ycdldb.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ycdl/ycdldb.py b/ycdl/ycdldb.py index 11e037b..3edf99a 100644 --- a/ycdl/ycdldb.py +++ b/ycdl/ycdldb.py @@ -263,6 +263,15 @@ class YCDLDB: videos = [{key: video[SQL_VIDEO[key]] for key in SQL_VIDEO} for video in videos] return videos + def insert_playlist(self, playlist_id, commit=True): + video_generator = self.youtube.get_playlist_videos(playlist_id) + results = [self.insert_video(video, commit=False) for video in video_generator] + + if commit: + self.sql.commit() + + return results + def insert_video(self, video, *, add_channel=True, commit=True): if not isinstance(video, ytapi.Video): video = self.youtube.get_video(video)