# get-youtube.py # Wrapper around youtube-dl for Android # Grabs URL from clipboard if it's a YouTube one. Otherwises prompts for URL # See https://conoroneill.net/downloading-youtube-videos-for-offline-viewing-on-android/ for instructions # Copyright Conor O'Neill 2018. Apache License 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt from __future__ import unicode_literals from androidhelper import Android droid = Android() import youtube_dl def input_default(prompt, default): return raw_input("%s [%s] " % (prompt, default)) or default # If clipboard URL is a YouTube one, grab it and automatically download if droid.getClipboard().result.startswith('https://youtu'): url = droid.getClipboard().result else: # Either the clipboard is empty or it has a non-YouTube URL. User must paste the required URL. url = raw_input("YouTube URL?: ") ydl_opts = { 'nocheckcertificate': True, 'outtmpl': '%(title)s.%(ext)s' } with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url])