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



資料來源:




2022年11月24日 星期四

利用虛擬機來實作Veyon 軟體廣播安裝教師機與學生機

 
       最近要在電腦教室讓老師們實作Veyon 軟體廣播安裝。希望老師能夠利用眼前的電腦,來完成實作。可是Veyon 軟體廣播安裝實作,需要有教師機與學生機。於是便想到虛擬機,其規劃如下:

實作步驟:

2.教師機安裝

3.教師機設定--公鑰要保留,等下還要匯入學生機

4.學生機安裝

    整個安裝過程跟教師機安裝大致相同,唯一的差別在:

5.學生機設定

    接下來,要匯入教師機的公鑰

    接下來,要查詢學生機的IP,並記住IP。要到教師機設定。

6.教師機監看學生機的設定
    開始監看


資料來源:

利用虛擬機來實作Veyon 軟體廣播安裝教師機與學生機-事前準備工作

 
       最近要在電腦教室讓老師們實作Veyon 軟體廣播安裝。希望老師能夠利用眼前的電腦,來完成實作。可是Veyon 軟體廣播安裝實作,需要有教師機與學生機。於是便想到虛擬機,其規劃如下:

事前準備:

準備步驟:
1.在教師機(Host) 安裝 VM workstation player
2.在VM workstation player 安裝Windows 10 虛擬機
3.用小畫家做出[教師機.bmp]與[學生機.bmp],其畫面如下:



4.對[教師機.bmp]按滑鼠右鍵,出現下拉式選單。選擇設成桌面背景

5.在Windows 10 虛擬機內,對[學生機.bmp]按滑鼠右鍵,出現下拉式選單。選擇設成桌面背景

2022年11月7日 星期一

只要點兩下,就能離開位子。讓電腦依照公開的PlayList自動下載YT多媒體

        由於在學校分享了只要點兩下,就能離開位子。讓電腦依照規劃自動下載YouTube影片。學校同事希望可以貼上公開的PlayList網址與Mp3 或Mp4 ,接下來就是點兩下,離開座位,讓電腦依照PlayList自動下載YouTube多媒體(Mp3或Mp4)。
        開發過程中,發現下載YouTube多媒體後,儲存在電腦內的檔案會有編碼問題,導致下載中斷。YouTube多媒體的名稱會有簡體字、\ 等問題,導致編碼問題。那就等整個下載完畢後,再利用Python來處理檔案名稱,沒想到還是編碼問題。想了四天,苦思無解。主要原因是無法繞過檔案名稱的編碼問題。
        後來,為了能夠做到[只要點兩下,就讓電腦教室學生機可以解除網站鎖定]。讓電腦教室也能讓教師研習使用,必須解除網站鎖定,免得研習無法進行。進行BAT的開發,沒想到發現了
ren *.mp4 *.mp3 。原因是 * 在BAT 是萬用字元,就可以繞過檔案名稱的編碼問題。

下載檔案。解壓密碼:demo1234

使用步驟教學:

檔案名稱:P002.py
檔案內容:
from pytube import Playlist
from ClassFunc import OpenFiles
from ClassFunc import YouTubeDownloader

gfp = OpenFiles('','download').GetFolderPath()
fcl = OpenFiles('YouTubePlayList.txt','').FileContentList()
TempType = OpenFiles('Mp3orMp4.txt','').FileContentList()
TempType.pop(0)
print(TempType)
for i in fcl:
    TempPlayList = Playlist(i)
    if TempPlayList.video_urls == []:
        print("您的playlist 可能是私有 或是 不公開")
    else:
        for j in TempPlayList.video_urls:
            for k in TempType:
                if k.upper() =='MP3':
                    YouTubeDownloader(j,gfp).YTMp3Downloader()
                elif k.upper() =='MP4':
                    YouTubeDownloader(j,gfp).YTDownloader()

for i in TempType:
    if i.upper() =='MP3':
        print("**************************************************")
        print("您選擇下載mp3檔案,由於編碼的關係,下載時檔案為mp4")
        print("請您於下載完畢後,點選[轉換副檔名為mp3.bat]")
        print("[轉換副檔名為mp3.bat]會完成轉換副檔名由mp4改為mp3")
        print("*************************************************")

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


檔案名稱:ClassFunc.py
檔案內容:
from pytube import YouTube
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+".mp4"+" downloading....")
        yt.streams.filter().get_highest_resolution().download(self.FolderPath)
        print("Download "+".mp4"+yt.title+".mp4"+" OK!")
   
    def YTMp3Downloader(self):
        yt = YouTube(self.Url,on_progress_callback=self.onProgress)
        print(yt.title+".mp4"+" downloading....")
        yt.streams.filter().get_audio_only().download(self.FolderPath)
        print("Download "+yt.title+".mp4"+" 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

檔案名稱:轉換副檔名為mp3.bat
檔案內容:
@echo off 
REM 讀取檔案

for /f "skip=1 delims=" %%a in (Mp3orMp4.txt) do (
    set mp3txt=%%~a
)
echo %mp3txt%
if "%mp3txt%"=="mp3" (
cd  %~dp0\download\
ren *.mp4 *.mp3
)

PAUSE
EXIT


資料來源:
1.Using Playlists
2.下載 Youtube 清單中所有影片
3.只要點兩下,就能離開位子。讓電腦依照規劃自動下載YouTube影片


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")

資料來源:

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

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