2017-08-31 2 views
0

J'utilise flickrapi de télécharger des albums et ont écrit ce code:python flickrapi pour télécharger tous les albums

flickr = flickrapi.FlickrAPI(api_key, api_password, format='parsed-json') 
userid = 'XXXXXXXXX' 

# auth and token not required anymore, since already cached  
#flickr.authenticate_via_browser(perms='read') 
#token = flickr.get_request_token() 

photos = flickr.photos.search(user_id=userid, per_page='100') 
sets = flickr.photosets.getList(user_id=userid) 

#print photos 
#print sets 

total_photos=0 
for photoset_index in sets['photosets']['photoset']: 
    photoset_title = photoset_index['title']['_content'] 
    number_photos = photoset_index['photos'] 
    total_photos=total_photos+number_photos 
    #print photoset_title,number_photos 
total_number_of_albums = len(sets['photosets']['photoset']) 
print total_number_of_albums 

for photos_index in photos['photos']['photo']: 
    photo_name = photos_index['title'] 
    photo_id = photos_index['id'] 
    #print photo_name, photo_id 
total_number_of_pics = photos['photos']['total'] 
print total_photos, total_number_of_pics 

Je peux obtenir le nom de l'album et le nombre de photos, mais comment puis-je accéder à l'album photos? La documentation et l'API du développeur ne dit rien sur le téléchargement. https://www.flickr.com/services/api/

Répondre

0

J'ai trouvé une solution au problème. Vous avez besoin

sudo pip install flickr_download 

La documentation est https://pypi.python.org/pypi/flickr_download

Copie la sortie du code dans un script bash et exécuter. Tous les albums seraient téléchargés.

Le dessous est le code:

api_key = 'GET_IT_FROM_UR_FLICKR_ACCOUNT' 
api_secret = 'GET_IT_FROM_UR_FLICKR_ACCOUNT' 

flickr = flickrapi.FlickrAPI(api_key, api_secret, format='parsed-json') 
flickr.authenticate_via_browser(perms='read') 
print flickr.token_cache.token 

photos = flickr.photos.search(user_id=userid, per_page='100') 
sets = flickr.photosets.getList(user_id=userid) 

#print photos 
#print sets 

total_photos=0 
for photoset_index in sets['photosets']['photoset']: 
    photoset_title = photoset_index['title']['_content'] 
    number_photos = photoset_index['photos'] 
    id = photoset_index['id'] 
    total_photos=total_photos+number_photos 
    print "flickr_download -k " + api_key + " -s " + api_secret + " -t -d " + id 
    #print id,photoset_title,number_photos 
total_number_of_albums = len(sets['photosets']['photoset']) 
print total_number_of_albums 

for photos_index in photos['photos']['photo']: 
    photo_name = photos_index['title'] 
    photo_id = photos_index['id'] 
    #print photo_name, photo_id 
total_number_of_pics = photos['photos']['total'] 
# Cross check pics in photoset and actual number of pics. Should be equal 
print total_photos, total_number_of_pics