Skip to content

Yt dlp #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions code/convertermusica.py
Original file line number Diff line number Diff line change
@@ -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'_Caminho_para_o_executável_do_FFmpeg_',
}
#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()