Skip to content

Commit

Permalink
Fix instagram downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
amadejkastelic committed Aug 1, 2023
1 parent 283eb52 commit bf412ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions downloader/instagram.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
from urllib.parse import urlparse

import aiohttp
import instaloader

from downloader import base
Expand All @@ -18,13 +17,12 @@ def __init__(self, url: str):
async def download(self) -> io.BytesIO:
post = instaloader.Post.from_shortcode(self.client.context, self.id)

async with aiohttp.ClientSession() as session:
async with session.get(post.video_url) as resp:
return (
self.MESSAGE.format(
url=self.url,
description=post.title or post.caption,
likes=post.likes,
),
io.BytesIO(await resp.read()),
)
with self.client.context._session.get(post.video_url) as resp:
return (
self.MESSAGE.format(
url=self.url,
description=post.title or post.caption,
likes=post.likes,
),
io.BytesIO(resp.content),
)
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def on_message(self, message: discord.Message):
text, video = await client.download()
except Exception as e:
logging.error(f'Failed downloading {url}: {str(e)}')
new_message.edit(f'Failed downloading {url}. {message.author.mention}')
await new_message.edit(content=f'Failed downloading {url}. {message.author.mention}')
return

await message.channel.send(
Expand Down

0 comments on commit bf412ca

Please sign in to comment.