Last active
February 12, 2019 10:06
-
-
Save bahacan19/eff0959c9f8f1528c167df134f1f6de7 to your computer and use it in GitHub Desktop.
chuck puller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#originally----->>>>> https://code.luasoftware.com/tutorials/ffmpeg/how-to-download-ts-stream-video-as-mp4/ | |
import os | |
import grequests | |
# name of the video | |
name = 'DipBirinciBolum' | |
# .ts URL of the video, replace segment number with {0} | |
source_url = 'https://vcdn.puhutv.com/37f6afc657221d2f237772b8c03117ab39a96640bc4a70dea43ec7f94e77f85a/hls/2160p/chunklist-{0}.ts?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKiIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6IDE1MjU3OTc3Nzl9fX1dfQ==&Expires=1525797779&Signature=Ic91Cc~kjviIm~Uo5TMiRJgfe~yMRe5Qm0Q7RXaAdU3cGhhf~KOQvP6ZCeMeFH3GyPtpuxDQkUS2IGxMrdsBRPRZaiMfJrFPsmdigsUYquA-or8HTSsgAz2vrckiNX7rJGcIFXU1ylr7mbm~xkBcGTYMDrWdUS8j~S9edIOcR9Cuifv1sTnKLmvh3wdUnBHVqpPQT2fE1wDerHvrNTK~Moys78q65SYvCVT9N6mbDsjkVOGlSa75LiaP5BH0Xx2GYpYjYHvKzINo17Pt52h3iaTyOiSgmP5hL0Qbyqb8Q8wmCzIiuKADK-H6JsNAquBQZrm5Zrms9FjQ3KSa9hgonA__&Key-Pair-Id=APKAIZEE37VAVFSDJO5Q' | |
if not os.path.exists(name): | |
os.makedirs(name) | |
keys = [] | |
urls = [] | |
for x in range(1,2000): | |
filename = '{0}/{1:05d}.ts'.format(name, x) | |
if os.path.isfile(filename): | |
#print 'skip', x | |
continue | |
file_actualname = "{0:0>5}".format(x) #https://stackoverflow.com/a/17118161/1380499 | |
urls.append(source_url.format(file_actualname)) | |
keys.append(x) | |
# allow 6 simultenous download | |
if len(urls) == 6: | |
rs = (grequests.get(u) for u in urls) | |
results = grequests.map(rs) | |
for key, _result in enumerate(results): | |
filename = '{0}/{1:05d}.ts'.format(name, keys[key]) | |
#print urls[key], _result.status_code | |
if _result.status_code == 200: | |
with open(filename, 'wb') as f: | |
f.write(_result.content) | |
else: | |
# if error assume no more segment, or you can run this script again to make sure it's a permanent error | |
exit() | |
urls = [] | |
keys = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in script directory
cat DipBirinciBolum/*.ts > DipBirinciBolum.ts
then:
ffmpeg -i DipBirinciBolum.ts -bsf:a aac_adtstoasc -acodec copy -vcodec copy DipBirinciBolum.mp4