2017-10-10 4 views
2

私はプログラミングには新しく、私はyoutubeから簡単なmp3ダウンローダを作っています。そして、私の質問では、私はどのようにfiledialog.askdirectory()ディレクトリをダウンロードした音楽に変更することができないのか気づいています。私は、ディレクトリを定義することができる場合は、以下を確認してください。pythonでディレクトリyoutube_dlを変更する方法

from tkinter import * 
from tkinter import filedialog 
from tkinter import messagebox 
import youtube_dl 

import sys 

root=Tk() 
root.resizable(0,0) 


def save(): 
    messagebox.showinfo('Wybór', 'Wybierz folder docelowy') 
    directory=filedialog.askdirectory() 
     ydl_opts = { 
     'format': 'bestaudio/best', 
     'postprocessors': [{ 
      'key': 'FFmpegExtractAudio', 
      'preferredcodec': 'mp3', 
      'preferredquality': '192', 
     }], 
    } 
    with youtube_dl.YoutubeDL(ydl_opts) as ydl: 
     ydl.download([e1.get()]) 


    messagebox.showinfo('Zakonczone','Pobieranie zakonczone') 



def exit(): 
    sys.exit() 


root.title('Youtube downloader') 
l1=Label(root,text='Wpisz adres url filmu Youtube',font=20) 
l1.pack() 
e1=Entry(root,width=50) 
e1.pack() 
b1=Button(root,text='Pobierz',width=7,height=2,command=save) 
b1.pack(side=LEFT) 
b2=Button(root,text='Wyjdź',command=exit,width=7,height=2) 
b2.pack(side=RIGHT) 




root.mainloop() 

答えて

0

は、構成内の指定したフォルダの使用outtmplでビデオをダウンロードするには。

私はdownloaded_musicという名前のフォルダを作成し、以下のようにコードを更新しました:

from tkinter import * 
from tkinter import filedialog 
from tkinter import messagebox 
import youtube_dl 

import sys 

root=Tk() 
root.resizable(0,0) 

def save(): 
    #messagebox.showinfo('Wybór', 'Wybierz folder docelowy') 
    #messagebox.showinfo('Folder Selection', 'Select download folder') 
    #directory=filedialog.askdirectory() 
    directory = 'downloaded_music' 
    ydl_opts = { 
     'outtmpl': 'downloaded_music/%(title)s-%(id)s.%(ext)s', 
     'format': 'bestaudio/best', 
     'postprocessors': [{ 
      'key': 'FFmpegExtractAudio', 
      'preferredcodec': 'mp3', 
      'preferredquality': '192', 
     }], 
    } 
    with youtube_dl.YoutubeDL(ydl_opts) as ydl: 
     ydl.download([e1.get()]) 
    #messagebox.showinfo('Zakonczone','Pobieranie zakonczone') 
    messagebox.showinfo('Success','Download completed') 

def exit(): 
    sys.exit() 

if __name__ == '__main__': 
    root.title('Youtube downloader') 
    #l1=Label(root,text='Wpisz adres url filmu Youtube',font=20) 
    l1=Label(root,text='Download MP3 from Youtube video',font=20) 
    l1.pack() 
    e1=Entry(root,width=50) 
    e1.pack() 
    #b1=Button(root,text='Pobierz',width=7,height=2,command=save) 
    b1=Button(root,text='Download',width=7,height=2,command=save) 
    b1.pack(side=LEFT) 
    #b2=Button(root,text='Wyjdź',command=exit,width=7,height=2) 
    b2=Button(root,text='Exit',command=exit,width=7,height=2) 
    b2.pack(side=RIGHT) 
    root.mainloop() 

今すぐダウンロードファイルはdownloaded_musicフォルダに格納されています。

関連する問題