Skip to content

Instantly share code, notes, and snippets.

@ellieayla
Created January 20, 2018 18:04
Show Gist options
  • Save ellieayla/4322b5da79b74bb09f96193c1dc01cb4 to your computer and use it in GitHub Desktop.
Save ellieayla/4322b5da79b74bb09f96193c1dc01cb4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# I had a pile of http://fav.me/... urls in a text file, and wanted to retrieve the original files via OEMBED.
from urllib.parse import quote
from urllib.request import urlopen, urlretrieve
import json
import sys
if __name__ == "__main__":
for fav in sys.stdin:
url = fav.split(' ')[0]
print(url)
with urlopen("https://backend.deviantart.com/oembed?url=" + quote(url)) as response:
r = json.load(response)
basename = r['url'].split("/")[-1]
local_filename, headers = urlretrieve(r['url'], basename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment