rssVideos: Clean up
This commit is contained in:
parent
95f568ebb9
commit
21fd49f096
|
@ -8,7 +8,6 @@ The common use case would be a feed from an RSS aggregator
|
||||||
with the unread items (non-video links are ignored).
|
with the unread items (non-video links are ignored).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import enum
|
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -17,12 +16,8 @@ import random
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
import urllib.error
|
|
||||||
|
|
||||||
import coloredlogs
|
import coloredlogs
|
||||||
import configargparse
|
import configargparse
|
||||||
|
@ -322,7 +317,7 @@ class RVDatabase:
|
||||||
self.auth_headers = cache.auth_headers
|
self.auth_headers = cache.auth_headers
|
||||||
|
|
||||||
def salvage_cache(self, cache: "RVDatabase") -> None:
|
def salvage_cache(self, cache: "RVDatabase") -> None:
|
||||||
log.debug(f"Salvaging cache")
|
log.debug("Salvaging cache")
|
||||||
cache_els = dict()
|
cache_els = dict()
|
||||||
for cache_el in cache.elements:
|
for cache_el in cache.elements:
|
||||||
cache_els[cache_el.guid] = cache_el
|
cache_els[cache_el.guid] = cache_el
|
||||||
|
@ -331,7 +326,7 @@ class RVDatabase:
|
||||||
el.salvage_cache(cache_els[el.guid])
|
el.salvage_cache(cache_els[el.guid])
|
||||||
|
|
||||||
def clean_cache(self, cache: "RVDatabase") -> None:
|
def clean_cache(self, cache: "RVDatabase") -> None:
|
||||||
log.debug(f"Cleaning cache")
|
log.debug("Cleaning cache")
|
||||||
self_els = dict()
|
self_els = dict()
|
||||||
for self_el in self.elements:
|
for self_el in self.elements:
|
||||||
self_els[self_el.guid] = self_el
|
self_els[self_el.guid] = self_el
|
||||||
|
@ -341,7 +336,7 @@ class RVDatabase:
|
||||||
el.clean()
|
el.clean()
|
||||||
|
|
||||||
def import_cache(self, cache: "RVDatabase") -> None:
|
def import_cache(self, cache: "RVDatabase") -> None:
|
||||||
log.debug(f"Importing cache")
|
log.debug("Importing cache")
|
||||||
self.build_list([element.item for element in cache.elements])
|
self.build_list([element.item for element in cache.elements])
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
|
@ -614,13 +609,7 @@ def get_args() -> configargparse.Namespace:
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def get_database(args: configargparse.Namespace) -> RVDatabase:
|
||||||
args = get_args()
|
|
||||||
configure_logging(args)
|
|
||||||
|
|
||||||
os.makedirs(args.videos, exist_ok=True)
|
|
||||||
os.chdir(args.videos)
|
|
||||||
|
|
||||||
database = RVDatabase(args)
|
database = RVDatabase(args)
|
||||||
cache = RVDatabase.load()
|
cache = RVDatabase.load()
|
||||||
feed_fetched = False
|
feed_fetched = False
|
||||||
|
@ -635,6 +624,7 @@ def main() -> None:
|
||||||
raise RuntimeError("Couldn't fetch feed, refusing to download")
|
raise RuntimeError("Couldn't fetch feed, refusing to download")
|
||||||
# This is a quirky failsafe in case of no internet connection,
|
# This is a quirky failsafe in case of no internet connection,
|
||||||
# so the script doesn't go noting that no element is a video.
|
# so the script doesn't go noting that no element is a video.
|
||||||
|
log.warning(f"Couldn't fetch feed: {err}")
|
||||||
if not feed_fetched:
|
if not feed_fetched:
|
||||||
if cache:
|
if cache:
|
||||||
log.warning("Using cached feed.")
|
log.warning("Using cached feed.")
|
||||||
|
@ -646,7 +636,19 @@ def main() -> None:
|
||||||
database.clean_cache(cache)
|
database.clean_cache(cache)
|
||||||
database.save()
|
database.save()
|
||||||
|
|
||||||
log.debug(f"Running action")
|
return database
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
args = get_args()
|
||||||
|
configure_logging(args)
|
||||||
|
|
||||||
|
os.makedirs(args.videos, exist_ok=True)
|
||||||
|
os.chdir(args.videos)
|
||||||
|
|
||||||
|
database = get_database(args)
|
||||||
|
|
||||||
|
log.debug("Running action")
|
||||||
if args.action == "clean":
|
if args.action == "clean":
|
||||||
database.clean()
|
database.clean()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue