-
-
Notifications
You must be signed in to change notification settings - Fork 52
Add support for playlists #840
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
91bf83a
Add support for playlists
zeebok c5cbbcc
Fix lint error
zeebok 98f4a40
Merge branch 'main' into playlist-object
zeebok 3cd1dc0
Merge branch 'main' into playlist-object
zeebok 19b4cd4
Merge branch 'main' into playlist-object
zeebok 9f9d008
Fix uncaught error when saving a new playlist
zeebok 81de63d
Merge branch 'playlist-object' of github.com:elementary/music into pl…
zeebok 175ff68
Fix save playlist dialog to filter playlist files
zeebok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-3.0-or-later | ||
| * SPDX-FileCopyrightText: 2026 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| public class Music.PlaylistObject : Object { | ||
| public File playlist_file { get; construct; } | ||
| private File[] uri_list = {}; | ||
|
|
||
| public PlaylistObject (File playlist) { | ||
| Object (playlist_file: playlist); | ||
| } | ||
|
|
||
| public static bool is_playlist (File playlist) { | ||
| FileInfo info; | ||
|
|
||
| try { | ||
| info = playlist.query_info (GLib.FileAttribute.STANDARD_CONTENT_TYPE, GLib.FileQueryInfoFlags.NONE); | ||
| } catch (Error e) { | ||
| warning (e.message); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| var mimetype = info.get_content_type (); | ||
| if (mimetype == null) { | ||
| warning ("Failed to get content type"); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| return mimetype == "audio/x-mpegurl"; | ||
| } | ||
|
|
||
| public File[]? get_uri_list () { | ||
| return uri_list; | ||
| } | ||
|
|
||
| public void load_playlist () requires (playlist_file != null) { | ||
| FileInputStream fis = playlist_file.read (); | ||
| DataInputStream dis = new DataInputStream (fis); | ||
| string current_line; | ||
|
|
||
| while ((current_line = dis.read_line ()) != null) { | ||
| if (current_line.ascii_down ().has_prefix ("file:///")) { | ||
| uri_list += File.new_for_uri (current_line); | ||
| } | ||
| else if (FileUtils.test (current_line, FileTest.IS_DIR)) { | ||
| uri_list += File.new_for_path (current_line); | ||
| } | ||
| else { | ||
| debug ("Unknown line: " + current_line); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void save_playlist (ListStore queue) requires (playlist_file != null) { | ||
| FileOutputStream fos = playlist_file.replace (null, false, GLib.FileCreateFlags.REPLACE_DESTINATION); | ||
| DataOutputStream dos = new DataOutputStream (fos); | ||
|
|
||
| for (uint i = 0; i < queue.n_items; i++) { | ||
| AudioObject track = (AudioObject)queue.get_item (i); | ||
| dos.put_string (track.uri); | ||
| dos.put_string ("\n"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thinking about the code more, I am curious if this should maybe live in
PlaybackManager.queue_fileand check if the playlist file is a supported type, that way anything that falls under "audio/x-mpegurl" but is not an m3u causes the invalid file toast instead of being added to the queue as a broken AudioObject?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.
audio/x-mpegurl should be m3u or m3u8
dont confuse with audio/mpeg
unless mime-type.com speaks lies, but mimetype.io seems to say the same thing
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.
Well for some reason playlist extensions of other programs (like a fake .pls file) will be visible with that filter? Maybe I shouldn't worry about it until it is actually a problem that happens with other people lol