2017-10-27 13 views
1
내가 YouTube에서 음악을 다운로드하기 위해이 스크립트를했고, 내 IDLE에서 작동하고 .exe로 compilated 후 여전히 그를 MP3에 노래를 변환 할 수 있도록

pyInstaller 중에 + 드라이버

from tkinter import * 
from tkinter import ttk 
from tkinter import messagebox 
from tkinter import filedialog 
import youtube_dl 
import os 



class f(object): 
    def __init__(self, finestra): 
     self.finestra = finestra 
     self.top = ttk.Frame(self.finestra, padding="10 10 10 10") 
     self.top.grid(column=5, row=5) 
     self.top.columnconfigure(1, weight=1) 
     self.top.rowconfigure(1, weight=1) 

     self.finestra.bind("<Return>",self.esegui_query) 

     self.link = StringVar() 
     self.esito = StringVar() 
     self.bitrate = StringVar() 
     self.esito.set("In Attesa") 

#RIGA 1 
     ttk.Label(self.top, text="Link:").grid(column=0,row=0) 
     ttk.Entry(self.top, textvariable=self.link).grid(column=1,row=0) 
     ttk.Button(self.top, text="Scarica", command=self.esegui_query).grid(column=2,row=0) 
#RIGA 2 
     ttk.Label(self.top, text="Bitrate:").grid(column=0,row=1) 
     r1 = Radiobutton(self.top, text="192", variable=self.bitrate, value="192", cursor="dot") 
     r1.grid(column=1,row=1) 
     r2 = Radiobutton(self.top, text="320", variable=self.bitrate, value="320", cursor="dot") 
     r2.grid(column=2,row=1) 
     r1.select() 
     ttk.Label(self.top, textvariable=self.esito).grid(column=3,row=1) 

    def esegui_query(self,*argv): 
     link = self.link.get() 
     bitrate=self.bitrate.get() 
     ydl_opts = { 
     #'format': 'bestaudio/best', 
     'postprocessors': [{ 
      'key': 'FFmpegExtractAudio', 
      'preferredcodec': 'mp3', 
      'preferredquality': bitrate, 
         }], 
        } 
     self.esito.set("Downloading...") 
     try: 
      with youtube_dl.YoutubeDL(ydl_opts) as ydl: 
       ydl.download([link]) 
      self.esito.set("Encoding...") 
      for file in (os.listdir('.')): 
       if file.endswith('.mp3') or file.endswith('.m4a') or file.endswith('.mp4'): 
        file2 = file[::-1][16:][::-1] 
        break 
      self.esito.set("Download Completato") 
     except Exception as e: 
      self.esito.set("ERRORE") 
      messagebox.showwarning("ERRORE",e) 



finestra = Tk() 
finestra.title("Download Youtube") 
f = f(finestra) 
finestra.mainloop() 

작동

, 나는 avprobe을 다운로드 운전사와 그들을 안으로 두었다

C:\Program Files\Python 3.5\Scripts 

가이드를 어떻게 말한다. 스크립트를 수 있도록 pyInstaller 중에으로 스크립트를 컴파일하는 것은 다른 PC에서 작동하는 동안

어떻게 그 드라이버를 포함 할 수

답변

0

당신은 여분의 데이터로 드라이버 (들)을 포함하도록을 .spec 파일을 편집 할 수 있습니다

a = Analysis(... 
datas=[ ('folder\your_driver', '.') ], 
... 
) 

https://pythonhosted.org/PyInstaller/spec-files.html

그러면 pyinstaller로 컴파일 할 때 드라이버가 복사됩니다. 문제는 모든 사용자의 시스템에서 드라이버를 찾을 수 있도록 드라이버의 위치가 .exe에 상대적인 동일한 위치에 있어야한다는 것입니다.

--resource RESOURCE 
:

또한 명령 행 인수를 사용할 수 있습니다