Skip to content

Instantly share code, notes, and snippets.

@jae-jae jae-jae/Pipfile

Last active May 21, 2019
Embed
What would you like to do?
download m3u8
import PySimpleGUI as sg
import requests
import os
import uuid
from threading import Thread
def downloadM3u8(url, window):
window.FindElement('mark').Update('Downloading ...')
_getVideo(url, window)
window.FindElement('mark').Update('Done')
def _getVideo(url, window):
if url.endswith('/'):
url = url[:-1]
baseUrl = url.rsplit('/', 1)[0]
resp = requests.get(url)
lines = resp.text.split('\n')
if not lines or lines[0] != '#EXTM3U':
return
filename = '{}.mp4'.format(uuid.uuid1())
if os.path.exists(filename):
os.remove(filename)
count = len(lines)
base = 100 / count
with open(file=filename, mode='wb+') as fp:
for i in range(count):
window.FindElement('progbar').UpdateBar(base * (i + 1))
line = lines[i]
if line.endswith('.ts'):
seg = baseUrl + '/' + line
resp = requests.get(seg)
if resp.status_code == 200:
fp.write(resp.content)
layout = [
[sg.Text('Input m3u8 url here:')],
[sg.Multiline('', key='url', size=(80, 10))],
[sg.ProgressBar(100, size=(30, 20), key='progbar'), sg.Text('Downloading ...', key='mark')],
[sg.Submit(), sg.Cancel()],
]
window = sg.Window('Download m3u8').Layout(layout)
while True:
event, values = window.Read()
if event is None or event == 'Cancel':
break
url = values['url'].strip()
if url:
Thread(target=downloadM3u8, args=(url, window)).start()
else:
window.FindElement('mark').Update('No url found')
continue
window.Close()
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
pysimplegui = "*"
requests = "*"
uuid = "*"
[requires]
python_version = "3.7"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.