2022年11月26日 星期六

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

下載檔案解壓密碼:demo1234
使用步驟教學:

        最近同事問我,可不可以下載FaceBook的影片作為教學影片?於是就開始嘗試去寫程式來完成這件事。 
        更由於先前的程式可以依照規劃與公開的PlayList來下載YouTube多媒體,網友提供了Youtube-dl 這個套件可以下載FB的影片。後來找Google大神,發現Youtube-dl功能很強大。原始網站https://github.com/ytdl-org/youtube-dl 提供了命令列功能與支援的網站https://github.com/ytdl-org/youtube-dl/blob/master/docs/supportedsites.md。但是我卻想要用Python程式來試試。可是問題來了,我該怎麼在Python用Youtube-dl這個套件?於是找大神,關鍵字是python youtube-dl example,沒想到找到資料來源1.Python youtube_dl.YoutubeDL() Examples。那我就開始測試,第一個測試程式如下:
程式目的:測試Youtube-dl是否能下載FB多媒體
程式名稱:test.py
程式內容:
import youtube_dl

ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://fb.watch/h21zao5IVE/'])
結果:
        很開心,發現可以下載FB多媒體。
        那要如何取得FB多媒體的網址呢?
        以FireFox為例,如下所示:


程式目的:下載FB多媒體
程式名稱:FbMp4Download.py
程式內容:
import youtube_dl
import os
from ClassFunc import OpenFiles

fcl = OpenFiles('下載名單.txt','').FileContentList()
ydl_opts = {
    'noplaylist': True
}
for i in fcl:
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([i])

程式目的:常用程式類別
程式名稱:ClassFunc.py
程式內容:
import os

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



資料來源:




沒有留言:

張貼留言

Laravel 12 Model 資料庫中的資料表,並提供與資料庫互動的介面

相關系列文章: 1. 在 windows 10 安裝 laravel 12 studentManagement環境與設定 2. laravel 12 route 路由 3. laravel 12 Blade Templates 網頁模版 4. laravel 12 Control...