Skip to content

Commit

Permalink
adds instagram no stories as success, and fix for telethon-based arch…
Browse files Browse the repository at this point in the history
…ivers.
  • Loading branch information
msramalho committed Mar 5, 2024
1 parent 601572d commit f482777
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/auto_archiver/archivers/instagram_api_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ def _download_highlights_reusable(self, result: Metadata, id: str) ->dict:
def download_stories(self, result: Metadata, username: str) -> Metadata:
now = datetime.now().strftime("%Y-%m-%d_%H-%M")
stories = self._download_stories_reusable(result, username)
if stories == []: return result.success("insta no story")
result.set_title(f"stories {username} at {now}").set("#stories", len(stories))
return result.success(f"insta stories {now}")

def _download_stories_reusable(self, result: Metadata, username: str) -> list[dict]:
stories = self.call_api(f"v1/user/stories/by/username", {"username": username})
assert stories, f"Stories for {username} not found"
if not stories or not len(stories): return []
stories = stories[::-1] # newest to oldest

for s in tqdm(stories, desc="downloading stories", unit="story"):
Expand Down
2 changes: 1 addition & 1 deletion src/auto_archiver/archivers/instagram_tbot_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup(self) -> None:
# make a copy of the session that is used exclusively with this archiver instance
new_session_file = os.path.join("secrets/", f"instabot-{time.strftime('%Y-%m-%d')}{random_str(8)}.session")
shutil.copy(self.session_file + ".session", new_session_file)
self.session_file = new_session_file
self.session_file = new_session_file.replace(".session", "")

try:
self.client = TelegramClient(self.session_file, self.api_id, self.api_hash)
Expand Down
2 changes: 1 addition & 1 deletion src/auto_archiver/archivers/telethon_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setup(self) -> None:
# make a copy of the session that is used exclusively with this archiver instance
new_session_file = os.path.join("secrets/", f"telethon-{time.strftime('%Y-%m-%d')}{random_str(8)}.session")
shutil.copy(self.session_file + ".session", new_session_file)
self.session_file = new_session_file
self.session_file = new_session_file.replace(".session", "")

# initiate the client
self.client = TelegramClient(self.session_file, self.api_id, self.api_hash)
Expand Down
3 changes: 2 additions & 1 deletion src/auto_archiver/archivers/youtubedl_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def download(self, item: Metadata) -> Metadata:
return False

# this time download
ydl = yt_dlp.YoutubeDL({**ydl_options, "getcomments": self.comments})
ydl = yt_dlp.YoutubeDL({**ydl_options, "getcomments": self.comments})
#TODO: for playlist or long lists of videos, how to download one at a time so they can be stored before the next one is downloaded?
info = ydl.extract_info(url, download=True)

if "entries" in info:
Expand Down
2 changes: 1 addition & 1 deletion src/auto_archiver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
_MINOR = "10"
# On main and in a nightly release the patch should be one ahead of the last
# released build.
_PATCH = "0"
_PATCH = "1"
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
# https://semver.org/#is-v123-a-semantic-version for the semantics.
_SUFFIX = ""
Expand Down

0 comments on commit f482777

Please sign in to comment.