Last active
January 8, 2020 23:16
-
-
Save solarfl4re/0a3647788f8ec2f375f2da3db55fb0fe to your computer and use it in GitHub Desktop.
For Pythonista 3. Needs StaSH and youtube-dl (installed with pip). Save YouTube vides by long-pressing links and running this script with 'Run Pythonista 3 Script...'
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
# coding: utf-8 | |
from __future__ import unicode_literals | |
import appex | |
import console | |
from os import remove | |
import youtube_dl | |
def main(): | |
if not appex.is_running_extension(): | |
print('Running in Pythonista app, using test data...\n') | |
url = 'http://example.com' | |
else: | |
url = appex.get_url() | |
if not url: | |
url = appex.get_attachments() | |
if url: | |
ydl_opts = { | |
'progress_hooks': [postdownload] | |
} | |
with youtube_dl.YoutubeDL(ydl_opts) as ydl: | |
ydl.download(url) | |
def postdownload(d): | |
if d['status'] == 'finished': | |
console.quicklook(d['filename']) | |
remove(d['filename']) | |
appex.finish() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment