add ping check

- fix artist downloader function
This commit is contained in:
geoffrey45
2022-06-20 09:49:16 +03:00
parent 3cf44759b5
commit 12c8406a0d
6 changed files with 48 additions and 15 deletions
+16 -3
View File
@@ -8,12 +8,12 @@ from datetime import datetime
from typing import Dict, Set
from typing import List
import requests
from app import models
from app import settings
from app import instances
app_dir = settings.APP_DIR
def background(func):
"""
@@ -73,6 +73,7 @@ def remove_duplicates(tracklist: List[models.Track]) -> List[models.Track]:
return tracklist
def is_valid_file(filename: str) -> bool:
"""
Checks if a file is valid. Returns True if it is, False if it isn't.
@@ -97,7 +98,7 @@ def check_artist_image(image: str) -> str:
Checks if the artist image is valid.
"""
img_name = image.replace("/", "::") + ".webp"
app_dir = settings.APP_DIR
if not os.path.exists(os.path.join(app_dir, "images", "artists", img_name)):
return use_memoji()
else:
@@ -194,3 +195,15 @@ class Get:
"""
p = instances.playlist_instance.get_all_playlists()
return [models.Playlist(p) for p in p]
class Ping:
"""Checks if there is a connection to the internet by pinging google.com"""
@staticmethod
def __call__() -> bool:
try:
requests.get("https://google.com")
return True
except requests.exceptions.ConnectionError:
return False