Skip to content

Instantly share code, notes, and snippets.

@conoro
Last active February 3, 2018 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conoro/d63c9f326ee65647a717b0283f21683f to your computer and use it in GitHub Desktop.
Save conoro/d63c9f326ee65647a717b0283f21683f to your computer and use it in GitHub Desktop.
Get YouTube. Tiny wrapper on youtube-dl for running on Android and prompting for URL
# 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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment