Add some debug to saved io
This commit is contained in:
parent
2c6ee6e533
commit
7e87b9b5ac
2 changed files with 41 additions and 6 deletions
|
@ -4,7 +4,7 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="aa6d62a8-d64d-4a60-a85f-8d9fa52b6b49" name="Changes" comment="Fix aiosqlite again">
|
<list default="true" id="aa6d62a8-d64d-4a60-a85f-8d9fa52b6b49" name="Changes" comment="Forgot to hexdigest">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/cogs/ytdl.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cogs/ytdl.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/cogs/ytdl.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cogs/ytdl.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
<workItem from="1704572901106" duration="125000" />
|
<workItem from="1704572901106" duration="125000" />
|
||||||
<workItem from="1704573038888" duration="7749000" />
|
<workItem from="1704573038888" duration="7749000" />
|
||||||
<workItem from="1704760229948" duration="946000" />
|
<workItem from="1704760229948" duration="946000" />
|
||||||
<workItem from="1704790508193" duration="2436000" />
|
<workItem from="1704790508193" duration="2855000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Update gitignore">
|
<task id="LOCAL-00001" summary="Update gitignore">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -275,7 +275,23 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1704793106430</updated>
|
<updated>1704793106430</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="25" />
|
<task id="LOCAL-00025" summary="I hate SQL">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1704793198163</created>
|
||||||
|
<option name="number" value="00025" />
|
||||||
|
<option name="presentableId" value="LOCAL-00025" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1704793198163</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00026" summary="Forgot to hexdigest">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1704793320744</created>
|
||||||
|
<option name="number" value="00026" />
|
||||||
|
<option name="presentableId" value="LOCAL-00026" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1704793320744</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="27" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
@ -283,7 +299,6 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||||
<MESSAGE value="Update gitignore" />
|
|
||||||
<MESSAGE value="Beta 1 * Screenshot (unpolished, functional) * Dig * Traceroute * Whois * Ping * yt-dl" />
|
<MESSAGE value="Beta 1 * Screenshot (unpolished, functional) * Dig * Traceroute * Whois * Ping * yt-dl" />
|
||||||
<MESSAGE value="Beta 1 * Screenshot (unpolished, functional) * Dig * Traceroute * Whois * Ping * yt-dl * Docker file" />
|
<MESSAGE value="Beta 1 * Screenshot (unpolished, functional) * Dig * Traceroute * Whois * Ping * yt-dl * Docker file" />
|
||||||
<MESSAGE value="Update the docker image" />
|
<MESSAGE value="Update the docker image" />
|
||||||
|
@ -307,6 +322,8 @@
|
||||||
<MESSAGE value="Allow re-use of previous downloads" />
|
<MESSAGE value="Allow re-use of previous downloads" />
|
||||||
<MESSAGE value="Fix aiosqlite" />
|
<MESSAGE value="Fix aiosqlite" />
|
||||||
<MESSAGE value="Fix aiosqlite again" />
|
<MESSAGE value="Fix aiosqlite again" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Fix aiosqlite again" />
|
<MESSAGE value="I hate SQL" />
|
||||||
|
<MESSAGE value="Forgot to hexdigest" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Forgot to hexdigest" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -93,6 +93,13 @@ class YTDLCog(commands.Cog):
|
||||||
await self._init_db()
|
await self._init_db()
|
||||||
async with aiosqlite.connect("./data/ytdl.db") as db:
|
async with aiosqlite.connect("./data/ytdl.db") as db:
|
||||||
_hash = hashlib.md5(f"{webpage_url}:{format_id}".encode()).hexdigest()
|
_hash = hashlib.md5(f"{webpage_url}:{format_id}".encode()).hexdigest()
|
||||||
|
self.log.debug(
|
||||||
|
"Saving %r (%r:%r) with message %d>%d, index %d",
|
||||||
|
_hash,
|
||||||
|
message.channel.id,
|
||||||
|
message.id,
|
||||||
|
attachment_index
|
||||||
|
)
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO downloads (key, message_id, channel_id, webpage_url, format_id, attachment_index)
|
INSERT INTO downloads (key, message_id, channel_id, webpage_url, format_id, attachment_index)
|
||||||
|
@ -113,26 +120,37 @@ class YTDLCog(commands.Cog):
|
||||||
await self._init_db()
|
await self._init_db()
|
||||||
async with aiosqlite.connect("./data/ytdl.db") as db:
|
async with aiosqlite.connect("./data/ytdl.db") as db:
|
||||||
_hash = hashlib.md5(f"{webpage_url}:{format_id}".encode()).hexdigest()
|
_hash = hashlib.md5(f"{webpage_url}:{format_id}".encode()).hexdigest()
|
||||||
|
self.log.debug(
|
||||||
|
"Attempting to find a saved download for '%s:%s' (%r).",
|
||||||
|
webpage_url,
|
||||||
|
format_id,
|
||||||
|
_hash
|
||||||
|
)
|
||||||
cursor = await db.execute(
|
cursor = await db.execute(
|
||||||
"SELECT message_id, channel_id, attachment_index FROM downloads WHERE key=?",
|
"SELECT message_id, channel_id, attachment_index FROM downloads WHERE key=?",
|
||||||
(_hash,)
|
(_hash,)
|
||||||
)
|
)
|
||||||
entry = await cursor.fetchone()
|
entry = await cursor.fetchone()
|
||||||
if not entry:
|
if not entry:
|
||||||
|
self.log.debug("There was no saved download.")
|
||||||
return
|
return
|
||||||
message_id, channel_id, attachment_index = entry
|
message_id, channel_id, attachment_index = entry
|
||||||
channel = self.bot.get_channel(channel_id)
|
channel = self.bot.get_channel(channel_id)
|
||||||
if not channel:
|
if not channel:
|
||||||
|
self.log.debug("Channel %r was not found.", channel_id)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
message = await channel.fetch_message(message_id)
|
message = await channel.fetch_message(message_id)
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
|
self.log.debug("%r did not contain a message with ID %r", channel, message_id)
|
||||||
await db.execute("DELETE FROM downloads WHERE key=?", (_hash,))
|
await db.execute("DELETE FROM downloads WHERE key=?", (_hash,))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return message.attachments[attachment_index].url
|
url = message.attachments[attachment_index].url
|
||||||
|
self.log.debug("Found URL %r, returning.", url)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
self.log.debug("Attachment index %d is out of range (%r)", attachment_index, message.attachments)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue