From 0d2ab43be349c7ad8ee9fa20ade30743b2f1c598 Mon Sep 17 00:00:00 2001 From: Thales Rangel Date: Sun, 24 Nov 2024 15:32:00 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Novo=20c=C3=B3digo=20para=20baixar=20m?= =?UTF-8?q?=C3=BAsicas=20do=20YouTube=20de=20forma=20funcional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 + .idea/vcs.xml | 6 ++ .idea/workspace.xml | 78 +++++++++++++++++++ code/convertermusica.py | 34 ++++---- 5 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..060d2c5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..fd73aaf --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + { + "associatedIndex": 6 +} + + + + + + + + + + + + + + + + + + + + 1719090776295 + + + + \ No newline at end of file diff --git a/code/convertermusica.py b/code/convertermusica.py index 691d882..75f95c2 100644 --- a/code/convertermusica.py +++ b/code/convertermusica.py @@ -1,25 +1,27 @@ -from pytube import YouTube from pathlib import Path -import re import os -import moviepy.editor as mp +import yt_dlp + def download_music(): - with open(r"C:\Users\pedrolmbs\spotifycrackeado\musicas.txt") as musicas_txt: + with open(r"_Caminho_de_um_arquivo_de_texto_com_os_links_das_músicas_no_Youtube") as musicas_txt: for linha in musicas_txt: link = linha - path = (r"C:\Users\pedrolmbs\spotifycrackeado\musicas") - yt = YouTube(link) + path = (r"_Diretório_para_onde_as_músicas_vão_") + ydl_opts = { + 'format': 'bestaudio/best', + 'outtmpl': os.path.join(path, '%(title)s.%(ext)s'), + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }], + 'ffmpeg_location': r'C:\Users\thale\OneDrive\Documentos\ffmpeg\ffmpeg-master-latest-win64-gpl-shared\bin', + } #Fazer o dowload - ys = yt.streams.filter(only_audio=True).first().download(path) - #Converter o video(mp4) para mp3 - for file in os.listdir(path): #For para percorrer dentro da pasta passada anteriormente - if re.search('mp4', file): #If verificando se o arquivo e .MP4 - mp4_path = os.path.join(path , file) #Cria uma variavel para armazenar o arquivo .MP4 - mp3_path = os.path.join(path, os.path.splitext(file)[0]+'.mp3') #Variavel que cria o nome do arquivo e adiciona .MP3 ao final - new_file = mp.AudioFileClip(mp4_path) #Cria o arquivo de áudio (.MP3) - new_file.write_audiofile(mp3_path) #Renomeia o arquivo, setando o nome criado anteriormente - os.remove(mp4_path) #Remove o arquivo .MP4 - print("Download Completo") + + with yt_dlp.YoutubeDL(ydl_opts) as ydl: + ydl.download([link]) + print("Download completo") download_music() \ No newline at end of file From d56a1607391e8ad2c9e67091a5930a7613bb5ba7 Mon Sep 17 00:00:00 2001 From: Thales Rangel Date: Sun, 24 Nov 2024 17:07:43 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20do=20caminho=20do?= =?UTF-8?q?=20FFmpeg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/convertermusica.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/convertermusica.py b/code/convertermusica.py index 75f95c2..84e0610 100644 --- a/code/convertermusica.py +++ b/code/convertermusica.py @@ -16,7 +16,7 @@ def download_music(): 'preferredcodec': 'mp3', 'preferredquality': '192', }], - 'ffmpeg_location': r'C:\Users\thale\OneDrive\Documentos\ffmpeg\ffmpeg-master-latest-win64-gpl-shared\bin', + 'ffmpeg_location': r'_Caminho_para_o_executável_do_FFmpeg_', } #Fazer o dowload