Created
February 13, 2017 11:54
-
-
Save midchildan/6f246cc162ac27a4481f5d1a8c7d9560 to your computer and use it in GitHub Desktop.
A Pythonista extension for downloading videos using youtube-dl.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import appex | |
import console | |
import os | |
import sys | |
import tempfile | |
import youtube_dl | |
def main(): | |
url = None | |
if not appex.is_running_extension(): | |
print('Running in Pythonista app, using test data...\n') | |
url = 'https://www.youtube.com/watch?v=BaW_jenozKcj' | |
if url is None: | |
url = appex.get_url() | |
if url is None: | |
url = appex.get_text() | |
if url is None: | |
sys.exit('No input URL found.') | |
with tempfile.TemporaryDirectory() as d: | |
dlpath = os.path.join(d, '%(title)s.%(ext)s') | |
download(url, outtmpl=dlpath) | |
for f in os.listdir(d): | |
fpath = os.path.join(d, f) | |
console.open_in(fpath) | |
def download(url, **opts): | |
with youtube_dl.YoutubeDL(opts) as ydl: | |
ydl.download([url]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment