Skip to content

Instantly share code, notes, and snippets.

@solarfl4re
Last active January 8, 2020 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solarfl4re/0a3647788f8ec2f375f2da3db55fb0fe to your computer and use it in GitHub Desktop.
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...'
# 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