#!/usr/bin/python3 # Download einer Videodatei von YouTube # URL (Datentyp str) mit Referenz url speichern url = "http://www.youtube.com/watch?v=BaW_jenozKc" # Optionen zum Download des Videos # niedrigste Auflösung, um Speicherplatz zu sparen ydl_opts = {"format": "worst"} # Datentyp dict # Erzeugung einer Instanz ydl vom Datentyp YoutubeDL from youtube_dl import YoutubeDL ydl = YoutubeDL(ydl_opts) # Hinzufügung von allen verfügbaren Extraktoren ydl.add_default_info_extractors() # Download und Erzeugung eines Dictionary info with ydl: info = ydl.extract_info( url, download=True # False: Info, kein Download ) # Ausgabe des Namens der aktuellen Programmdatei print ("\nAusgeführt wird Datei "+__file__) # str # Ausgabe des Titels des Videos (nicht mit IDLE) # Der Titel kann aussergewöhnliche Zeichen enthaten. print("Titel: " + info["title"]) # Datentyp str # Ausgabe vom Namen des Uploaders und Upload-Datum d = info["upload_date"][6:8]+". "+\ info["upload_date"][4:6]+". "+info["upload_date"][0:4] print( "Upload von " + info["uploader"] + " ("+d+")" ) # + " (") +\ info["upload_date"] + ")") # Ausgabe der URL der Webseite des Videos print("URL: " + info['webpage_url']) # Datentyp str # Ausgabe der Bildgröße des Videos (Pixel) print("Bildhöhe = " + str(info["height"]),\ ", Bildbreite = " + str(info["width"])) # int, int # Ausgabe weiterer Information zum Video print("Länge = " + str(info["duration"]) + " s") # int print("Untertitel = " + str(info["subtitles"])) # dict