Skip to content

Instantly share code, notes, and snippets.

@conoro conoro/get-youtube.py
Last active Feb 3, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.