■ ■ ■ ■ ■ ■
src/commands/stories/run.py
| 1 | + | from prettytable import PrettyTable |
| 2 | + | from src import printcolors as pc |
| 3 | + | import sys |
| 4 | + | import time |
| 5 | + | import urllib |
| 6 | + | import os |
| 7 | + | |
| 8 | + | |
| 9 | + | from src.CommandFather import CommandFather |
| 10 | + | |
| 11 | + | |
| 12 | + | class Command(CommandFather): |
| 13 | + | |
| 14 | + | def __init__(self, status, api): |
| 15 | + | super().__init__(status) |
| 16 | + | self.status = status |
| 17 | + | self.osintgram = api |
| 18 | + | |
| 19 | + | def run(self): |
| 20 | + | if self.osintgram.check_private_profile(): |
| 21 | + | return |
| 22 | + | |
| 23 | + | pc.printout("Searching for " + self.osintgram.target + " stories...\n") |
| 24 | + | |
| 25 | + | data = self.osintgram.get_api().user_reel_media(str(self.osintgram.target_id)) |
| 26 | + | |
| 27 | + | counter = 0 |
| 28 | + | |
| 29 | + | if data['items'] is not None: # no stories avaibile |
| 30 | + | counter = data['media_count'] |
| 31 | + | for i in data['items']: |
| 32 | + | story_id = i["id"] |
| 33 | + | if i["media_type"] == 1: # it's a photo |
| 34 | + | url = i['image_versions2']['candidates'][0]['url'] |
| 35 | + | end = super().get_option('output_path') + "/" + self.osintgram.target + "_" + story_id + ".jpg" |
| 36 | + | urllib.request.urlretrieve(url, end) |
| 37 | + | |
| 38 | + | elif i["media_type"] == 2: # it's a gif or video |
| 39 | + | url = i['video_versions'][0]['url'] |
| 40 | + | end = super().get_option('output_path') + "/" + self.osintgram.target + "_" + story_id + ".mp4" |
| 41 | + | urllib.request.urlretrieve(url, end) |
| 42 | + | |
| 43 | + | if counter > 0: |
| 44 | + | pc.printout(str(counter) + " target stories saved in output folder\n", pc.GREEN) |
| 45 | + | else: |
| 46 | + | pc.printout("Sorry! " + self.osintgram.target + " has no stories available :-(\n", pc.RED) |
| 47 | + | |