def downloadAlbum(album): html = fetch(album.albumURL) b = renren.getPhotos(album,html) newAlbum = renren.getAlbumInfo(album.albumURL,html) album.albumName = newAlbum.albumName #username_230654960/albumname_id/photoid.type path = ''.join([album.ownerName,'_',album.ownerID,'/',album.albumName,'_',album.albumID,'/']) if not os.path.exists(path): os.makedirs(path) success = True for photo in b: type = photo.photoURL[photo.photoURL.rfind('.'):] success &= save(photo.photoURL,''.join([photo.photoID,type]),path,False) return success
def downloadAlbum(album): html = fetch(album.albumURL) b = renren.getPhotos(album, html) newAlbum = renren.getAlbumInfo(album.albumURL, html) album.albumName = newAlbum.albumName #username_230654960/albumname_id/photoid.type path = ''.join([ album.ownerName, '_', album.ownerID, '/', album.albumName, '_', album.albumID, '/' ]) if not os.path.exists(path): os.makedirs(path) success = True for photo in b: type = photo.photoURL[photo.photoURL.rfind('.'):] success &= save(photo.photoURL, ''.join([photo.photoID, type]), path, False) return success
def round(): #get user request url = safe_raw_input('URL,UID or quit(q):') if url.lower() == 'quit' or url.lower() == 'q': return False if url == '': return True albums = [] fixedURL = renren.getAlbumListURL(url) if fixedURL is not None: #fetch albums html html = fetch(fixedURL) albums = renren.getAlbums(html) else: fixedURL = renren.getPhotoListURL(url) if fixedURL is not None: html = fetch(fixedURL) album = renren.getAlbumInfo(fixedURL, html) albums.append(album) #download each album ac = safe_raw_input( 'You are about to download %d albums from %s (%s). Press Y to continue or others to abort.' % (len(albums), albums[0].ownerName, albums[0].ownerID)) success = True if ac.lower() == 'y': for album in albums: print 'Downloading %s (%d)' % (encode( album.albumName), album.picCount) try: success &= downloadAlbum(album) except Exception as e: print e success = False if success: print 'All %d albums from %s (%s) downloaded successfully.' \ % (len(albums),encode(albums[0].ownerName),albums[0].ownerID) else: print 'Some photos were not downloaded properly. Please recheck.' return True
def round(): #get user request url = safe_raw_input('URL,UID or quit(q):') if url.lower() == 'quit' or url.lower() =='q': return False if url == '': return True albums = [] fixedURL = renren.getAlbumListURL(url) if fixedURL is not None: #fetch albums html html = fetch(fixedURL) albums = renren.getAlbums(html) else: fixedURL = renren.getPhotoListURL(url) if fixedURL is not None: html = fetch(fixedURL) album = renren.getAlbumInfo(fixedURL,html) albums.append(album) #download each album ac = safe_raw_input('You are about to download %d albums from %s (%s). Press Y to continue or others to abort.' %(len(albums),albums[0].ownerName,albums[0].ownerID)) success = True if ac.lower() == 'y': for album in albums: print 'Downloading %s (%d)' % (encode(album.albumName),album.picCount) try: success &= downloadAlbum(album) except Exception as e: print e success = False if success: print 'All %d albums from %s (%s) downloaded successfully.' \ % (len(albums),encode(albums[0].ownerName),albums[0].ownerID) else: print 'Some photos were not downloaded properly. Please recheck.' return True