Skip to content

Commit

Permalink
Better instagram session implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
amadejkastelic committed Nov 9, 2023
1 parent b92b5e0 commit f5b416f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,33 @@ A Discord bot that automatically embeds media and metadata of messages containin
docker pull ghcr.io/amadejkastelic/discord-video-embed-bot:<latest|tag>
```
- Run it with your discord api key: `docker run -e DISCORD_API_KEY=<api_key> video-embed-bot`
- Facebook requires you to provide cookies. Download them in your browser using [an extension](https://chrome.google.com/webstore/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc) while you're logged in and mount them to the container).

### Facebook
Facebook requires you to provide cookies. Download them in your browser using [an extension](https://chrome.google.com/webstore/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc) while you're logged in and mount them to the container).

### Reddit
- For extended reddit support you need to create an app on reddit and add the following environment variables:
```bash
REDDIT_API_TOKEN=<your_reddit_api_token>
REDDIT_API_SECRET=<your_reddit_api_secret>
REDDIT_USER_AGENT=<name_version_and_your_username>
```

### Twitter
- For better twitter support you need to add credentials:
```bash
TWITTER_USERNAME=<your_twitter_username>
TWITTER_EMAIL=<your_twitter_email>
TWITTER_PASSWORD=<your_twitter_password>
```

### Instagram
- For better instagram integration that allows to view items that require login, you need to provide the instagram.sess file and instagram username environemnt variable:
```bash
INSTAGRAM_USERNAME=<your_instagram_username>
```
- `instagram.sess` file should be in the working directory of your instance
- You can obtain the session file by logging into Instagram in Firefox and running:
```bash
python bin/fetch_instagram_session.py
```
8 changes: 4 additions & 4 deletions downloader/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def get_instance(cls) -> typing.Optional[instaloader.Instaloader]:
cls.INSTANCE = instaloader.Instaloader(
user_agent='Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'
)
if os.path.exists('instagram.sess'):
cls.INSTANCE.load_session_from_file(username='amadejkastelic', filename='instagram.sess')
if os.path.exists('instagram.sess') and os.getenv('INSTAGRAM_USERNAME') is not None:
cls.INSTANCE.load_session_from_file(username=os.getenv('INSTAGRAM_USERNAME'), filename='instagram.sess')

return cls.INSTANCE

Expand Down Expand Up @@ -94,9 +94,9 @@ def _get_post(self) -> models.Post:
def _get_story(self) -> models.Post:
story = instaloader.StoryItem.from_mediaid(context=self.client.context, mediaid=int(self.id))
if story.is_video:
url = story.video_url
url = story.video_url or story.url
else:
url = story.url
url = story.url or story.video_url

with requests.get(url=url) as resp:
return models.Post(
Expand Down

0 comments on commit f5b416f

Please sign in to comment.