commit ffbe866bc6b6760830325535300700b3f396926b Author: Halhadus Date: Sat Oct 5 08:48:49 2024 +0000 Scripts diff --git a/checkduplicate.py b/checkduplicate.py new file mode 100644 index 0000000..4b26f25 --- /dev/null +++ b/checkduplicate.py @@ -0,0 +1,18 @@ +duplicate = [] +with open("musiclist.txt", "r") as file: + lines = file.readlines() + for line in lines: + url = line.split("---")[1] + a = 0 + for line2 in lines: + url2 = line2.split("---")[1] + if url == url2: + a += 1 + if a >= 2: + if not line in duplicate: + duplicate.append(line) + else: + continue + +for duplines in duplicate: + print(duplines) diff --git a/main.py b/main.py new file mode 100644 index 0000000..839642c --- /dev/null +++ b/main.py @@ -0,0 +1,75 @@ +import yt_dlp +import os + +musiclist = [] +with open('musiclist.txt', 'r') as f: + for line in f: + if line.strip() == '': + continue + musicname, videoid, provider = line.strip().split('---') + musiclist.append({"musicname": musicname.strip(), "videoid": videoid.strip(), "provider": provider.strip()}) + +if os.path.exists('/mnt/sdcard/Music'): + download_location = '/mnt/sdcard/Music' +elif os.path.exists('/storage/emulated/0/Music'): + download_location = '/storage/emulated/0/Music' +elif os.path.exists('/sdcard/Music'): + download_location = '/sdcard/Music' +elif os.environ.get('HOME') is not None: + if os.path.exists(f'{os.environ["HOME"]}/Music'): + download_location = f'{os.environ["HOME"]}/Music' + else: + os.mkdir(f'{os.environ["HOME"]}/Music') + download_location = f'{os.environ["HOME"]}/Music' +else: + download_location = os.getcwd() + '/music' + +print(f'Downloading music to {download_location}') + +for music in musiclist: + if music["provider"] == 'YT': + youtube_link = f'https://www.youtube.com/watch?v={music["videoid"]}' + elif music["provider"] == 'YTM': + youtube_link = f'https://music.youtube.com/watch?v={music["videoid"]}' + music_name = music["musicname"] + # find anothor better way to remove not allowed characters and remove this stupid part + music_name = music_name.replace('/', '-') + music_name = music_name.replace('@', '') + music_name = music_name.replace('#', '') + music_name = music_name.replace('%', '') + music_name = music_name.replace('$', '') + music_name = music_name.replace('^', '') + music_name = music_name.replace('?', '') + music_name = music_name.replace('"', '') + music_name = music_name.replace("'", '') + music_name = music_name.replace(':', '') + music_name = music_name.replace('|', '') + music_name = music_name.replace('>', '') + music_name = music_name.replace('<', '') + music_name = music_name.replace('\\', '') + music_name = music_name.replace('&', '') + music_name = music_name.replace('+', '') + music_name = music_name.replace('=', '') + music_name = music_name.replace('~', '') + music_name = music_name.replace('`', '') + music_name = music_name.replace(';', '') + music_name = music_name.replace('*', '') + if os.path.exists(f'{download_location}/{music_name}.opus'): + print(f'{music_name} already exists') + continue + print(f'Downloading {music_name} from {youtube_link}') + yt_opts = { + 'format': 'bestaudio/best', + 'outtmpl': f'{music_name}.%(ext)s', + 'postprocessors': [ + {'key': 'FFmpegExtractAudio', 'preferredcodec': 'opus'}, + {'key': 'FFmpegMetadata', 'add_metadata': True}, + {'key': 'EmbedThumbnail'} + ], + 'writethumbnail': True, + 'quiet': True + } + yt = yt_dlp.YoutubeDL(yt_opts) + yt.download([youtube_link]) + print(f'{music_name} downloaded') + os.system(f'mv "{music_name}.opus" "{download_location}/{music_name}.opus"') diff --git a/playlisttotxt.py b/playlisttotxt.py new file mode 100644 index 0000000..90dc232 --- /dev/null +++ b/playlisttotxt.py @@ -0,0 +1,39 @@ +import csv +import os +import sys + +if len(sys.argv) != 2: + print('Usage: python3 playlisttotxt.py ') + sys.exit(1) +else: + csvname = sys.argv[1] + +with open(csvname, 'r') as file: + reader = csv.reader(file) + next(reader) + playlist = [] + for row in reader: + artist_name = row[3] + track_name = row[1] + playlist.append(f'{artist_name} - {track_name}') + +formatted_lines = [] +if os.path.exists('musiclist.txt'): + with open('musiclist.txt', 'r') as file: + lines = file.readlines() + for line in lines: + formatted_lines.append(line.split(' --- ')[0]) + +with open('musiclist.txt', 'a') as file: + for track in playlist: + if track in formatted_lines: + continue + else: + url = input(f'URL for {track}: ') + urlid = url.split('v=')[1] + if url.startswith('https://youtube.com/watch?v=') or url.startswith('https://www.youtube.com/watch?v='): + file.write(f'{track} --- {urlid} --- YT\n') + elif url.startswith('https://music.youtube.com/watch?v='): + file.write(f'{track} --- {urlid} --- YTM\n') + else: + print('Invalid URL')