swingmusic/app/functions.py
geoffrey45 6818f9b0e8 handle watchdog's file created event using the on_modified
handler

+ move processing thumbnails and album colors to the populate class
+ move processing artist colors behind the populate call in run_periodic_checks
2023-01-25 13:43:09 +03:00

42 lines
1.1 KiB
Python

"""
This module contains functions for the server
"""
import time
from requests import ConnectionError as RequestConnectionError
from requests import ReadTimeout
from app import utils
from app.lib.artistlib import CheckArtistImages
from app.lib.colorlib import ProcessAlbumColors, ProcessArtistColors
from app.lib.populate import Populate, ProcessTrackThumbnails, PopulateCancelledError
from app.lib.trackslib import validate_tracks
from app.logger import log
@utils.background
def run_periodic_checks():
"""
Checks for new songs every N minutes.
"""
# ValidateAlbumThumbs()
# ValidatePlaylistThumbs()
validate_tracks()
while True:
try:
Populate(key=utils.get_random_str())
except PopulateCancelledError:
pass
if utils.Ping()():
try:
CheckArtistImages()
except (RequestConnectionError, ReadTimeout):
log.error(
"Internet connection lost. Downloading artist images stopped."
)
ProcessArtistColors()
time.sleep(300)