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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfc3b6e
Added mp3 tags
DipayanP007 bd486c4
Made some changes to main.py
DipayanP007 4d002e4
Updated main.py to pass the lint checks
DipayanP007 a0a9558
Modified the code for lint
DipayanP007 f75676d
Modified the code for lint
DipayanP007 0c39b1a
Modified main.py according to the changes
DipayanP007 39cf509
Modified main.py according to the changes
DipayanP007 6cc5bd3
Modified main.py according to the changes
DipayanP007 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
env/ | ||
attachments/ | ||
.idea/ | ||
venv/ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,25 @@ 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 does not 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 not audio.artist.isspace(): | ||||||
content = content + f"{str(audio.artist)} - " | ||||||
|
||||||
if audio.title is not None and not audio.title.isspace(): | ||||||
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.
Suggested change
|
||||||
content = content + f"{str(audio.title)}" | ||||||
# If the title tag does not exist but the artist tag exists, display the file name along with artist tag | ||||||
else: | ||||||
filename = path.splitext(filename)[0] | ||||||
content = content + filename.replace("_", " ") | ||||||
|
||||||
return discord.utils.escape_markdown(filename) | ||||||
return discord.utils.escape_markdown(content) | ||||||
|
||||||
|
||||||
async def command_stop(): | ||||||
|
@@ -230,7 +243,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 +291,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 +346,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 | ||||||
) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.