Skip to content

Instantly share code, notes, and snippets.

@tervay
Last active July 9, 2021 22:12
Show Gist options
  • Save tervay/a5911760007351f79acb6fcffc473446 to your computer and use it in GitHub Desktop.
Save tervay/a5911760007351f79acb6fcffc473446 to your computer and use it in GitHub Desktop.
Flickr Video Downloader
$ pip install requests flickrapi lxml requests-cache
from flickrapi import FlickrAPI
from lxml import etree
import requests
import shutil
import requests_cache
requests_cache.install_cache("flickr_cache")
key = "<key>"
secret = "<secret>"
user = "<user id>"
api = FlickrAPI(key, secret, cache=True)
def download_file(url, name):
local_filename = "out/" + name + ".mp4"
with requests.get(url, stream=True) as r:
with open(local_filename, "wb") as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def get(id_, name):
print(f"Downloading {id_} as {name}.mp4")
url = f"https://www.flickr.com/video_download.gne?id={id_}"
download_file(url, name)
for thing in api.walk_user(user):
id_ = thing.attrib["id"]
rsp = api.photos.getSizes(photo_id=thing.attrib["id"])
xml = etree.tostring(rsp).decode("utf-8")
if "video" in xml:
info_rsp = api.photos.getInfo(photo_id=thing.attrib["id"])
date_str = "unknown-date"
for photo in info_rsp:
for info_blob in photo:
if "taken" in info_blob.attrib:
splt = info_blob.attrib["taken"].split(" ")
date_str = splt[0] + "_" + splt[1].replace(":", "-")
get(thing.attrib["id"], date_str + "_" + thing.attrib["title"] + "_" + id_)
else:
print(f" Skipped {id_}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment