Advertisement
Guest User

Fuckr

a guest
May 31st, 2015
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Fuckr: retrieve URL to full-size Flickr images
  3. # Ported from jwz's galdown script: http://www.jwz.org/hacks/galdown
  4. # by Rena Kunisaki, 2015 May 31
  5. # Copyright © 2015 Rena Kunisaki
  6. # Original code copyright © 2006-2015 Jamie Zawinski <jwz@jwz.org>
  7. #
  8. # Permission to use, copy, modify, distribute, and sell this software and its
  9. # documentation for any purpose is hereby granted without fee, provided that
  10. # the above copyright notice appear in all copies and that both that
  11. # copyright notice and this permission notice appear in supporting
  12. # documentation.  No representations are made about the suitability of this
  13. # software for any purpose.  It is provided "as is" without express or
  14. # implied warranty.
  15. import re
  16. import requests
  17. import sys
  18.  
  19. def search(str, pat, flags=None, group=1):
  20.     if flags is None:
  21.         flags = re.M | re.S | re.X
  22.     return re.search(pat, str, flags).group(group)
  23.  
  24.    
  25. def flickr_crack_secret(img):
  26.     #api_key = 'dc4728449ac9905195f4bd612e1c215a'
  27.     api_key = '4fc05fa65f1adedb76e0cb0655cc6836'
  28.     id = search(img, r'/\d+/(\d+)_[a-f\d]+', flags=re.M | re.S | re.I)
  29.     if id is None: raise ValueError("No image ID in this URL")
  30.    
  31.     url = 'https://api.flickr.com/services/rest' + \
  32.           '?method=flickr.photos.getInfo' + \
  33.           '&photo_id=' + id + \
  34.           '&api_key=' + api_key
  35.    
  36.     req = requests.get(url)
  37.     xml = req.text
  38.    
  39.     #if not '<photo ' in xml:
  40.     #   raise ValueError("No <photo> found in response")
  41.    
  42.     return "https://farm{farm}.staticflickr.com/{serv}/{id}_{secret}_o.{fmt}".\
  43.         format(
  44.             id     = search(xml, r'\b id="(.*?)"'),
  45.             farm   = search(xml, r'\b farm="(.*?)"'),
  46.             serv   = search(xml, r'\b server="(.*?)"'),
  47.             fmt    = search(xml, r'\b originalformat="(.*?)"'),
  48.             secret = search(xml, r'\b originalsecret="(.*?)"'),
  49.         )
  50.    
  51.  
  52. if __name__ == '__main__':
  53.     if len(sys.argv) < 2:
  54.         sys.exit("Usage: %s url [url...]" % sys.argv[0])
  55.    
  56.     for i in range(1, len(sys.argv)):
  57.         print(flickr_crack_secret(sys.argv[i]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement