-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add seek command #344
Add seek command #344
Conversation
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.
This is a feature I have kept on the backburner because just adding this command is not quite enough. The following are all related to seeking and should all be added at the same time:
- seeking to a specific point in a song (what this command currently does)
- seeking forward/backward a certain amount of time in a song
- starting a song at a specific time (both via the
play
command as well as in playlists; youtube has a format for this and jmusicbot should probably adapt that same format)
Additionally, I want to keep time-related notation consistent throughout the bot.
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
How do you think we should deal with invalid input in |
By the way sorry if this PR is messy, this is my first one. If you got any suggestions on how I can do it better, I'm open to them :) |
Since the time parsing will likely need to be able to handle both specific and relative times ( public static class SeekTime
{
public final int seconds;
public final boolean relative;
/* constructor here */
}
Exception or null, I tend to use nulls but exceptions are useful if there are multiple fail-cases.
Generally it's better to keep similar changes in a single commit, but I can squash before merging so it's not a huge deal. |
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.
For the parsing function, I think the format for relative times should just be the same but with a preceding +
or -
. For example, +04:20
will seek forward 4 minutes and 20 seconds, -20
will seek backwards 20 seconds, and 01:23
will seek directly to 1 minute 23 seconds into the song. The parsing function should be in the new TimeUtil you added (checking that the resulting time is valid for the current song should still be in the command).
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
I like the idea with the + and - before the timestamp. I'll do the forward/backward seeking in the coming days. |
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java
Outdated
Show resolved
Hide resolved
Seek with decimals, no timestamp separator And examples of course 👀 |
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.
Nearly there!
this.help = "seeks the current song" + | ||
"\nExamples: `1:02:23` `+1:10` `-90`"; |
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.
I wouldn't include this second line in the help, as every other command has a single-line brief help. Save the examples for if someone enters the command wrong (after the 'Expected format' error message later in this file)
TimeUtil.SeekTime seekTime = TimeUtil.parseTime(args); | ||
if (seekTime == null) | ||
{ | ||
event.replyError("Invalid seek! Expected format: " + arguments); |
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.
Put the second line of the help here instead of in the help itself.
@@ -0,0 +1,49 @@ | |||
package com.jagrosh.jmusicbot; |
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.
license header
assertTrue(seek.relative); | ||
assertEquals(-5000, seek.milliseconds); | ||
} | ||
} |
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.
Good tests so far, although I also want to see assertFalse(seek.relative)
for the seeks that are not relative, as well as some things that intentionally return null from parseTime
So, is this finally able to become a real feature? I am really looking forward to this functionality. |
Really looking forward to this feature! I tested it and get the following exception when trying to play a song, eg. I tested it using openjdk 8 and 14 running on Ubuntu 20.04
|
@whew-inc Fantastic, it works! Thanks a lot, I'm very happy with your work :D |
Is this still open or has it been implemented yet? I would love to see this feature and would be happy to help with it as needed. |
The PR is still open because it isn't finished yet, as per this comment
|
This comment has been minimized.
This comment has been minimized.
Seems too hacky for me.
Alright, I'm picking it back up in #674. |
Maybe don't inline everything? Also a native implementation is better than using eval for this. Also Java isn't JS. It would have been better if you picked the PR up instead of designing a roundabout for a straight path. |
but what if the scripting engine used for eval is js? :o |
I'm not a contributor, just a user. I listen to long-form audio so I needed a way to seek without restarting the whole track. I only posted the script on the off chance someone would have a similar use case while the pull request is ongoing. |
Hello, I noticed the last there hasn't been any comments on this issue since April, any updates? |
I will work on this feature in #674 in the future. |
Since my PR #674 is (mostly) finished, I'll close this in favor of it. |
* Add seek command * Combine nested if statements * Put the seek command in correct place to keep alphabetical order * Add license header * Brackets on next line * Restructure if-statements * Check for permissions with DJCommand#checkDJPermission * Make regex slightly smaller * Optimize imports * Output length of current track if requested seek time is invalid * Restate seeked point when seeked successfully * Add empty newline at end of file to keep consistency * Create TimeUtil class for parsing and formatting time * Move FormatUtil#formatTime to TimeUtil, and refactor * Apply requested changes (Pass 2) * Seek based on current position in track * Apply requested changes (Pass 3) * Add javadoc param * Apply requested changes (Pass 4) * Fix merge * Avoid reassigning parameter (Codacy) * Rework timestamp parsing * Refactor timestamp parsing * Apply requested changes (Pass 5) * Add examples in help * Apply requested changes (Pass 6) * Fix missing import * Keep track of start timestamp & add "unit" times * Fix my abdominal merge with QueuedTrack * Use RequestMetadata to store start timestamp * Store request info in request metadata * Add regex to try getting a timestamp from the url * Require RequestMetadata for QueuedTracks * Add some unit tests for unit seeking * Add docs & examples --------- Co-authored-by: Whew., Inc <22574706+Whew-Inc@users.noreply.github.com>
commit 8733899 Author: John Grosh <john.a.grosh@gmail.com> Date: Wed Jul 10 17:35:50 2024 -0400 Update bug-report.yml commit e5fd05e Author: Moritz Bender <35152647+Morilli@users.noreply.github.com> Date: Wed Jul 10 13:19:13 2024 +0200 Update dependencies to fix youtube issues (jagrosh#1609) commit 6a5a9c7 Author: John Grosh <john.a.grosh@gmail.com> Date: Fri May 10 17:43:49 2024 -0400 Change playlist page count (jagrosh#1542) * change playlist page count * make the value configurable * small refactor commit 8557f7a Author: Michaili K <git@michaili.dev> Date: Fri May 10 21:36:43 2024 +0200 Log track exceptions in the audio handler (jagrosh#1558) commit 48e62f1 Author: Michaili K <git@michaili.dev> Date: Fri May 10 21:32:30 2024 +0200 Revert "Always self-deafen (jagrosh#1491)" (jagrosh#1551) This reverts commit a7807b9. commit 6f12c33 Author: John Grosh <john.a.grosh@gmail.com> Date: Fri May 10 15:23:30 2024 -0400 custom eval engine (jagrosh#1530) commit 0afb3db Author: Michaili K <git@michaili.dev> Date: Fri May 10 20:19:11 2024 +0200 Switch to lavalink's new YouTube audio source manager (jagrosh#1552) * Switch to new lavalink's new YouTube audio source manager * Add back setPlaylistPageCount call for the youtube audio source manager * Manually add all the individual audio sources EXCEPT for old youtube * Remove unused import * Upgrade lavaplayer-youtube-source to 1.0.3 * Upgrade lavaplayer-youtube-source to 1.0.4 commit 81322ef Author: Michaili K <git@michaili.dev> Date: Fri May 10 20:14:28 2024 +0200 Add seek command (supersedes jagrosh#344) (jagrosh#674) * Add seek command * Combine nested if statements * Put the seek command in correct place to keep alphabetical order * Add license header * Brackets on next line * Restructure if-statements * Check for permissions with DJCommand#checkDJPermission * Make regex slightly smaller * Optimize imports * Output length of current track if requested seek time is invalid * Restate seeked point when seeked successfully * Add empty newline at end of file to keep consistency * Create TimeUtil class for parsing and formatting time * Move FormatUtil#formatTime to TimeUtil, and refactor * Apply requested changes (Pass 2) * Seek based on current position in track * Apply requested changes (Pass 3) * Add javadoc param * Apply requested changes (Pass 4) * Fix merge * Avoid reassigning parameter (Codacy) * Rework timestamp parsing * Refactor timestamp parsing * Apply requested changes (Pass 5) * Add examples in help * Apply requested changes (Pass 6) * Fix missing import * Keep track of start timestamp & add "unit" times * Fix my abdominal merge with QueuedTrack * Use RequestMetadata to store start timestamp * Store request info in request metadata * Add regex to try getting a timestamp from the url * Require RequestMetadata for QueuedTracks * Add some unit tests for unit seeking * Add docs & examples --------- Co-authored-by: Whew., Inc <22574706+Whew-Inc@users.noreply.github.com>
commit 8733899 Author: John Grosh <john.a.grosh@gmail.com> Date: Wed Jul 10 17:35:50 2024 -0400 Update bug-report.yml commit e5fd05e Author: Moritz Bender <35152647+Morilli@users.noreply.github.com> Date: Wed Jul 10 13:19:13 2024 +0200 Update dependencies to fix youtube issues (jagrosh#1609) commit 6a5a9c7 Author: John Grosh <john.a.grosh@gmail.com> Date: Fri May 10 17:43:49 2024 -0400 Change playlist page count (jagrosh#1542) * change playlist page count * make the value configurable * small refactor commit 8557f7a Author: Michaili K <git@michaili.dev> Date: Fri May 10 21:36:43 2024 +0200 Log track exceptions in the audio handler (jagrosh#1558) commit 48e62f1 Author: Michaili K <git@michaili.dev> Date: Fri May 10 21:32:30 2024 +0200 Revert "Always self-deafen (jagrosh#1491)" (jagrosh#1551) This reverts commit a7807b9. commit 6f12c33 Author: John Grosh <john.a.grosh@gmail.com> Date: Fri May 10 15:23:30 2024 -0400 custom eval engine (jagrosh#1530) commit 0afb3db Author: Michaili K <git@michaili.dev> Date: Fri May 10 20:19:11 2024 +0200 Switch to lavalink's new YouTube audio source manager (jagrosh#1552) * Switch to new lavalink's new YouTube audio source manager * Add back setPlaylistPageCount call for the youtube audio source manager * Manually add all the individual audio sources EXCEPT for old youtube * Remove unused import * Upgrade lavaplayer-youtube-source to 1.0.3 * Upgrade lavaplayer-youtube-source to 1.0.4 commit 81322ef Author: Michaili K <git@michaili.dev> Date: Fri May 10 20:14:28 2024 +0200 Add seek command (supersedes jagrosh#344) (jagrosh#674) * Add seek command * Combine nested if statements * Put the seek command in correct place to keep alphabetical order * Add license header * Brackets on next line * Restructure if-statements * Check for permissions with DJCommand#checkDJPermission * Make regex slightly smaller * Optimize imports * Output length of current track if requested seek time is invalid * Restate seeked point when seeked successfully * Add empty newline at end of file to keep consistency * Create TimeUtil class for parsing and formatting time * Move FormatUtil#formatTime to TimeUtil, and refactor * Apply requested changes (Pass 2) * Seek based on current position in track * Apply requested changes (Pass 3) * Add javadoc param * Apply requested changes (Pass 4) * Fix merge * Avoid reassigning parameter (Codacy) * Rework timestamp parsing * Refactor timestamp parsing * Apply requested changes (Pass 5) * Add examples in help * Apply requested changes (Pass 6) * Fix missing import * Keep track of start timestamp & add "unit" times * Fix my abdominal merge with QueuedTrack * Use RequestMetadata to store start timestamp * Store request info in request metadata * Add regex to try getting a timestamp from the url * Require RequestMetadata for QueuedTracks * Add some unit tests for unit seeking * Add docs & examples --------- Co-authored-by: Whew., Inc <22574706+Whew-Inc@users.noreply.github.com>
commit 8733899 Author: John Grosh <john.a.grosh@gmail.com> Date: Wed Jul 10 17:35:50 2024 -0400 Update bug-report.yml commit e5fd05e Author: Moritz Bender <35152647+Morilli@users.noreply.github.com> Date: Wed Jul 10 13:19:13 2024 +0200 Update dependencies to fix youtube issues (jagrosh#1609) commit 6a5a9c7 Author: John Grosh <john.a.grosh@gmail.com> Date: Fri May 10 17:43:49 2024 -0400 Change playlist page count (jagrosh#1542) * change playlist page count * make the value configurable * small refactor commit 8557f7a Author: Michaili K <git@michaili.dev> Date: Fri May 10 21:36:43 2024 +0200 Log track exceptions in the audio handler (jagrosh#1558) commit 48e62f1 Author: Michaili K <git@michaili.dev> Date: Fri May 10 21:32:30 2024 +0200 Revert "Always self-deafen (jagrosh#1491)" (jagrosh#1551) This reverts commit a7807b9. commit 6f12c33 Author: John Grosh <john.a.grosh@gmail.com> Date: Fri May 10 15:23:30 2024 -0400 custom eval engine (jagrosh#1530) commit 0afb3db Author: Michaili K <git@michaili.dev> Date: Fri May 10 20:19:11 2024 +0200 Switch to lavalink's new YouTube audio source manager (jagrosh#1552) * Switch to new lavalink's new YouTube audio source manager * Add back setPlaylistPageCount call for the youtube audio source manager * Manually add all the individual audio sources EXCEPT for old youtube * Remove unused import * Upgrade lavaplayer-youtube-source to 1.0.3 * Upgrade lavaplayer-youtube-source to 1.0.4 commit 81322ef Author: Michaili K <git@michaili.dev> Date: Fri May 10 20:14:28 2024 +0200 Add seek command (supersedes jagrosh#344) (jagrosh#674) * Add seek command * Combine nested if statements * Put the seek command in correct place to keep alphabetical order * Add license header * Brackets on next line * Restructure if-statements * Check for permissions with DJCommand#checkDJPermission * Make regex slightly smaller * Optimize imports * Output length of current track if requested seek time is invalid * Restate seeked point when seeked successfully * Add empty newline at end of file to keep consistency * Create TimeUtil class for parsing and formatting time * Move FormatUtil#formatTime to TimeUtil, and refactor * Apply requested changes (Pass 2) * Seek based on current position in track * Apply requested changes (Pass 3) * Add javadoc param * Apply requested changes (Pass 4) * Fix merge * Avoid reassigning parameter (Codacy) * Rework timestamp parsing * Refactor timestamp parsing * Apply requested changes (Pass 5) * Add examples in help * Apply requested changes (Pass 6) * Fix missing import * Keep track of start timestamp & add "unit" times * Fix my abdominal merge with QueuedTrack * Use RequestMetadata to store start timestamp * Store request info in request metadata * Add regex to try getting a timestamp from the url * Require RequestMetadata for QueuedTracks * Add some unit tests for unit seeking * Add docs & examples --------- Co-authored-by: Whew., Inc <22574706+Whew-Inc@users.noreply.github.com>
* Add seek command * Combine nested if statements * Put the seek command in correct place to keep alphabetical order * Add license header * Brackets on next line * Restructure if-statements * Check for permissions with DJCommand#checkDJPermission * Make regex slightly smaller * Optimize imports * Output length of current track if requested seek time is invalid * Restate seeked point when seeked successfully * Add empty newline at end of file to keep consistency * Create TimeUtil class for parsing and formatting time * Move FormatUtil#formatTime to TimeUtil, and refactor * Apply requested changes (Pass 2) * Seek based on current position in track * Apply requested changes (Pass 3) * Add javadoc param * Apply requested changes (Pass 4) * Fix merge * Avoid reassigning parameter (Codacy) * Rework timestamp parsing * Refactor timestamp parsing * Apply requested changes (Pass 5) * Add examples in help * Apply requested changes (Pass 6) * Fix missing import * Keep track of start timestamp & add "unit" times * Fix my abdominal merge with QueuedTrack * Use RequestMetadata to store start timestamp * Store request info in request metadata * Add regex to try getting a timestamp from the url * Require RequestMetadata for QueuedTracks * Add some unit tests for unit seeking * Add docs & examples --------- Co-authored-by: Whew., Inc <22574706+Whew-Inc@users.noreply.github.com>
This pull request...
Description
Allows DJs and user that added the track to perform a seek on a playing track.
Purpose
Example: Going to a specific timestamp in a song compilation.
Relevant Issue(s)
No relevant issue AFAIK, only a planned feature:
https://github.com/jagrosh/MusicBot/projects/1#card-1542746