Skip to content

Instantly share code, notes, and snippets.

@marcosins
Last active January 15, 2022 06:07
Show Gist options
  • Select an option

  • Save marcosins/334df03cd73b53e6ab47adfd33e39598 to your computer and use it in GitHub Desktop.

Select an option

Save marcosins/334df03cd73b53e6ab47adfd33e39598 to your computer and use it in GitHub Desktop.
Descarga videos de la convencion desde mediastream y extrae el audio original
#!/usr/bin/env python3
#############################################################################
# Usa `curl` para descargar todos los videos de la Convención Coonstitucional
# desde mediastream y extrae el audio usando `ffmpeg``
# Todos los videos están en `mp4` (codec `h264`)
# El audio se guarda desde el video original como `m4a` (codec AAC)
#
# License: GPLv3
#############################################################################
import json
import subprocess
import os
VODS_JSON = 'vods.json' # https://github.com/marcosins/convencion-vods/blob/main/videos/vods.json
DOWNLOAD_FOLDER = '~/Videos/CC/'
DELETE_ORIGINAL_VIDEO = True
def downloadFile(url, fileName):
destination = DOWNLOAD_FOLDER + fileName
try:
print('Donwloading [', fileName, '] from -> ', url)
subprocess.call(
['curl', '--output', destination + '.mp4', '-L', url]
)
print('Extracting audio...')
subprocess.call(
['ffmpeg', '-i', destination + '.mp4',
'-vn', '-acodec', 'copy', destination + '.m4a']
)
if(DELETE_ORIGINAL_VIDEO):
os.remove(destination + '.mp4')
except Exception:
print(Exception)
print('DONE!')
return True
def main():
with open(VODS_JSON, 'r') as vods_json:
vods = json.loads(vods_json.read())
for vod in vods:
filename = vod['watch'].split('/')[-1] # slug en convencion.tv
downloadFile(vod['download'], filename)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment