-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
48 lines (36 loc) · 1.36 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import subprocess
import requests
from urllib.parse import urlparse, parse_qs
def get_image_bytes(url):
response = requests.get(url, timeout=5)
response.raise_for_status()
return response.content
def is_ffmpeg_installed():
try:
# Run the ffmpeg command to check if it is installed
subprocess.run(['ffmpeg', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return True
except subprocess.CalledProcessError:
print("ffmpeg is installed, but returned an error")
except FileNotFoundError:
print("ffmpeg is not installed")
return False
def isValidYouTubeURL(url):
parsed_url = urlparse(url)
return "youtube.com" in parsed_url.netloc or "youtu.be" in parsed_url.netloc
def isValidSpotifyURL(url):
parsed_url = urlparse(url)
return "spotify.com" in parsed_url.netloc or "open.spotify.com" in parsed_url.netloc
def isSpotifyTrack(url):
parsed_url = urlparse(url)
return "track" in parsed_url.path
def isPlaylist(url):
parsed_url = urlparse(url)
query_params = parse_qs(parsed_url.query)
# Check if the 'list' parameter exists
return 'list' in query_params
def isVideo(url):
parsed_url = urlparse(url)
query_params = parse_qs(parsed_url.query)
# Check if the 'v' parameter exists
return 'v' in query_params or parsed_url.netloc == "youtu.be"