New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solved: Read media info from tags #30
Changes from 6 commits
bfc3b6e
bd486c4
4d002e4
a0a9558
f75676d
0c39b1a
39cf509
6cc5bd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
env/ | ||
attachments/ | ||
.idea/ | ||
venv/ | ||
__pycache__/ |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ | |||||||||||||||||||||||||||||||||
TextChannel, | ||||||||||||||||||||||||||||||||||
VoiceClient, | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
from tinytag import TinyTag | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# SETTINGS | ||||||||||||||||||||||||||||||||||
# How many seconds to wait in-between songs | ||||||||||||||||||||||||||||||||||
|
@@ -99,13 +100,29 @@ async def on_message(message: Message): | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Take a filename as string and return it formatted nicely | ||||||||||||||||||||||||||||||||||
def format_filename(filename: str): | ||||||||||||||||||||||||||||||||||
# Remove file extension | ||||||||||||||||||||||||||||||||||
filename = path.splitext(filename)[0] | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Replace all underscores with spaces | ||||||||||||||||||||||||||||||||||
filename = filename.replace("_", " ") | ||||||||||||||||||||||||||||||||||
# Get all the tags for a track | ||||||||||||||||||||||||||||||||||
audio = TinyTag.get( | ||||||||||||||||||||||||||||||||||
str(os.path.join(f"{attachment_directory_filepath}", f"{filename}")) | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
content = "" | ||||||||||||||||||||||||||||||||||
# If the tag doesnot exist or is whitespace display the file name only | ||||||||||||||||||||||||||||||||||
# Otherwise display in the format @user: <Artist-tag> - <Title-tag> | ||||||||||||||||||||||||||||||||||
if audio.artist is not None and len(audio.artist.strip()) != 0: | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed this in my first review, but using
Suggested change
|
||||||||||||||||||||||||||||||||||
content = content + f"{str(audio.artist)} - " | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if audio.title is not None: | ||||||||||||||||||||||||||||||||||
if len(audio.title.strip()) == 0: | ||||||||||||||||||||||||||||||||||
filename = path.splitext(filename)[0] | ||||||||||||||||||||||||||||||||||
content = content + filename.replace("_", " ") | ||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||
content = content + f"{str(audio.title)}" | ||||||||||||||||||||||||||||||||||
# If the title tag doesnot exist but the artist tag exists, display the file name along with artist tag | ||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||
filename = path.splitext(filename)[0] | ||||||||||||||||||||||||||||||||||
content = content + filename.replace("_", " ") | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove some duplicated code if we write the if statements like this
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return discord.utils.escape_markdown(filename) | ||||||||||||||||||||||||||||||||||
return discord.utils.escape_markdown(content) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
async def command_stop(): | ||||||||||||||||||||||||||||||||||
|
@@ -230,7 +247,7 @@ async def inner_f(): | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Build and send "Now Playing" embed | ||||||||||||||||||||||||||||||||||
embed_title = f"{random_emoji} Now Playing {random_emoji}" | ||||||||||||||||||||||||||||||||||
list_format = "{0} - [{1}]({2}) [`↲jump`]({3})" | ||||||||||||||||||||||||||||||||||
list_format = "{0}: [{1}]({2}) [`↲jump`]({3})" | ||||||||||||||||||||||||||||||||||
embed_content = list_format.format( | ||||||||||||||||||||||||||||||||||
submit_message.author.mention, | ||||||||||||||||||||||||||||||||||
format_filename(attachment.filename), | ||||||||||||||||||||||||||||||||||
|
@@ -278,7 +295,7 @@ async def command_list(message: Message): | |||||||||||||||||||||||||||||||||
attachment, | ||||||||||||||||||||||||||||||||||
local_filepath, | ||||||||||||||||||||||||||||||||||
) in enumerate(channel_media_attachments): | ||||||||||||||||||||||||||||||||||
list_format = "**{0}.** {1} - [{2}]({3}) [`↲jump`]({4})\n" | ||||||||||||||||||||||||||||||||||
list_format = "**{0}.** {1}: [{2}]({3}) [`↲jump`]({4})\n" | ||||||||||||||||||||||||||||||||||
embed_content += list_format.format( | ||||||||||||||||||||||||||||||||||
index + 1, | ||||||||||||||||||||||||||||||||||
submit_message.author.mention, | ||||||||||||||||||||||||||||||||||
|
@@ -333,7 +350,6 @@ async def scrape_channel_media( | |||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Save attachment content | ||||||||||||||||||||||||||||||||||
# TODO: Parse mp3 tags and things | ||||||||||||||||||||||||||||||||||
attachment_filepath = path.join( | ||||||||||||||||||||||||||||||||||
attachment_directory_filepath, attachment.filename | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pynacl>=1.4.0 | ||
discord.py>=1.7.3 | ||
discord.py>=1.7.3 | ||
tinytag==1.7.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.