More logging updates.

This commit is contained in:
voussoir 2020-11-10 17:53:52 -08:00
parent 648d2af560
commit 294ccb77d9
3 changed files with 21 additions and 10 deletions

View file

@ -39,7 +39,7 @@ class Channel(Base):
return videos return videos
def delete(self, commit=True): def delete(self, commit=True):
self.ycdldb.log.debug('Deleting %s.', self) self.ycdldb.log.info('Deleting %s.', self)
self.ycdldb.sql_delete(table='videos', pairs={'author_id': self.id}) self.ycdldb.sql_delete(table='videos', pairs={'author_id': self.id})
self.ycdldb.sql_delete(table='channels', pairs={'id': self.id}) self.ycdldb.sql_delete(table='channels', pairs={'id': self.id})
@ -61,7 +61,7 @@ class Channel(Base):
return self.ycdldb.sql_select_one(query, bindings) is not None return self.ycdldb.sql_select_one(query, bindings) is not None
def refresh(self, *, force=False, rss_assisted=True, commit=True): def refresh(self, *, force=False, rss_assisted=True, commit=True):
self.ycdldb.log.debug('Refreshing %s.', self.id) self.ycdldb.log.info('Refreshing %s.', self.id)
if not self.uploads_playlist: if not self.uploads_playlist:
self.uploads_playlist = self.ycdldb.youtube.get_user_uploads_playlist_id(self.id) self.uploads_playlist = self.ycdldb.youtube.get_user_uploads_playlist_id(self.id)
@ -90,6 +90,11 @@ class Channel(Base):
# Of course, it's possible they were deleted. # Of course, it's possible they were deleted.
known_ids = {v.id for v in self.ycdldb.get_videos(channel_id=self.id)} known_ids = {v.id for v in self.ycdldb.get_videos(channel_id=self.id)}
refresh_ids = list(known_ids.difference(seen_ids)) refresh_ids = list(known_ids.difference(seen_ids))
if refresh_ids:
self.ycdldb.log.debug(
'%d ids did not come back from the generator, fetching them separately.',
len(refresh_ids),
)
for video in self.ycdldb.youtube.get_videos(refresh_ids): for video in self.ycdldb.youtube.get_videos(refresh_ids):
self.ycdldb.insert_video(video, commit=False) self.ycdldb.insert_video(video, commit=False)
@ -169,7 +174,7 @@ class Video(Base):
return None return None
def delete(self, commit=True): def delete(self, commit=True):
self.ycdldb.log.debug('Deleting %s.', self) self.ycdldb.log.info('Deleting %s.', self)
self.ycdldb.sql_delete(table='videos', pairs={'id': self.id}) self.ycdldb.sql_delete(table='videos', pairs={'id': self.id})
@ -183,7 +188,7 @@ class Video(Base):
if state not in constants.VIDEO_STATES: if state not in constants.VIDEO_STATES:
raise exceptions.InvalidVideoState(state) raise exceptions.InvalidVideoState(state)
self.ycdldb.log.debug('Marking %s as %s.', self, state) self.ycdldb.log.info('Marking %s as %s.', self, state)
pairs = { pairs = {
'id': self.id, 'id': self.id,

View file

@ -205,6 +205,8 @@ class YCDLDBChannelMixin:
return excs return excs
def refresh_all_channels(self, *, force=False, rss_assisted=True, skip_failures=False, commit=True): def refresh_all_channels(self, *, force=False, rss_assisted=True, skip_failures=False, commit=True):
self.log.info('Refreshing all channels.')
if rss_assisted and not force: if rss_assisted and not force:
return self._rss_assisted_refresh(skip_failures=skip_failures, commit=commit) return self._rss_assisted_refresh(skip_failures=skip_failures, commit=commit)
@ -365,7 +367,7 @@ class YCDLDBVideoMixin:
query = 'SELECT * FROM videos' + wheres + orderbys query = 'SELECT * FROM videos' + wheres + orderbys
self.log.debug(f'{query} {bindings}') self.log.debug('%s %s', query, bindings)
explain = self.sql_execute('EXPLAIN QUERY PLAN ' + query, bindings) explain = self.sql_execute('EXPLAIN QUERY PLAN ' + query, bindings)
self.log.debug('\n'.join(str(x) for x in explain.fetchall())) self.log.debug('\n'.join(str(x) for x in explain.fetchall()))
@ -438,8 +440,10 @@ class YCDLDBVideoMixin:
} }
if existing: if existing:
self.log.loud('Updating Video %s.', video.id)
self.sql_update(table='videos', pairs=data, where_key='id') self.sql_update(table='videos', pairs=data, where_key='id')
else: else:
self.log.loud('Inserting Video %s.', video.id)
self.sql_insert(table='videos', data=data) self.sql_insert(table='videos', data=data)
video = self.get_cached_instance('video', data) video = self.get_cached_instance('video', data)
@ -478,6 +482,7 @@ class YCDLDB(
# LOGGING # LOGGING
self.log = vlogging.getLogger('ycdl:%s' % self.data_directory.absolute_path) self.log = vlogging.getLogger('ycdl:%s' % self.data_directory.absolute_path)
self.log.setLevel(log_level) self.log.setLevel(log_level)
self.youtube.log.setLevel(log_level)
# DATABASE # DATABASE
self.database_filepath = self.data_directory.with_child(constants.DEFAULT_DBNAME) self.database_filepath = self.data_directory.with_child(constants.DEFAULT_DBNAME)
@ -519,7 +524,7 @@ class YCDLDB(
) )
def _first_time_setup(self): def _first_time_setup(self):
self.log.debug('Running first-time database setup.') self.log.info('Running first-time database setup.')
self.sql.executescript(constants.DB_INIT) self.sql.executescript(constants.DB_INIT)
self.commit() self.commit()

View file

@ -1,6 +1,7 @@
import apiclient.discovery import apiclient.discovery
import isodate import isodate
import logging
from voussoirkit import vlogging
from . import helpers from . import helpers
@ -53,7 +54,7 @@ class Youtube:
serviceName='youtube', serviceName='youtube',
version='v3', version='v3',
) )
self.log = logging.getLogger(__name__) self.log = vlogging.getLogger(__name__)
def get_playlist_videos(self, playlist_id): def get_playlist_videos(self, playlist_id):
page_token = None page_token = None
@ -70,8 +71,6 @@ class Youtube:
videos = self.get_videos(video_ids) videos = self.get_videos(video_ids)
videos.sort(key=lambda x: x.published, reverse=True) videos.sort(key=lambda x: x.published, reverse=True)
self.log.debug('Got %d more videos.', len(videos))
for video in videos: for video in videos:
yield video yield video
@ -127,12 +126,14 @@ class Youtube:
chunks = helpers.chunk_sequence(video_ids, 50) chunks = helpers.chunk_sequence(video_ids, 50)
for chunk in chunks: for chunk in chunks:
self.log.debug('Requesting batch of %d video ids.', len(chunk)) self.log.debug('Requesting batch of %d video ids.', len(chunk))
self.log.loud(chunk)
chunk = ','.join(chunk) chunk = ','.join(chunk)
data = self.youtube.videos().list( data = self.youtube.videos().list(
part='id,contentDetails,snippet,statistics', part='id,contentDetails,snippet,statistics',
id=chunk, id=chunk,
).execute() ).execute()
items = data['items'] items = data['items']
self.log.debug('Got %d snippets.', len(items))
snippets.extend(items) snippets.extend(items)
videos = [] videos = []