2022-10-26 15:42:11 +00:00
|
|
|
import metadata.metadata
|
2022-10-17 12:56:32 +00:00
|
|
|
import download_links
|
2022-10-17 22:27:30 +00:00
|
|
|
import url_to_path
|
2022-10-18 16:48:24 +00:00
|
|
|
import download
|
2022-10-21 19:24:38 +00:00
|
|
|
|
2022-10-17 17:28:33 +00:00
|
|
|
import logging
|
2022-10-21 19:24:38 +00:00
|
|
|
import os
|
2022-10-17 17:28:33 +00:00
|
|
|
|
2022-10-24 11:55:34 +00:00
|
|
|
|
2022-10-17 17:28:33 +00:00
|
|
|
TEMP = "temp"
|
|
|
|
STEP_ONE_CACHE = ".cache1.csv"
|
|
|
|
STEP_TWO_CACHE = ".cache2.csv"
|
2022-10-18 16:48:24 +00:00
|
|
|
STEP_THREE_CACHE = ".cache3.csv"
|
2022-10-17 17:28:33 +00:00
|
|
|
|
2022-10-24 11:11:32 +00:00
|
|
|
NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea"
|
2022-10-21 19:24:38 +00:00
|
|
|
MUSIC_DIR = os.path.expanduser('~/Music')
|
2022-10-26 15:42:11 +00:00
|
|
|
TOR = True
|
2022-10-19 15:47:48 +00:00
|
|
|
|
2022-10-17 17:28:33 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2022-10-14 14:55:23 +00:00
|
|
|
|
|
|
|
|
2022-10-24 11:11:32 +00:00
|
|
|
def get_existing_genre():
|
|
|
|
valid_directories = []
|
|
|
|
for elem in os.listdir(MUSIC_DIR):
|
|
|
|
if elem not in NOT_A_GENRE:
|
|
|
|
valid_directories.append(elem)
|
|
|
|
|
|
|
|
return valid_directories
|
|
|
|
|
|
|
|
|
2022-10-14 14:55:23 +00:00
|
|
|
def search_for_metadata(query: str):
|
2022-10-26 15:42:11 +00:00
|
|
|
search = metadata.metadata.Search(query=query, temp=TEMP)
|
2022-10-14 14:55:23 +00:00
|
|
|
|
|
|
|
print(search.options)
|
|
|
|
while True:
|
2022-10-17 17:28:33 +00:00
|
|
|
input_ = input(
|
|
|
|
"q to quit, ok to download, .. for previous options, . for current options, int for this element: ").lower()
|
2022-10-14 14:55:23 +00:00
|
|
|
input_.strip()
|
|
|
|
if input_ == "q":
|
|
|
|
exit(0)
|
|
|
|
if input_ == "ok":
|
|
|
|
return search
|
|
|
|
if input_ == ".":
|
|
|
|
print(search.options)
|
|
|
|
continue
|
|
|
|
if input_ == "..":
|
|
|
|
print(search.get_previous_options())
|
|
|
|
continue
|
|
|
|
if input_.isdigit():
|
|
|
|
print(search.choose(int(input_)))
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
2022-10-24 11:11:32 +00:00
|
|
|
def get_genre():
|
|
|
|
existing_genres = get_existing_genre()
|
|
|
|
print("printing available genres:")
|
|
|
|
for i, genre_option in enumerate(existing_genres):
|
|
|
|
print(f"{i}: {genre_option}")
|
|
|
|
|
|
|
|
genre = input("Input the ID for an existing genre or text for a new one: ")
|
|
|
|
|
|
|
|
if genre.isdigit():
|
|
|
|
genre_id = int(genre)
|
|
|
|
if genre_id >= len(existing_genres):
|
|
|
|
logging.warning("An invalid genre id has been given")
|
|
|
|
return get_genre()
|
|
|
|
return existing_genres[genre_id]
|
|
|
|
|
|
|
|
return genre
|
|
|
|
|
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
def cli(start_at: int = 0):
|
2022-10-26 15:42:11 +00:00
|
|
|
proxies = None
|
2022-10-19 15:47:48 +00:00
|
|
|
if TOR:
|
2022-10-26 15:42:11 +00:00
|
|
|
proxies = {
|
2022-10-19 15:47:48 +00:00
|
|
|
'http': 'socks5h://127.0.0.1:9150',
|
|
|
|
'https': 'socks5h://127.0.0.1:9150'
|
|
|
|
}
|
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
if start_at <= 2:
|
2022-10-24 11:11:32 +00:00
|
|
|
genre = get_genre()
|
|
|
|
logging.info(f"{genre} has been set as genre.")
|
2022-10-18 16:48:24 +00:00
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
if start_at <= 0:
|
|
|
|
search = search_for_metadata(query=input("initial query: "))
|
|
|
|
logging.info("Starting Downloading of metadata")
|
|
|
|
search.download(file=STEP_ONE_CACHE)
|
2022-10-14 14:55:23 +00:00
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
if start_at <= 1:
|
|
|
|
logging.info("Fetching Download Links")
|
2022-10-26 15:42:11 +00:00
|
|
|
download_links.Download(file=STEP_TWO_CACHE, metadata_csv=STEP_ONE_CACHE, temp=TEMP, proxies=proxies)
|
2022-10-17 22:27:30 +00:00
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
if start_at <= 2:
|
|
|
|
logging.info("creating Paths")
|
|
|
|
url_to_path.UrlPath(genre=genre)
|
2022-10-17 12:56:32 +00:00
|
|
|
|
2022-10-21 21:50:18 +00:00
|
|
|
if start_at <= 3:
|
|
|
|
logging.info("starting to download the mp3's")
|
2022-10-26 15:42:11 +00:00
|
|
|
download.Download(proxies=proxies, file=STEP_THREE_CACHE, temp=TEMP, base_path=MUSIC_DIR)
|
2022-10-18 16:48:24 +00:00
|
|
|
|
2022-10-14 14:55:23 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-10-24 11:11:32 +00:00
|
|
|
cli(start_at=0)
|