forked from nang-dev/automated_youtube_channel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape_videos.py
52 lines (40 loc) · 1.76 KB
/
scrape_videos.py
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
import datetime
import dateutil.relativedelta
from instalooter.looters import InstaLooter, ProfileLooter
import instaloader
from instalooter.cli.login import login
now = datetime.datetime.now()
dateTimeObj = datetime.datetime.now()
timestampStr = dateTimeObj.strftime("%d-%b-%Y (%H:%M:%S.%f)")
# scrape_videos.py scrapes all the videos from pages we are following
def scrapeVideos(username = "",
password = "",
output_folder = "",
days = 1):
print(timestampStr,'-',"Starting Scraping")
L = instaloader.Instaloader()
# Login or load session for loader
L.login(username, password)
profile = instaloader.Profile.from_username(L.context, username)
following = profile.get_followees()
#print(following)
for followee in profile.get_followees():
print(followee.username)
today = datetime.date.today()
timeframe = (today, today - dateutil.relativedelta.relativedelta(days=days))
for profile in following:
acc = profile.username
looter = ProfileLooter(acc, get_videos=True, videos_only=True, jobs=1, template="{id}-{username}-{width}-{height}")
if not looter.logged_in():
looter.login(username, password)
print(timestampStr,'-',"Scraping From Account: " + acc)
try:
numDowloaded = looter.download(output_folder, media_count=40, timeframe=timeframe)
print(timestampStr,'-',"Downloaded " + str(numDowloaded) + " videos successfully")
except Exception as e:
print(timestampStr,'-',"Skipped acc " + acc + "because of")
print(e);
if __name__ == "__main__":
scrapeVideos(username = "chewymemes_v3",
password = "",
output_folder = "./Memes_December_4")