├── img ├── ff.PNG ├── demo.PNG ├── demo2.png ├── download.PNG ├── encoded.png ├── encoding.png ├── ffmpeg.png ├── finish.PNG ├── createVenv.PNG ├── different.PNG ├── download2.PNG ├── chromeDriver.PNG ├── encodeAction.PNG └── requirements.PNG ├── RUN.bat ├── .gitignore ├── config.py ├── requirements.txt ├── delete.py ├── movies.py ├── main.py ├── merge.py ├── INIT.bat ├── cover.py ├── args.py ├── encode.py ├── getchromedriver.py ├── crawler.py ├── README.md ├── download.py └── LICENSE /img/ff.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/ff.PNG -------------------------------------------------------------------------------- /RUN.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | call "jable\Scripts\activate" 3 | python main.py 4 | pause 5 | -------------------------------------------------------------------------------- /img/demo.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/demo.PNG -------------------------------------------------------------------------------- /img/demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/demo2.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.mp4 3 | *.DS_store 4 | *.jpg 5 | *.m3u8 6 | chromedriver* 7 | /jable -------------------------------------------------------------------------------- /img/download.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/download.PNG -------------------------------------------------------------------------------- /img/encoded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/encoded.png -------------------------------------------------------------------------------- /img/encoding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/encoding.png -------------------------------------------------------------------------------- /img/ffmpeg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/ffmpeg.png -------------------------------------------------------------------------------- /img/finish.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/finish.PNG -------------------------------------------------------------------------------- /img/createVenv.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/createVenv.PNG -------------------------------------------------------------------------------- /img/different.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/different.PNG -------------------------------------------------------------------------------- /img/download2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/download2.PNG -------------------------------------------------------------------------------- /img/chromeDriver.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/chromeDriver.PNG -------------------------------------------------------------------------------- /img/encodeAction.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/encodeAction.PNG -------------------------------------------------------------------------------- /img/requirements.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hcjohn463/JableTVDownload/HEAD/img/requirements.PNG -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | headers = { 2 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36', 3 | } 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.31.0 2 | beautifulsoup4==4.12.3 3 | m3u8==0.8.0 4 | pycryptodome==3.17 5 | selenium 6 | soupsieve==2.5 7 | urllib3==2.2.1 8 | certifi==2024.2.2 9 | charset-normalizer==3.3.2 10 | idna==3.6 11 | -------------------------------------------------------------------------------- /delete.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def deleteMp4(folderPath): 4 | files = os.listdir(folderPath) 5 | originFile = folderPath.split(os.path.sep)[-1] + '.mp4' 6 | for file in files: 7 | if file != originFile: 8 | os.remove(os.path.join(folderPath, file)) 9 | 10 | 11 | def deleteM3u8(folderPath): 12 | files = os.listdir(folderPath) 13 | for file in files: 14 | if file.endswith('.m3u8'): 15 | os.remove(os.path.join(folderPath, file)) 16 | -------------------------------------------------------------------------------- /movies.py: -------------------------------------------------------------------------------- 1 | # In[0]: 2 | import requests 3 | from config import headers 4 | from bs4 import BeautifulSoup 5 | from selenium import webdriver 6 | 7 | 8 | def movieLinks(url): 9 | links = [] 10 | dr = webdriver.Chrome() 11 | dr.get(url) 12 | bs = BeautifulSoup(dr.page_source,"html.parser") 13 | a_tags = bs.select('div.img-box>a') 14 | print(a_tags) 15 | for a_tag in a_tags: 16 | links.append(a_tag['href']) 17 | print('获取到 {0} 個影片'.format(len(links))) 18 | print(links) 19 | return links 20 | 21 | # %% 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # author: hcjohn463 2 | #!/usr/bin/env python 3 | # coding: utf-8 4 | from args import * 5 | from download import download 6 | from movies import movieLinks 7 | # In[2]: 8 | 9 | parser = get_parser() 10 | args = parser.parse_args() 11 | 12 | if(len(args.url) != 0): 13 | url = args.url 14 | download(url) 15 | elif(args.random == True): 16 | url = av_recommand() 17 | download(url) 18 | elif(args.all_urls != ""): 19 | all_urls = args.all_urls 20 | urls = movieLinks(all_urls) 21 | for url in urls: 22 | download(url) 23 | else: 24 | # 使用者輸入Jable網址 25 | url = input('輸入jable網址:') 26 | download(url) 27 | -------------------------------------------------------------------------------- /merge.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | def mergeMp4(folderPath, tsList): 4 | # 開始時間 5 | start_time = time.time() 6 | print('開始合成影片..') 7 | 8 | for i in range(len(tsList)): 9 | file = tsList[i].split('/')[-1][0:-3] + '.mp4' 10 | full_path = os.path.join(folderPath, file) 11 | video_name = folderPath.split(os.path.sep)[-1] 12 | if os.path.exists(full_path): 13 | with open(full_path, 'rb') as f1: 14 | with open(os.path.join(folderPath, video_name + '.mp4'), 'ab') as f2: 15 | f2.write(f1.read()) 16 | else: 17 | print(file + " 失敗 ") 18 | end_time = time.time() 19 | print('花費 {0:.2f} 秒合成影片'.format(end_time - start_time)) 20 | print('下載完成!') 21 | -------------------------------------------------------------------------------- /INIT.bat: -------------------------------------------------------------------------------- 1 | chcp 65001 2 | 3 | @echo off 4 | SET VENV_PATH=.\jable 5 | 6 | REM 檢查虛擬環境是否存在 7 | IF EXIST "%VENV_PATH%\Scripts\activate.bat" ( 8 | ECHO 虛擬環境已經存在。 9 | ) ELSE ( 10 | ECHO 虛擬環境不存在,正在創建... 11 | python -m venv jable 12 | ECHO 虛擬環境創建完成。 13 | ) 14 | 15 | REM 激活虛擬環境 16 | CALL "%VENV_PATH%\Scripts\activate" 17 | 18 | pip3 install -r requirements.txt 19 | 20 | REM 檢查chromedriver.exe是否存在 21 | IF EXIST "chromedriver.exe" ( 22 | ECHO chromedriver已存在。 23 | ) ELSE ( 24 | ECHO chromedriver不存在,正在下載... 25 | python getchromedriver.py 26 | ) 27 | 28 | REM 檢查FFmpeg是否安裝 29 | where ffmpeg >nul 2>&1 30 | IF %ERRORLEVEL% EQU 0 ( 31 | ECHO FFmpeg已安裝,你可以執行RUN.bat了 32 | ) ELSE ( 33 | ECHO FFmpeg未安裝,請先安裝FFmpeg 34 | ) 35 | 36 | 37 | pause 38 | -------------------------------------------------------------------------------- /cover.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import os 3 | from bs4 import BeautifulSoup 4 | 5 | 6 | def getCover(html_file, folder_path): 7 | # get cover 8 | soup = BeautifulSoup(html_file, "html.parser") 9 | cover_name = f"{os.path.basename(folder_path)}.jpg" 10 | cover_path = os.path.join(folder_path, cover_name) 11 | for meta in soup.find_all("meta"): 12 | meta_content = meta.get("content") 13 | if not meta_content: 14 | continue 15 | if "preview.jpg" not in meta_content: 16 | continue 17 | try: 18 | r = requests.get(meta_content) 19 | with open(cover_path, "wb") as cover_fh: 20 | r.raw.decode_content = True 21 | for chunk in r.iter_content(chunk_size=1024): 22 | if chunk: 23 | cover_fh.write(chunk) 24 | except Exception as e: 25 | print(f"unable to download cover: {e}") 26 | 27 | print(f"cover downloaded as {cover_name}") 28 | -------------------------------------------------------------------------------- /args.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from bs4 import BeautifulSoup 3 | import random 4 | from urllib.request import Request, urlopen 5 | from config import headers 6 | import re 7 | 8 | 9 | def get_parser(): 10 | parser = argparse.ArgumentParser(description="Jable TV Downloader") 11 | parser.add_argument("--random", type=bool, default=False, 12 | help="Enter True for download random ") 13 | parser.add_argument("--url", type=str, default="", 14 | help="Jable TV URL to download") 15 | parser.add_argument("--all-urls", type=str, default="", 16 | help="Jable URL contains multiple avs") 17 | 18 | return parser 19 | 20 | 21 | def av_recommand(): 22 | headers = {'User-Agent': 'Mozilla/5.0'} 23 | url = 'https://jable.tv/' 24 | request = Request(url, headers=headers) 25 | web_content = urlopen(request).read() 26 | # 得到繞過轉址後的 html 27 | soup = BeautifulSoup(web_content, 'html.parser') 28 | h6_tags = soup.find_all('h6', class_='title') 29 | av_list = re.findall(r'https[^"]+', str(h6_tags)) 30 | return random.choice(av_list) 31 | 32 | 33 | # print(av_recommand()) 34 | -------------------------------------------------------------------------------- /encode.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | def ffmpegEncode(folder_path, file_name, action): 4 | if action == 0: #不轉檔 5 | return 6 | elif action == 1: #快速無損轉檔 7 | os.chdir(folder_path) 8 | try: 9 | subprocess.call(['ffmpeg', '-i', f'{file_name}.mp4', 10 | '-c', 'copy', '-bsf:a', 'aac_adtstoasc', '-movflags', '+faststart', 11 | f'f_{file_name}.mp4']) 12 | os.remove(os.path.join(folder_path, f'{file_name}.mp4')) 13 | os.rename(os.path.join(folder_path, f'f_{file_name}.mp4'), os.path.join(folder_path, f'{file_name}.mp4')) 14 | print("轉檔成功!") 15 | 16 | except: 17 | print("轉檔失敗!") 18 | elif action == 2: #GPU轉檔 19 | os.chdir(folder_path) 20 | try: 21 | subprocess.call(['ffmpeg', '-i', f'{file_name}.mp4','-c:v', 'h264_nvenc', '-b:v', '10000K', 22 | '-threads', '5', f'f_{file_name}.mp4']) 23 | os.remove(os.path.join(folder_path, f'{file_name}.mp4')) 24 | os.rename(os.path.join(folder_path, f'f_{file_name}.mp4'), os.path.join(folder_path, f'{file_name}.mp4')) 25 | print("轉檔成功!") 26 | 27 | except: 28 | print("轉檔失敗!") 29 | elif action == 3: #CPU轉檔 30 | os.chdir(folder_path) 31 | try: 32 | subprocess.call(['ffmpeg', '-i', f'{file_name}.mp4', '-c:v', 'libx264', '-b:v', '3M', 33 | '-threads', '5', '-preset', 'superfast', f'f_{file_name}.mp4']) 34 | os.remove(os.path.join(folder_path, f'{file_name}.mp4')) 35 | os.rename(os.path.join(folder_path, f'f_{file_name}.mp4'), os.path.join(folder_path, f'{file_name}.mp4')) 36 | print("轉檔成功!") 37 | 38 | except: 39 | print("轉檔失敗!") 40 | else: 41 | return 42 | -------------------------------------------------------------------------------- /getchromedriver.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | import zipfile 4 | import shutil 5 | import os 6 | 7 | def get_chromedriver_version(): 8 | url = 'https://googlechromelabs.github.io/chrome-for-testing/' 9 | response = requests.get(url) 10 | 11 | if response.status_code == 200: 12 | soup = BeautifulSoup(response.text, 'html.parser') 13 | formatted_html = soup.prettify() 14 | 15 | # print(formatted_html) 16 | 17 | tr_tags = soup.find_all('tr', class_='status-ok') 18 | for tr in tr_tags: 19 | if tr.find('a', string="Stable"): 20 | version_code = tr.find('code').text.strip() 21 | print(version_code) 22 | break 23 | return version_code 24 | else: 25 | print("Fail, Code:", response.status_code) 26 | 27 | def download_chromedriver(download_link): 28 | url = download_link 29 | response = requests.get(url) 30 | 31 | if response.status_code == 200: 32 | with open('chromedriver.zip', 'wb') as file: 33 | file.write(response.content) 34 | print("success!") 35 | else: 36 | print("Fail, Code:", response.status_code) 37 | 38 | def unzip_chromedriver(): 39 | with zipfile.ZipFile('chromedriver.zip', 'r') as zip_ref: 40 | zip_ref.extractall('./') 41 | 42 | chromedriver_version = get_chromedriver_version() 43 | download_link = f"https://storage.googleapis.com/chrome-for-testing-public/{chromedriver_version}/win64/chromedriver-win64.zip" 44 | download_chromedriver(download_link) 45 | unzip_chromedriver() 46 | 47 | # move chromedriver to the root directory 48 | file_source = "chromedriver-win64/chromedriver.exe" 49 | file_destination = "./" 50 | shutil.move(file_source, file_destination) 51 | 52 | # clean up 53 | shutil.rmtree('chromedriver-win64') 54 | os.remove("chromedriver.zip") -------------------------------------------------------------------------------- /crawler.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | from config import headers 4 | from functools import partial 5 | import concurrent.futures 6 | import time 7 | import copy 8 | 9 | 10 | def scrape(ci, folderPath, downloadList, urls): 11 | os.path.split(urls) 12 | fileName = urls.split('/')[-1][0:-3] 13 | saveName = os.path.join(folderPath, fileName + ".mp4") 14 | if os.path.exists(saveName): 15 | # 跳過已下載 16 | print('當前目標: {0} 已下載, 故跳過...剩餘 {1} 個'.format( 17 | urls.split('/')[-1], len(downloadList))) 18 | downloadList.remove(urls) 19 | else: 20 | response = requests.get(urls, headers=headers, timeout=10) 21 | if response.status_code == 200: 22 | content_ts = response.content 23 | if ci: 24 | content_ts = ci.decrypt(content_ts) # 解碼 25 | with open(saveName, 'ab') as f: 26 | f.write(content_ts) 27 | # 輸出進度 28 | downloadList.remove(urls) 29 | print('\r當前下載: {0} , 剩餘 {1} 個, status code: {2}'.format( 30 | urls.split('/')[-1], len(downloadList), response.status_code), end='', flush=True) 31 | 32 | 33 | def prepareCrawl(ci, folderPath, tsList): 34 | downloadList = copy.deepcopy(tsList) 35 | # 開始時間 36 | start_time = time.time() 37 | print('開始下載 ' + str(len(downloadList)) + ' 個檔案..', end='') 38 | print('預計等待時間: {0:.2f} 分鐘 視影片長度與網路速度而定)'.format(len(downloadList) / 150)) 39 | 40 | # 開始爬取 41 | startCrawl(ci, folderPath, downloadList) 42 | 43 | end_time = time.time() 44 | print('\n花費 {0:.2f} 分鐘 爬取完成 !'.format((end_time - start_time) / 60)) 45 | 46 | 47 | def startCrawl(ci, folderPath, downloadList): 48 | # 同時建立及啟用 20 個執行緒 49 | round = 0 50 | while(downloadList != []): 51 | with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: 52 | executor.map(partial(scrape, ci, folderPath, 53 | downloadList), downloadList) 54 | round += 1 55 | print(f', round {round}') 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JableTVDownload 2 | 3 | ## 下載JableTV好幫手 4 | 5 | 每次看正要爽的時候就給我卡住轉圈圈 6 | 7 | 直接下載到電腦看沒煩惱 8 | 9 | ## 懶人包 for Windows 使用者 10 | 11 | 1. 請自行安裝 ffmpeg,裝完之後執行 INIT.bat 將會自動建置其餘環境。 12 | 2. 若收到可以執行 RUN.bat 之訊息,執行 RUN.bat 即可使用此神器。 13 | 14 | ### 1.搭建並啟用虛擬環境(Activate Virtual Environment) 15 | 16 | ``` 17 | python -m venv jable 18 | jable/Scripts/activate 19 | ``` 20 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/createVenv.PNG) 21 | 22 | ### 2.下載所需套件、檔案(Download Requirement Files) 23 | a. 24 | `pip install -r requirements.txt` 25 | 26 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/requirements.PNG) 27 | 28 | b. 29 | 下載ChromeDriver至資料夾 [ChromeDriver] 30 | 31 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/chromeDriver.PNG) 32 | 33 | c. 34 | 安裝 [FFmpeg] 用於轉檔,此畫面代表FFmpeg安裝成功 (不安裝也可以看,不過影片會有拖拉卡幀的狀況) 35 | 36 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/ffmpeg.png) 37 | 38 | ### 3.執行程式(Execute) 39 | `python main.py` 40 | 41 | ### 4.輸入影片網址(Input Video Url) 42 | `https://jable.tv/videos/ipx-486/` 43 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/download2.PNG) 44 | 45 | ### 5.等待下載(Wait Download) 46 | 要轉檔輸入`y`,不要輸入`n` 47 | 要用GPU加速(Nvidia)轉檔輸入`y`,用CPU輸入`n` 48 | 49 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/download.PNG) 50 | 51 | ### 6.等待轉檔(Wait Encode) 52 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/encoding.png) 53 | 54 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/encoded.png) 55 | 56 | ### 7.完成(Finish) 57 | ![image](https://github.com/hcjohn463/JableDownload/blob/main/img/demo2.png) 58 | 59 | ### 如果覺得好用 再麻煩給個星星好評 謝謝!! 60 | --- 61 | 62 | [ChromeDriver]: 63 | [FFmpeg]: 64 | 65 | ### Argument parser 66 | `$python main.py -h` 67 | 68 | ![](https://i.imgur.com/qgyS5sf.png) 69 | 70 | `$python main.py --random True` 71 | 72 | 可以直接下載隨機熱門影片 73 | 74 | ![](https://i.imgur.com/dSsdB7Y.png) 75 | 76 | 可以直接在cmd line指定url。 77 | 78 | ![](https://i.imgur.com/DKFrD7T.png) 79 | 80 | ### 更新日誌(Update log) 81 | 🦕 2023/4/19 新增ffmpeg自動轉檔 v1.11 82 | 🏹 2023/4/19 兼容Ubuntu Server v1.10 83 | 🦅 2023/4/15 輸入演員鏈接,下載所有該演員相關的影片 v1.9 84 | 🚗 2022/1/25 下載結束後抓封面 v1.8 85 | 🐶 2021/6/4 更改m3u8得到方法(正則表達式) v1.7 86 | 🌏 2021/5/28 更新代碼讓Unix系統(Mac,linux等)能使用 v1.6 87 | 🍎 2021/5/27 更新爬蟲網頁方法 v1.5 88 | 🌳 2021/5/20 修改編碼問題 v1.4 89 | 🌈 2021/5/6 增加下載進度提示、修改Crypto問題 v1.3 90 | ⭐ 2021/5/5 更新穩定版本 v1.2 91 | -------------------------------------------------------------------------------- /download.py: -------------------------------------------------------------------------------- 1 | 2 | import requests 3 | import os 4 | import re 5 | import urllib.request 6 | import m3u8 7 | from Crypto.Cipher import AES 8 | from config import headers 9 | from crawler import prepareCrawl 10 | from merge import mergeMp4 11 | from delete import deleteM3u8, deleteMp4 12 | from cover import getCover 13 | from encode import ffmpegEncode 14 | from args import * 15 | from selenium import webdriver 16 | from selenium.webdriver.chrome.options import Options 17 | 18 | def download(url): 19 | encode = 0 #不轉檔 20 | action = input('要轉檔嗎?[y/n]') 21 | if action.lower() == 'y': 22 | action = input('選擇轉檔方案[1:僅轉換格式(默認,推薦) 2:NVIDIA GPU 轉檔 3:CPU 轉檔]') 23 | if action == '2': 24 | encode = 2 #GPU轉檔 25 | elif action == '3': 26 | encode = 3 #CPU轉檔 27 | else: 28 | encode = 1 #快速無損轉檔 29 | 30 | print('正在下載影片: ' + url) 31 | # 建立番號資料夾 32 | urlSplit = url.split('/') 33 | dirName = urlSplit[-2] 34 | if os.path.exists(f'{dirName}/{dirName}.mp4'): 35 | print('番號資料夾已存在, 跳過...') 36 | return 37 | if not os.path.exists(dirName): 38 | os.makedirs(dirName) 39 | folderPath = os.path.join(os.getcwd(), dirName) 40 | 41 | #配置Selenium參數 42 | options = Options() 43 | options.add_argument('--no-sandbox') 44 | options.add_argument('--disable-dev-shm-usage') 45 | options.add_argument('--disable-extensions') 46 | options.add_argument('--headless') 47 | options.add_argument("user-agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36") 48 | dr = webdriver.Chrome(options=options) 49 | dr.get(url) 50 | result = re.search("https://.+m3u8", dr.page_source) 51 | print(f'result: {result}') 52 | m3u8url = result[0] 53 | print(f'm3u8url: {m3u8url}') 54 | 55 | # 得到 m3u8 網址 56 | m3u8urlList = m3u8url.split('/') 57 | m3u8urlList.pop(-1) 58 | downloadurl = '/'.join(m3u8urlList) 59 | 60 | # 儲存 m3u8 file 至資料夾 61 | m3u8file = os.path.join(folderPath, dirName + '.m3u8') 62 | urllib.request.urlretrieve(m3u8url, m3u8file) 63 | 64 | # 得到 m3u8 file裡的 URI和 IV 65 | m3u8obj = m3u8.load(m3u8file) 66 | m3u8uri = '' 67 | m3u8iv = '' 68 | 69 | for key in m3u8obj.keys: 70 | if key: 71 | m3u8uri = key.uri 72 | m3u8iv = key.iv 73 | 74 | # 儲存 ts網址 in tsList 75 | tsList = [] 76 | for seg in m3u8obj.segments: 77 | tsUrl = downloadurl + '/' + seg.uri 78 | tsList.append(tsUrl) 79 | 80 | # 有加密 81 | if m3u8uri: 82 | m3u8keyurl = downloadurl + '/' + m3u8uri # 得到 key 的網址 83 | # 得到 key的內容 84 | response = requests.get(m3u8keyurl, headers=headers, timeout=10) 85 | contentKey = response.content 86 | 87 | vt = m3u8iv.replace("0x", "")[:16].encode() # IV取前16位 88 | 89 | ci = AES.new(contentKey, AES.MODE_CBC, vt) # 建構解碼器 90 | else: 91 | ci = '' 92 | 93 | # 刪除m3u8 file 94 | deleteM3u8(folderPath) 95 | 96 | # 開始爬蟲並下載mp4片段至資料夾 97 | prepareCrawl(ci, folderPath, tsList) 98 | 99 | # 合成mp4 100 | mergeMp4(folderPath, tsList) 101 | 102 | # 刪除子mp4 103 | deleteMp4(folderPath) 104 | 105 | # 取得封面 106 | getCover(html_file=dr.page_source, folder_path=folderPath) 107 | 108 | # 轉檔 109 | ffmpegEncode(folderPath, dirName, encode) 110 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------