標籤

bat (52) 作品 (38) python (21) shell (17) windows (11) 虛擬機 (11) php (10) CPP (6) KMS (6) 程式設計 (6) docker (5) 使用教學 (5) xoops (4) 公文 (4) Apache2 (3) Excel (3) juniper (3) 資料庫 (3) mysql (2) 免動手 (2) 資料結構 (2) 軟體廣播 (2) 電腦維修 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) LAMP (1) NAS (1) Ubuntu (1) VHD (1) Windows Server (1) 原因 (1) 程式應用 (1) 程式積木 (1) 編輯器 (1) 雲端硬碟 (1)

2022年11月3日 星期四

只要點兩下,就能離開位子。讓電腦依照規劃自動下載YT影片


        由於教學上需要,需要從YouTube下載影片。希望能夠做到只要點兩下,就能離開位子。讓電腦依照規劃自動下載YouTube影片。網路上有許多教學如下:
1.Kej's FLV Retriever:
使用Kej's FLV Retriever 將影片網址貼上,按下RETRIEVE NOW! 按鈕後,就會出現下載網址,點選下載網址就可以下載了。但是卻遇到這個畫面:
2.將YouTube影片網址去除ube:
將YouTube影片網址去除ube,就會進到https://yout.com/的網站,選擇所需的格式,就可以下載了,只是下載次數有限制且下載速度慢。但是未來還要收費。
3.使用Youtube Downloader HD程式:
只要將影片網址,按下按鈕,就可以下載。若有一大堆影片需要下載,就要一個一個地下載。不能設定好網址後,批次下載。
        整理一下自己的需求。若自己看到好的教學影片,只要將影片網址記錄在一個TXT檔,只要點兩下,就能依照TXT的規劃,自動地一個一個地下載。換句話說,只要規劃好TXT,點兩下,就可以離開位子,讓電腦自動下載。
下載檔案。解壓密碼:demo1234
使用步驟:

檔案名稱:P001.py
檔案內容:
from pytube import YouTube
from pytube.cli import on_progress
import os

class YouTubeDownloader:
    def __init__(self,URL,FolderPath):
        self.Url = URL
        self.FolderPath = FolderPath
   
    def onProgress(self,stream,chunk,remains):
        total = stream.filesize
        percent = (total-remains)/total*100
        print(f'下載中… {percent:05.2f}%', end='\r')

    def YTDownloader(self):
        yt = YouTube(self.Url,on_progress_callback=self.onProgress)
        print(yt.title+" downloading....")
        yt.streams.filter().get_highest_resolution().download(self.FolderPath)
        print("Download "+yt.title+" OK!")

class OpenFiles():
    #開啟檔案

    def __init__(self,FileName,FolderName):
        self.FileName = FileName
        self.FolderName = FolderName
   
    def FileContentList(self):
        #設定信件內容檔名並取得檔案內容並回傳List
        ContentFileName = str(os.path.abspath(os.getcwd()))+"\\"+self.FileName
        ContentFile = open(ContentFileName,'r')
        FileContentList = ContentFile.readlines()
        ContentFile.close()
        return FileContentList
   
    def GetFolderPath(self):
        #取得資料夾路徑
        if os.path.exists(self.FolderName):
            FolderPath = str(os.path.abspath(os.getcwd()))+"\\"+self.FolderName
        else:
            os.mkdir(self.FolderName)
            FolderPath = str(os.path.abspath(os.getcwd()))+"\\"+self.FolderName

        return FolderPath
   
fcl = OpenFiles('下載名單.txt','').FileContentList()
gfp = OpenFiles('','download').GetFolderPath()
for i in fcl:
    temp=i.replace('\n','')
    YouTubeDownloader(temp,gfp).YTDownloader()

os.system("pause")
os.system("exit")

資料來源:

沒有留言:

張貼留言

只要點兩下,傳統右鍵選單改回Win11右鍵選單

系列文章: 1. 只要點兩下,就能將Win11 右鍵選單 回復 傳統右鍵選單 2. 只要點兩下,傳統右鍵選單改回Win11右鍵選單 上一篇提到只要點兩下,就能將Win11選單回到傳統選單。但是有沒有方法能夠回到Win11選單呢?                    ...