2023-04-12 10:15:12 +00:00
|
|
|
from typing import List, Set, Tuple
|
2022-11-11 23:29:07 +00:00
|
|
|
import logging
|
|
|
|
import tempfile
|
|
|
|
import os
|
2022-11-24 22:22:06 +00:00
|
|
|
import configparser
|
|
|
|
from sys import platform as current_os
|
2023-04-03 08:38:12 +00:00
|
|
|
from pathlib import Path
|
2023-04-04 18:19:29 +00:00
|
|
|
import random
|
|
|
|
|
2023-04-13 17:27:53 +00:00
|
|
|
from .path_manager import LOCATIONS
|
|
|
|
|
2023-04-04 20:07:56 +00:00
|
|
|
# modifies the garbage collector to speed up the program
|
|
|
|
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
|
|
|
# https://web.archive.org/web/20221124122222/https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
|
|
|
MODIFY_GC: bool = True
|
|
|
|
|
2023-04-04 18:19:29 +00:00
|
|
|
"""
|
|
|
|
I will now and then use those messages in the programm.
|
|
|
|
But I won't overuse them dw.
|
|
|
|
|
|
|
|
I will keep those messages, if you disagree with me on the messages,
|
|
|
|
feel free to fork the programm and edit them, or just edit them in the config
|
|
|
|
file once I implemented it.
|
|
|
|
"""
|
|
|
|
HAPPY_MESSAGES: List[str] = [
|
|
|
|
"Support the artist.",
|
|
|
|
"Star Me: https://github.com/HeIIow2/music-downloader",
|
|
|
|
"🏳️⚧️🏳️⚧️ Trans rights are human rights. 🏳️⚧️🏳️⚧️",
|
|
|
|
"🏳️⚧️🏳️⚧️ Trans women are women, trans men are men. 🏳️⚧️🏳️⚧️",
|
|
|
|
"🏴☠️🏴☠️ Unite under one flag, fuck borders. 🏴☠️🏴☠️",
|
|
|
|
"Join my Matrix Space: https://matrix.to/#/#music-kraken:matrix.org",
|
2023-04-05 08:08:27 +00:00
|
|
|
"Gotta love the BPJM!! >:(",
|
|
|
|
"🏳️⚧️🏳️⚧️ Protect trans youth. 🏳️⚧️🏳️⚧️"
|
2023-04-04 18:19:29 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def get_random_message() -> str:
|
|
|
|
return random.choice(HAPPY_MESSAGES)
|
2022-11-11 23:29:07 +00:00
|
|
|
|
2022-11-28 13:49:13 +00:00
|
|
|
|
2023-04-12 10:15:12 +00:00
|
|
|
ID_BITS: int = 64
|
2023-04-13 16:52:03 +00:00
|
|
|
ID_RANGE: Tuple[int, int] = (0, int(2**ID_BITS))
|
2023-04-12 10:15:12 +00:00
|
|
|
|
2023-04-13 17:27:53 +00:00
|
|
|
TEMP_DIR = LOCATIONS.TEMP_DIRECTORY
|
|
|
|
LOG_PATH = LOCATIONS.get_log_file("download_logs.log")
|
|
|
|
MUSIC_DIR: Path = LOCATIONS.MUSIC_DIRECTORY
|
2023-04-13 16:52:03 +00:00
|
|
|
|
2022-11-22 13:53:29 +00:00
|
|
|
|
2022-11-17 12:23:27 +00:00
|
|
|
# configure logger default
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format=logging.BASIC_FORMAT,
|
|
|
|
handlers=[
|
2023-04-05 07:35:52 +00:00
|
|
|
logging.FileHandler(Path(TEMP_DIR, LOG_PATH)),
|
2022-11-17 12:23:27 +00:00
|
|
|
logging.StreamHandler()
|
|
|
|
]
|
|
|
|
)
|
2022-11-11 23:29:07 +00:00
|
|
|
|
2023-04-04 19:10:47 +00:00
|
|
|
OBJECT_LOGGER = logging.getLogger("objects")
|
|
|
|
TARGET_LOGGER = logging.getLogger("target")
|
2022-11-11 23:29:07 +00:00
|
|
|
DATABASE_LOGGER = logging.getLogger("database")
|
2023-04-04 19:10:47 +00:00
|
|
|
|
2022-11-16 12:21:30 +00:00
|
|
|
YOUTUBE_LOGGER = logging.getLogger("Youtube")
|
2022-11-17 12:23:27 +00:00
|
|
|
MUSIFY_LOGGER = logging.getLogger("Musify")
|
2022-11-11 23:29:07 +00:00
|
|
|
GENIUS_LOGGER = logging.getLogger("genius")
|
2023-01-24 08:40:01 +00:00
|
|
|
ENCYCLOPAEDIA_METALLUM_LOGGER = logging.getLogger("ma")
|
|
|
|
|
2023-04-04 19:10:47 +00:00
|
|
|
DOWNLOAD_LOGGER = logging.getLogger("download")
|
2023-04-04 19:18:56 +00:00
|
|
|
TAGGING_LOGGER = logging.getLogger("tagging")
|
2023-04-05 14:11:30 +00:00
|
|
|
CODEX_LOGGER = logging.getLogger("codex")
|
2023-04-04 19:10:47 +00:00
|
|
|
|
2023-04-13 16:52:03 +00:00
|
|
|
NOT_A_GENRE_REGEX: Tuple[str] = (
|
2023-04-05 08:01:51 +00:00
|
|
|
r'^\.', # is hidden/starts with a "."
|
|
|
|
)
|
2022-11-11 23:29:07 +00:00
|
|
|
|
2023-04-05 08:01:51 +00:00
|
|
|
TOR: bool = False
|
2022-11-11 23:29:07 +00:00
|
|
|
proxies = {
|
|
|
|
'http': 'socks5h://127.0.0.1:9150',
|
|
|
|
'https': 'socks5h://127.0.0.1:9150'
|
|
|
|
} if TOR else {}
|
2022-11-16 12:21:30 +00:00
|
|
|
|
2023-04-05 15:40:22 +00:00
|
|
|
|
|
|
|
# Only the formats with id3 metadata can be used
|
|
|
|
# https://www.audioranger.com/audio-formats.php
|
|
|
|
# https://web.archive.org/web/20230322234434/https://www.audioranger.com/audio-formats.php
|
|
|
|
ALLOWED_FILE_FORMATS: Set[str] = {
|
|
|
|
"mp3", "mp2", "mp1", # MPEG-1 ID3.2
|
|
|
|
"wav", "wave", "rmi", # RIFF (including WAV) ID3.2
|
|
|
|
"aiff", "aif", "aifc", # AIFF ID3.2
|
|
|
|
"aac", "aacp", # Raw AAC ID3.2
|
|
|
|
"tta", # True Audio ID3.2
|
|
|
|
"ape", # Monkey's Audio ID3.1
|
|
|
|
"mpc", "mpp", "mp+", # MusePack ID3.1
|
|
|
|
"wv", # WavPack ID3.1
|
|
|
|
"ofr", "ofs" # OptimFrog ID3.1
|
|
|
|
}
|
|
|
|
|
|
|
|
# kB per second
|
|
|
|
BITRATE = 125
|
|
|
|
AUDIO_FORMAT = "mp3"
|
|
|
|
if AUDIO_FORMAT not in ALLOWED_FILE_FORMATS:
|
|
|
|
raise ValueError(f"The Audio Format is not in {ALLOWED_FILE_FORMATS} ({AUDIO_FORMAT}).")
|
|
|
|
|
2023-04-03 08:38:12 +00:00
|
|
|
"""
|
|
|
|
available variables:
|
|
|
|
- genre
|
|
|
|
- label
|
|
|
|
- artist
|
|
|
|
- album
|
|
|
|
- song
|
2023-04-04 08:43:52 +00:00
|
|
|
- album_type
|
2023-04-03 08:38:12 +00:00
|
|
|
"""
|
2023-04-04 08:43:52 +00:00
|
|
|
DOWNLOAD_PATH = "{genre}/{artist}/{album_type}/{album}"
|
2023-04-05 15:40:22 +00:00
|
|
|
DOWNLOAD_FILE = "{song}.{audio_format}"
|
2023-04-03 08:38:12 +00:00
|
|
|
DEFAULT_VALUES = {
|
|
|
|
"genre": "Various Genre",
|
|
|
|
"label": "Various Labels",
|
|
|
|
"artist": "Various Artists",
|
|
|
|
"album": "Various Album",
|
|
|
|
"song": "Various Song",
|
2023-04-05 15:40:22 +00:00
|
|
|
"album_type": "Other",
|
|
|
|
"audio_format": AUDIO_FORMAT
|
2023-04-03 08:38:12 +00:00
|
|
|
}
|
2023-04-05 15:40:22 +00:00
|
|
|
|
2023-04-04 15:59:08 +00:00
|
|
|
|
|
|
|
# size of the chunks that are streamed
|
|
|
|
CHUNK_SIZE = 1024
|
2023-04-04 19:06:33 +00:00
|
|
|
# this is a percentage describing the percentage of failed downloads,
|
|
|
|
# relative to the total downloads.
|
|
|
|
# If the percentage goes over this threshold DownloadResult returns the download errors
|
|
|
|
# in the __str__ method
|
|
|
|
SHOW_DOWNLOAD_ERRORS_THRESHOLD = 0.3
|