標籤

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)

2023年2月21日 星期二

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

 系列文章:


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

     感恩員東國小徐千惠資訊組長的建議。
     由於學生練舞需要有配樂。除了下載影片MP4,也能下載MP3,希望能簡便使用。換言之,只要貼上所有網址,只要點兩下就能將MP3或MP4下載。在2.只要點兩下,就能離開位子。讓電腦依照公開的PlayList自動下載YT多媒體中,利用公開playlist,來下載MP3或MP4。現在則改寫1.只要點兩下,就能離開位子。讓電腦依照規劃自動下載YT影片的程式碼,讓其可以下載MP3


程式碼:
檔案名稱: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!")

    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
   
fcl = OpenFiles('下載名單.txt','').FileContentList()
gfp = OpenFiles('','download').GetFolderPath()
TempType = OpenFiles('Mp3orMp4.txt','').FileContentList()
TempType.pop(0)
for i in fcl:
    temp=i.replace('\n','')
    for k in TempType:
        if k.upper() == 'MP3':
            YouTubeDownloader(temp,gfp).YTMp3Downloader()
        elif k.upper() =='MP4':
            YouTubeDownloader(temp,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")

檔案名稱:轉換副檔名為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

資料來源:

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

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