Adaptar script per videos de ccma.cat

This commit is contained in:
Xaloc 2022-05-28 20:24:37 +02:00
parent 074e91f500
commit 106ae9e698

View File

@ -5,67 +5,86 @@ import wget as wget
from urllib.request import urlopen from urllib.request import urlopen
from urllib.error import HTTPError from urllib.error import HTTPError
sep = input("Are audio and video in the Same or Different files? [S|D]") #posar url fins on acaben els numeros raros (parar abans de video o audio)
sep = sep.lower()
if not(sep=='s' or sep=='d'): url = "https://adaptive-int.ccma.cat/4/3/6161234/1653745544791"
raise ValueError("The answer should be S or D")
#video o video+so si junt 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 i=0
while True: while True:
v = i v = i
i += 1 i += 1
#url del video!!!!!!!!!!!!!! o video+so si junt #video
url= 'https://house-fastly-signed-us-east-1-prod.brightcovecdn.com/media/v1/hls/v4/clear/3695997568001/0df46668-c157-40a2-aeab-845c32d4eae3/d7cb636b-ca37-4bed-9248-0e494c526027/5x/segment'+str(v)+'.ts?fastly_token=NWUxNzNiNWFfMmM3NDk0NGU1NjE4NWM0MTE3MWQ4NjY1MGIwMGNhOGE2ZWI2NTc1NmQ2N2E1ODc3YjhjNzkxMjlhOWQyZTUzM18vL2hvdXNlLWZhc3RseS1zaWduZWQtdXMtZWFzdC0xLXByb2QuYnJpZ2h0Y292ZWNkbi5jb20vbWVkaWEvdjEvaGxzL3Y0L2NsZWFyLzM2OTU5OTc1NjgwMDEvMGRmNDY2NjgtYzE1Ny00MGEyLWFlYWItODQ1YzMyZDRlYWUzL2Q3Y2I2MzZiLWNhMzctNGJlZC05MjQ4LTBlNDk0YzUyNjAyNy8%3D' #url from media request without de number and .ts at the end tmp_url= url_video+'segment_'+str(v)+'.m4s' #url from media request without de number and .ts at the end
url=str(url) tmp_url=str(tmp_url)
print(url) print(tmp_url)
try: try:
urlopen(url) urlopen(tmp_url)
wget.download(url) wget.download(tmp_url, out="video/segment_"+str(v)+".m4s")
print('\n next \n') print('\n next \n')
except HTTPError as e: except HTTPError as e:
if e.code == 403: if e.code == 403:
wget.download(url) wget.download(tmp_url, out="video/segment_"+str(v)+".m4s")
continue continue
else: else:
print('\n end \n') print('\n end \n')
break break
os.system("cat *"+str(v)+".ts >> all.ts") os.system("cat video/*"+str(v)+".m4s >> video.m4s")
os.system("ffmpeg -i all.ts -acodec copy -vcodec copy video.mp4") #audio
if sep=='s': tmp_url= url_audio+'segment_'+str(v)+'.m4s' #url from media request without de number and .ts at the end
os.system("mv video.mp4 output.mp4") tmp_url=str(tmp_url)
os.system("rm *.ts") print(tmp_url)
if sep=='d':
#so
i=0
while True:
v = i
i += 1
#url del so!!!!!!!!!!!!!!
url= 'https://house-fastly-signed-us-east-1-prod.brightcovecdn.com/media/v1/hls/v4/clear/3695997568001/0df46668-c157-40a2-aeab-845c32d4eae3/600d909e-91a6-4f5c-b70b-2fe049618325/5x/segment'+str(v)+'.ts?fastly_token=NWUxNzNiNWFfNDI3ZDlkODIxM2U2YjBmY2E3MDlhYzhkOTcxYWI3YWRlOGUyOTgzYmQzZjJlZDYyYWRhNGIyMDJmZjZhNjMwYl8vL2hvdXNlLWZhc3RseS1zaWduZWQtdXMtZWFzdC0xLXByb2QuYnJpZ2h0Y292ZWNkbi5jb20vbWVkaWEvdjEvaGxzL3Y0L2NsZWFyLzM2OTU5OTc1NjgwMDEvMGRmNDY2NjgtYzE1Ny00MGEyLWFlYWItODQ1YzMyZDRlYWUzLzYwMGQ5MDllLTkxYTYtNGY1Yy1iNzBiLTJmZTA0OTYxODMyNS8%3D' #url from media request without de number and .ts at the end
url=str(url)
print(url)
try: try:
urlopen(url) urlopen(tmp_url)
wget.download(url) wget.download(tmp_url, out="audio/segment_"+str(v)+".m4s")
print('\n next \n') print('\n next \n')
except HTTPError as e: except HTTPError as e:
if e.code == 403: if e.code == 403:
wget.download(url) wget.download(tmp_url, out="audio/segment_"+str(v)+".m4s")
continue continue
else: else:
print('\n end \n') print('\n end \n')
break break
os.system("cat *"+str(v)+".ts >> all.ts") os.system("cat audio/*"+str(v)+".m4s >> audio.m4s")
os.system("ffmpeg -i all.ts -acodec copy -vcodec copy so.mp4") os.system("ffmpeg -i video.m4s -acodec copy -vcodec copy video.mp4")
os.system("rm *.ts") os.system("rm -r video")
#ajuntar
os.system("ffmpeg -i video.mp4 -i so.mp4 -c:v copy -c:a aac -strict experimental output.mp4") os.system("ffmpeg -i audio.m4s -acodec copy -vcodec copy audio.mp4")
os.system("rm video.mp4 so.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")