PrepareDownload.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:alfred-workflows 作者: mttjhn 项目源码 文件源码
def main(wf):
    log.debug('Started!')
    # Get query from Alfred
    if len(wf.args):
        query = wf.args[0]
    else:
        query = None

    log.debug(query)
    # If the query is blank, grab the contents of the clipboard
    if query == None:
        query = getClipboard()

    log.debug(query)

    if query != None:
        # Start by trimming whitespace
        query = query.strip()
        # Let's process the URL now!
        if URL_CHECK in query:
            # Looks like we're ok to go ahead on this one.
            # TODO: Could do full URL parsing here, but this is probably good enough
            # We're already dealing with undocumented Droplr API anyways...
            output = getDroplrInfo(query)
            if len(output) > 0:
                # Looks like we found something!
                # Let's prepare the link...
                processItem = wf.add_item(title=u'Download {0} from Droplr'.format(output[1]),
                    subtitle=u'File name: {0}'.format(output[0]),
                    arg=query, 
                    icon=u'{0}.png'.format(output[1]),
                    valid=True)
            else:
                # Didn't find data, but we could still try the link!..
                processItem = wf.add_item(title=u'Download from Droplr',
                    subtitle=u'{0}'.format(query),
                    arg=query, 
                    icon=u'image.png',
                    valid=True)
            # Set the variable we're filtering for
            processItem.setvar(u'download', '1')
        else:
            invalidError = wf.add_item(title=u'Valid URL not found in clipboard!',
                subtitle=u'Please try again with a valid Droplr URL.',
                icon=ICON_ERROR,
                valid=False)

        # Send the results to Alfred as XML
        wf.send_feedback()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号