#!/usr/bin/python3 -u import os as os import wget as wget from urllib.request import urlopen from urllib.error import HTTPError #posar url fins on acaben els numeros raros (parar abans de video o audio) url = "https://adaptive-int.ccma.cat/4/3/6161234/1653745544791" url_video = url+"/video/1080p/" url_audio = url+"/audio/ca/" os.system("mkdir audio") os.system("mkdir video") #Baixar inits #Video init try: urlopen(str(url_video+"init.mp4")) wget.download(str(url_video+"init.mp4"), out="video/init.mp4") print('\n next \n') except HTTPError as e: if e.code == 403: wget.download(str(url_video+"init.mp4"), out="video/init.mp4") pass os.system("cat video/*.mp4 >> video.m4s") #Audio init try: urlopen(str(url_audio+"init.mp4")) wget.download(str(url_audio+"init.mp4"), out="audio/init.mp4") print('\n next \n') except HTTPError as e: if e.code == 403: wget.download(str(url_audio+"init.mp4"), out="audio/init.mp4") pass os.system("cat audio/*.mp4 >> audio.m4s") i=0 while True: v = i i += 1 #video tmp_url= url_video+'segment_'+str(v)+'.m4s' #url from media request without de number and .ts at the end tmp_url=str(tmp_url) print(tmp_url) try: urlopen(tmp_url) wget.download(tmp_url, out="video/segment_"+str(v)+".m4s") print('\n next \n') except HTTPError as e: if e.code == 403: wget.download(tmp_url, out="video/segment_"+str(v)+".m4s") continue else: print('\n end \n') break os.system("cat video/*"+str(v)+".m4s >> video.m4s") #audio tmp_url= url_audio+'segment_'+str(v)+'.m4s' #url from media request without de number and .ts at the end tmp_url=str(tmp_url) print(tmp_url) try: urlopen(tmp_url) wget.download(tmp_url, out="audio/segment_"+str(v)+".m4s") print('\n next \n') except HTTPError as e: if e.code == 403: wget.download(tmp_url, out="audio/segment_"+str(v)+".m4s") continue else: print('\n end \n') break os.system("cat audio/*"+str(v)+".m4s >> audio.m4s") os.system("ffmpeg -i video.m4s -acodec copy -vcodec copy video.mp4") os.system("rm -r video") os.system("ffmpeg -i audio.m4s -acodec copy -vcodec copy audio.mp4") os.system("rm -r audio") #ajuntar os.system("ffmpeg -i video.mp4 -i audio.mp4 -c:v copy -c:a aac -strict experimental output.mp4") os.system("rm video.mp4 audio.mp4") os.system("rm *.m4s")