-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadAlbums.py
More file actions
55 lines (45 loc) · 1.68 KB
/
DownloadAlbums.py
File metadata and controls
55 lines (45 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: Eduardo Frazão
# * http://github.com/fr4z40
# * https://bitbucket.org/fr4z40
import json
from urllib.request import urlopen
from subprocess import call
from getpass import getpass
from os import mkdir, chdir
from os.path import exists
# --------------------------- #
from facebook import GraphAPI #
# --------------------------- #
def down(url):
cli = 'Mozilla/5.0 Gecko/20100101 Firefox/39.0'
call(('wget -t 5 --user-agent="%s" -c "%s"' % (cli,url)), shell=True)
# -------------------------------------------------------------------------------------------------- #
def down_photos(album_name, album_id, qtd):
if exists('%s' % album_name) == False:
mkdir('%s' % album_name)
chdir('%s' % album_name)
try:
photos = (facebook_api.get_connections(album_id, 'photos'))['paging']['next']
photos = (((((photos.split('&after='))[0]).split('limit='))[0]) + 'limit=' + str(qtd))
photos = ((json.loads((urlopen(photos)).read().decode('utf8')))['data'])
for p in photos:
down(((p['images'])[0])['source'])
print('\n')
except:
pass
chdir('..')
facebook_api = GraphAPI(getpass("Token:"))
user_id = (facebook_api.get_object("me"))['id']
albums = (facebook_api.get_connections(user_id, 'albums'))['data']
for a in albums:
try:
album_name = a['name']
album_id = a['id']
qtd = a['count']
print('Saving Album: "%s"\nTotal Pics: %s\n\n' % (album_name, str(qtd)))
down_photos(album_name, album_id, qtd)
except:
pass
# -------------------------------------------------------------------------------------------------- #