skill_download/skilldown.py

91 lines
2.4 KiB
Python
Raw Normal View History

2020-01-09 11:34:34 +00:00
#!/usr/bin/python3 -u
import os as os
import wget as wget
from urllib.request import urlopen
from urllib.error import HTTPError
2022-05-28 19:24:37 +01:00
#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")
2020-01-09 11:34:34 +00:00
i=0
while True:
v = i
i += 1
2022-05-28 19:24:37 +01:00
#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)
2020-01-09 11:34:34 +00:00
try:
2022-05-28 19:24:37 +01:00
urlopen(tmp_url)
wget.download(tmp_url, out="audio/segment_"+str(v)+".m4s")
2020-01-09 11:34:34 +00:00
print('\n next \n')
except HTTPError as e:
if e.code == 403:
2022-05-28 19:24:37 +01:00
wget.download(tmp_url, out="audio/segment_"+str(v)+".m4s")
2020-01-09 11:34:34 +00:00
continue
else:
print('\n end \n')
break
2022-05-28 19:24:37 +01:00
os.system("cat audio/*"+str(v)+".m4s >> audio.m4s")
2020-01-09 11:34:34 +00:00
2022-05-28 19:24:37 +01:00
os.system("ffmpeg -i video.m4s -acodec copy -vcodec copy video.mp4")
os.system("rm -r video")
2020-01-09 11:34:34 +00:00
2020-05-13 14:20:11 +01:00
2022-05-28 19:24:37 +01:00
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")