Editorial Workflows

Downloader

unlisted workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Download a file from a URL and offer to save it locally or save it and open it in another installed app. The file URL is received as input so the workflow can be launched from other apps through a URL scheme. The workflow is stopped immediately if no URL is passed to it.

Shared by: viticci

Comments: Comment Feed (RSS)

Help — 29 May 2014
How do you set up Launch Center Pro to open this?
anonymous — 29 May 2014
How is this triggered by LCP? What is the code?
Pihrra — 01 Jun 2014
Simply create an action wich opens the following url :
editorial://?command=Downloader&input=[clipboard]
anonymous — 01 Jun 2014
Thanks for the LCP trigger. But now the is an errormessage in ine 28 (Pythonista-script):
list index out of range. More people withe the same error?
Fred Mwangi — 08 Jul 2014
This should work just fine for version 1.1
Try downloading this sample file:

http://data-fi.com/uploads/sample.pdf

Which version of editorial are you using? Which file are you trying to download?

+ Add Comment

Workflow Preview
Set Variable ?
Variable Name
URL
Value
Input
If… ?
Run the block if
URL
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
No URL
…End If
Set Variable ?
Variable Name
name
Value
Set Variable ?
Variable Name
size
Value
Set Variable ?
Variable Name
readable_size
Value
Run Python Script ?
Source Code
import urllib2
import console
import os
import workflow
from math import log

# http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-pythonh
# http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size

unit_list = zip(['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'], [0, 0, 1, 2, 2, 2])

def sizeof_fmt(num):
    """Human friendly file size"""
    if num > 1:
        exponent = min(int(log(num, 1024)), len(unit_list) - 1)
        quotient = float(num) / 1024**exponent
        unit, num_decimals = unit_list[exponent]
        format_string = '{:.%sf} {}' % (num_decimals)
        return format_string.format(quotient, unit)
    if num == 0:
        return '0 bytes'
    if num == 1:
        return '1 byte'

url = workflow.get_variable('URL')
u = urllib2.urlopen(url)
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
readable_size = sizeof_fmt(file_size)

file_name = urllib2.unquote(url.split('/')[-1])

workflow.set_variable('name', file_name)
workflow.set_variable('size', str(file_size))
workflow.set_variable('readable_size', str(readable_size))
Custom UI ?
User Interface
Presentation Style
  • Sheet
  • Full-Screen
  • Popover
Output
Use Editor Theme
ON