get paid

Get paid for the tasks you do online

2020年12月13日 星期日

利用 Python 下載 youtube

 最近會利用到 YouTube 上面的影片來做測試 

之前都用 web 的一些服務

但是後來發現 公司網路會阻檔這些網址

於是想到自己用 python 來 download

Python 有個很簡的 download model 叫 pytube 

直接用 pip install 就可以了

不過如果你是用舊版 3.8 前的 python , 必須要指定版本

因為 pip install 會安裝最新版的 pytube

但最新版只 support 3.8 

另外 還要用到 ssl 

因為有些網址 或 MAC 需要用到 SSL , 不然會有 error 發生

程式碼很簡單 如下

之後有空再寫成 UI 介面吧

import pytube

import ssl
ssl._create_default_https_context = ssl._create_stdlib_context
url=input("Input download youtube URL: ")
download = input("input the dir to save the file: ")
yt =pytube.YouTube(url)
# yt.download('/Users/chiusam/Downloads')
# video = youtube.streams.first()
video = yt.streams.first()
video.download('/Users/chiusam/Downloads')

ChartGPT 學 python 很強喔

 ChartGPT 最近很紅 ,  前一陣子有一些小 module  本來想 google  一下 語法 但發現用 chartGPT 直接請他給 sample code 反而較快 所以只要你有基本 知識 ChartGPT 可以加速你的開發 好用喔