├── .gitignore ├── README.md ├── getM3u8.py ├── m3u8Downloader.py └── videos ├── m3u8 └── downloaded_m3u8 ├── merged_ts └── tmp └── downloaded_ts /.gitignore: -------------------------------------------------------------------------------- 1 | *.m3u8 2 | *.ts -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | m3u8Downloader 2 | === 3 | > *Using python 2.7.13 with requests and bs4* 4 | ## Usage 5 | 6 | ### m3u8Downloader.py 7 | Open `cmd.exe` for `Windows` or `Terminal` for `Linux`. 8 | Download video from a m3u8 file via: 9 | ``` 10 | $ python m3u8Downloader.py m3u8_path video_name 11 | ``` 12 | Lots of ts files will be downloaded into `./video/tmp` folder named `video_name_X.ts` *(X is index)*. 13 | Once all ts files are downloaded, they will be merged to a file `video_name` into `./video` folder. 14 | 15 | **※ Don't forget** filename extension: 16 | `m3u8_path` is like `your_path/wait_for_download.m3u8` 17 | `video_name` is like `cannot_wait_to_watch.ts` 18 | 19 | + After merged, fragments will be deleted. 20 | + Duplicate video names **will not** be overwritten. 21 | + If you have downloaded some parts of a video, you can just use same video name to download remaining parts. 22 | 23 | ### getM3u8.py 24 | > No use in most situations. 25 | 26 | Open `cmd.exe` for `Windows` or `Terminal` for `Linux`. 27 | Download m3u8 file from an url. 28 | Better surround urls with **""** 29 | ``` 30 | $ python getM3u8.py "url" XXX.m3u8 31 | ``` 32 | m3u8 file will be downloaded into `./video/m3u8` folder. 33 | 34 | ## License 35 | MIT -------------------------------------------------------------------------------- /getM3u8.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import requests 3 | import sys 4 | 5 | m3u8Name = sys.argv[2] 6 | url = sys.argv[1] 7 | 8 | res = requests.get(url) 9 | 10 | soup = BeautifulSoup(res.text,"html.parser") 11 | m3u8Url = str(soup.source['src']) 12 | 13 | res = requests.get(m3u8Url,stream=True) 14 | if res.status_code == 200: 15 | with open('./videos/m3u8/'+m3u8Name,'wb') as f: 16 | for chunk in res: 17 | f.write(chunk) 18 | print m3u8Name+' downloaded' 19 | -------------------------------------------------------------------------------- /m3u8Downloader.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import requests 3 | import shutil 4 | import os 5 | 6 | m3u8 = str(sys.argv[1]) 7 | videoName = str(sys.argv[2]) 8 | 9 | with open(m3u8, 'r') as f: 10 | tslist = [line.rstrip() for line in f if line.rstrip().endswith('.ts')] 11 | if len(tslist) > 0: 12 | print 'Total '+ str(len(tslist)) +' files' 13 | else: 14 | print 'No ts file found.' 15 | exit() 16 | 17 | index = 1 18 | tsNames = [] 19 | for tsUrl in tslist: 20 | videoNameTmp = videoName[0:-3]+'_'+str(index)+videoName[-3:] 21 | if not os.path.isfile('./videos/tmp/'+videoNameTmp): 22 | res = requests.get(tsUrl, stream=True, headers={'Referer':'https://avgle.com'}) 23 | if res.status_code == 200: 24 | with open('./videos/tmp/'+videoNameTmp, 'wb') as f: 25 | for chunk in res: 26 | f.write(chunk) 27 | print videoNameTmp+' downloaded\r', 28 | else: 29 | print '\nConnection error' 30 | exit() 31 | tsNames.append(videoNameTmp) 32 | index += 1 33 | 34 | if index == len(tslist)+1: 35 | with open('./videos/'+videoName, 'wb') as f: 36 | for ts in tsNames: 37 | with open('./videos/tmp/'+ts, 'rb') as mergefile: 38 | shutil.copyfileobj(mergefile, f) 39 | os.remove('./videos/tmp/'+ts) 40 | print videoName+' merged.' 41 | else: 42 | print 'Merge failed, missing files.' 43 | -------------------------------------------------------------------------------- /videos/m3u8/downloaded_m3u8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShizukuIchi/avgle-downloader/69f9627730f978e20f189cd0af67a3a6b58681fa/videos/m3u8/downloaded_m3u8 -------------------------------------------------------------------------------- /videos/merged_ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShizukuIchi/avgle-downloader/69f9627730f978e20f189cd0af67a3a6b58681fa/videos/merged_ts -------------------------------------------------------------------------------- /videos/tmp/downloaded_ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShizukuIchi/avgle-downloader/69f9627730f978e20f189cd0af67a3a6b58681fa/videos/tmp/downloaded_ts --------------------------------------------------------------------------------