From 85e7bc01e4a27e38f9dc9d11dfb89500eee1b6d6 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 15 Aug 2020 14:25:43 +0200 Subject: [PATCH] document why we aren't deleting videos, clean up logging --- app/common/common.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index 67d0482..20c62d4 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -104,18 +104,18 @@ def update_channel(db, xmldata, from_webhook=False): title, author, videos, channel, playlist = parse_xml(xmldata) c = db.cursor() - from flask import current_app # XXX: remove for i, video in enumerate(videos): if video.get('deleted'): - if from_webhook: current_app.logger.warning(f"ignoring deleted video {video['video_id']}") # XXX: remove - # TODO: enable once we enforce hmac validation: - #c.execute("DELETE FROM videos WHERE id = ?", (video['video_id'],)) + # Note: Deletion events are not just fired for actual deletions, + # but also for unlisting videos and livestreams that just ended + # (even postLiveDVR ones). Hence, we don't follow it. + flask_logger(f"ignoring deleted/unlisted/ended video/stream {video['video_id']}") break c.execute("SELECT 1 FROM videos WHERE id=?",(video['video_id'],)) new_video = len(c.fetchall()) < 1 if new_video: - if from_webhook:current_app.logger.warning(f"new video {video['video_id']}") + flask_logger(f"new video {video['video_id']}") _, _, meta, _, _ = get_video_info(video['video_id']) # The 'published' timestamp sent in websub POSTs are often wrong (e.g.: # video gets uploaded as unlisted on day A and set to public on day B; @@ -130,7 +130,7 @@ def update_channel(db, xmldata, from_webhook=False): if meta: meta = video_metadata(meta) published2 = dateutil.parser.parse(meta['published']) - if from_webhook:current_app.logger.warning(f"published {published} / {published2}") + flask_logger(f"published {published} / {published2}") if published < published2: # g_v_i date is more accurate: published = published2 length = meta['length'] @@ -358,6 +358,13 @@ def websub_url_hmac(key, feed_id, timestamp, nonce): def websub_body_hmac(key, body): return hmac.new(key.encode('ascii'), body, hashlib.sha1).hexdigest() +def flask_logger(msg, level="warning"): + try: + from flask import current_app + current_app.logger.log(level, msg) + except: + pass + def pp(*args): from pprint import pprint import sys, codecs -- 2.39.3