Skip to content

Instantly share code, notes, and snippets.

@cnovasj
Forked from akash-gajjar/tldv.py
Last active March 26, 2025 13:11
Show Gist options
  • Select an option

  • Save cnovasj/95f6c77c197a3a03ab1ce69e9ac3c1df to your computer and use it in GitHub Desktop.

Select an option

Save cnovasj/95f6c77c197a3a03ab1ce69e9ac3c1df to your computer and use it in GitHub Desktop.
Download videos from TLDV.io
from datetime import datetime
import requests
import json
import os
import subprocess
# Instalar ffmpeg y requests
# Definir la ruta base para la descarga y conversión de archivos
base_dir = os.path.dirname(os.path.abspath(__file__))
download_dir = os.path.join(base_dir, 'downloads')
# Crear el directorio de descargas si no existe
if not os.path.exists(download_dir):
os.makedirs(download_dir)
# Obtener la URL de la reunión y el token de autenticación
url = input("Please paste the URL of the meeting you want to download: ")
# Extraer el ID de la reunión y eliminar cualquier barra diagonal al final
try:
meeting_id = url.split("/meetings/")[1].strip('/')
print(f"Found meeting ID: {meeting_id}")
except IndexError:
print("Invalid URL format. Please ensure the URL is in the correct format.")
exit()
auth_token = input("Please paste the auth token: ")
headers = {
"Authorization": f"Bearer {auth_token}"
}
# Realizar la solicitud para obtener la información de la reunión
api_url = f"https://gw.tldv.io/v1/meetings/{meeting_id}/watch-page?noTranscript=true"
print(f"Making request to: {api_url}")
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
data = response.json()
print("Response JSON data:", json.dumps(data, indent=2)) # Imprime el contenido de la respuesta JSON para depuración
if 'video' in data and 'source' in data['video']:
video_url = data['video']['source']
print(f"Video URL: {video_url}")
# Definir las rutas para los archivos .mp4
mp4_file_path = os.path.join(download_dir, f"{meeting_id}.mp4")
# Convertir .m3u8 a .mp4 usando ffmpeg directamente desde el URL
command = [
"ffmpeg", "-protocol_whitelist", "file,http,https,tcp,tls,crypto",
"-i", video_url, "-c", "copy", mp4_file_path
]
result = subprocess.run(command, capture_output=True, text=True)
# Mostrar la salida de ffmpeg para depuración
print(result.stdout)
print(result.stderr)
# Verificar si el archivo MP4 se creó correctamente
if os.path.exists(mp4_file_path):
print(f"Video converted successfully as {mp4_file_path}")
else:
print("Failed to convert the video.")
else:
print("'video' key not found in the response JSON.")
else:
print(f"Failed to get the meeting information. Status code: {response.status_code}")
print(f"Response content: {response.content}")
@KD-MM2
Copy link

KD-MM2 commented Dec 6, 2024

It's better to check if Bearer is present in entered auth_token or not.
If people included Bearer in their auth_token input, there will be duplicated: "Bearer Bearer ......."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment