Jump to content

[Request] Google Image Search workflow


Recommended Posts

Hello! Just purchased the power pack today and I'm really enjoying it.

 

 

I'm writing to request a workflow where I can paste a google image search URL like the following:

 

https://www.google.com/search?q=alfred+app&client=safari&rls=en&source=lnms&tbm=isch&sa=X&ei=X85iVLGSLMOTyASkn4GICg&ved=0CAoQ_AUoAw&biw=1438&bih=764

 

and have it automatically shorten the URL to the minimum google image search URL like this:

 

https://www.google.com/search?q=alfred+app&tbm=isch

 

Ideally the workflow would replace the long url with the shortened URL in the clipboard after hitting enter in the standard alfred text entry box.

 

This is all so I can easily paste google image search URLs to other people in irc/skype/email/etc and have it look nice.

 

Thanks so much!

Link to comment

I'd recommend this workflow as an alternative, unless you need to include the Google Image search terms in the links you post: http://www.alfredforum.com/topic/935-workflowshorten-url-support-googl-bitly-tcn-jmp-isgd-vgd/?hl=bitly#entry9644

 

It's a general purpose URL shortener offering your choice of shortening services.  

 

And for the opposite direction: http://www.alfredforum.com/topic/4843-resolve-canonical-urls-from-shortened-urls/

Edited by dfay
Link to comment

Seeing as nobody's answered yet, here's a Python function that will shorten your Google Images URL as required:

from urlparse import urlparse, parse_qs
from urllib import urlencode

def shorten_url(url):
    # Parse URL into component parts
    parsed = urlparse(url)
    # Parse the query string (?a=b&...)
    all_params = parse_qs(parsed.query)
    # Extract just the wanted parameters
    params = {}
    for k in ('q', 'tbm'):
        params[k] = all_params[k][0]
    # Rebuild a shorter query string
    query = urlencode(params)
    # Re-assemble the URL from component parts and new query string
    short_url = '{}://{}{}?{}'.format(parsed.scheme, parsed.netloc, parsed.path, query)
    return short_url
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...