Skip to content

Commit 8cde7a7

Browse files
Improved reddit videos
close #510
1 parent fc785d8 commit 8cde7a7

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/cogs/loops/reddit.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
# > 3rd party dependencies
77
import asyncpraw
8-
import pandas as pd
98

109
# > Discord dependencies
1110
import discord
12-
from discord.ext import commands
13-
from discord.ext.tasks import loop
11+
import pandas as pd
1412

1513
# Local dependencies
1614
import util.vars
17-
from util.vars import config, data_sources
18-
from util.disc_util import get_channel, get_webhook
15+
from discord.ext import commands
16+
from discord.ext.tasks import loop
1917
from util.db import update_db
18+
from util.disc_util import get_channel, get_webhook
19+
from util.vars import config, data_sources
2020

2121

2222
class Reddit(commands.Cog):
@@ -132,17 +132,20 @@ async def wsb(self, reddit: asyncpraw.Reddit) -> None:
132132
or url.endswith(".gif")
133133
):
134134
img_url.append(url)
135+
# If the post includes multiple images
135136
elif "gallery" in url:
136137
image_dict = submission.media_metadata
137138
for image_item in image_dict.values():
138139
largest_image = image_item["s"]
139140
img_url.append(largest_image["u"])
140141
elif "v.redd.it" in url:
141142
video = True
142-
descr = ""
143-
144-
if descr == "" and not video and not img_url:
145-
continue
143+
if "images" in submission.preview:
144+
img_url.append(
145+
submission.preview["images"][0]["source"]["url"]
146+
)
147+
else:
148+
print("No image found for video post")
146149

147150
e = discord.Embed(
148151
title=title,
@@ -156,9 +159,9 @@ async def wsb(self, reddit: asyncpraw.Reddit) -> None:
156159
if img_url:
157160
e.set_image(url=img_url[0])
158161

159-
# e.set_thumbnail(
160-
# url="https://styles.redditmedia.com/t5_2th52/styles/communityIcon_wzrl8s0hx8a81.png?width=256&s=dcbf830170c1e8237335a3f046b36f723c5d55e7"
161-
# )
162+
# Add video emoji to the title
163+
if video:
164+
e.title = "🎥 " + e.title
162165

163166
e.set_footer(
164167
text=f"🔼 {submission.score} | 💬 {submission.num_comments}",
@@ -181,12 +184,7 @@ async def wsb(self, reddit: asyncpraw.Reddit) -> None:
181184
avatar_url=self.bot.user.avatar.url,
182185
)
183186
else:
184-
if video:
185-
await self.channel.send(
186-
content=f"https://www.reddit.com{submission.permalink}"
187-
)
188-
else:
189-
await self.channel.send(embed=e)
187+
await self.channel.send(embed=e)
190188

191189
counter += 1
192190

src/util/sentiment_analyis.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
##> Imports
22
# > Standard libaries
33
from __future__ import annotations
4+
45
import re
56

67
# > Third party libraries

0 commit comments

Comments
 (0)