Add get_things_by_sql.
This commit is contained in:
parent
9f5726e5d3
commit
1e59d7be06
1 changed files with 15 additions and 0 deletions
|
@ -93,6 +93,15 @@ class YCDLDBCacheManagerMixin:
|
|||
thing_cache[thing_id] = thing
|
||||
return thing
|
||||
|
||||
def get_things_by_sql(self, thing_type, query, bindings=None):
|
||||
'''
|
||||
Use an arbitrary SQL query to select things from the database.
|
||||
Your query select *, all the columns of the thing's table.
|
||||
'''
|
||||
thing_rows = self.sql_select(query, bindings)
|
||||
for thing_row in thing_rows:
|
||||
yield self.get_cached_instance(thing_type, thing_row)
|
||||
|
||||
class YCDLDBChannelMixin:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -150,6 +159,9 @@ class YCDLDBChannelMixin:
|
|||
channels.sort(key=lambda c: c.name.lower())
|
||||
return channels
|
||||
|
||||
def get_channels_by_sql(self, query, bindings=None):
|
||||
return self.get_things_by_sql('channel', query, bindings)
|
||||
|
||||
def _rss_assisted_refresh(self, skip_failures=False, commit=True):
|
||||
'''
|
||||
Youtube provides RSS feeds for every channel. These feeds do not
|
||||
|
@ -389,6 +401,9 @@ class YCDLDBVideoMixin:
|
|||
for row in rows:
|
||||
yield self.get_cached_instance('video', row)
|
||||
|
||||
def get_videos_by_sql(self, query, bindings=None):
|
||||
return self.get_things_by_sql('video', query, bindings)
|
||||
|
||||
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]
|
||||
|
|
Loading…
Reference in a new issue