Skip to content
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

API endpoint for importing m3u/m3u8 playlists #2078

Closed
certuna opened this issue Jan 11, 2023 · 12 comments · Fixed by #2273
Closed

API endpoint for importing m3u/m3u8 playlists #2078

certuna opened this issue Jan 11, 2023 · 12 comments · Fixed by #2273

Comments

@certuna
Copy link
Contributor

certuna commented Jan 11, 2023

Plex has an API endpoint to upload m3u playlists, would be very practical to have in the Navidrome API too, for scripting. M3u playlist parsing is already implemented in ND so it's just a matter of exposing it in the API.

Something like /upload?path=/folder/playlist.m3u&token=3gK5s7T2p

@certuna certuna changed the title API endpoint for uploading m3u/m3u8 playlists API endpoint for importing m3u/m3u8 playlists Jan 11, 2023
@deluan
Copy link
Member

deluan commented Jan 11, 2023

Yeah, that could be added, for sure. I'm adding a good first issue label to this, as it should be a simple http handler in the Native API.

In the meantime, one could use the Subsonic API to create/update playlists: http://subsonic.org/pages/api.jsp#createPlaylist. It would require getting the songs ids first (via the search3 endpoint?)

EDIT: If anyone wants to work on this, it should be implemented as a POST to /api/playlists, with content-type = audio/x-mpegurl. Of course it would have to be an authenticated call.

@Zibbp
Copy link

Zibbp commented Jan 12, 2023

Another idea in the meantime if you're currently not using this method is to create a "playlist" folder within your music folder. I have all of my m3u8 files stored there and they get created/updated with a script. Navidrome is able to detect updates in the m3u8 file and import the new tracks.

@certuna
Copy link
Contributor Author

certuna commented Jan 13, 2023

Yeah this is the current workaround - you temporarily place the .m3u in the monitored folder, tell ND to rescan, and ND will then pick it up to import. It would just be a lot more efficient to directly feed the .m3u to ND.

@spwats
Copy link
Contributor

spwats commented Feb 10, 2023

👋 hey, I'd like to take a crack at this as a first issue!

@spwats
Copy link
Contributor

spwats commented Mar 16, 2023

Hey, sorry it's been a while but I'm finally picking this up. @deluan I'm unsure of how to implement what you're asking for. It appears that there's already a POST endpoint on /api/playlist that accepts json-encoded playlist objects. It sounds like you want this endpoint to also accept m3u8 encoded playlists. Is that correct? If so, I'm unsure of how to implement this within the context of the rest framework. I believe we would need some kind of outer-level custom handler or middleware that inspects the content-type of the POST request and then deserializes it appropriately. That feels like a lot of effort and refactoring to support this feature.
Would it perhaps make more sense to create a separate endpoint for uploading m3u8 playlists?

@deluan
Copy link
Member

deluan commented Mar 16, 2023

Hey, sorry it's been a while but I'm finally picking this up

No worries :)

It appears that there's already a POST endpoint on /api/playlist that accepts json-encoded playlist objects. It sounds like you want this endpoint to also accept m3u8 encoded playlists. Is that correct?

Exactly.

If so, I'm unsure of how to implement this within the context of the rest framework. I believe we would need some kind of outer-level custom handler or middleware that inspects the content-type of the POST request and then deserializes it appropriately. That feels like a lot of effort and refactoring to support this feature.

Not really. Let me try to explain the required changes:

  1. In native_api.go, you will need to change the mapping of the /playlist endpoint, and instead of using the helpers R() and RX(), you will write the mappings yourself, similar to what is done for the /playlist/{id}/tracks endpoint.
  2. For the Post handler, you will write a new one that calls the Playlist repository's Save if the content-type is application/json. If not you will call a method in the core.Playlists struct that needs to be created. See next step.
  3. We already have a core.Playlists.ImportFile() that receives a dir/filename as a parameter. You'll need to create a new method that receives an io.Reader and reads the m3u from it (core.Playlists.ImportReader()?). The rest of this new import function is similar to the current ImportFile.

Would it perhaps make more sense to create a separate endpoint for uploading m3u8 playlists?

No, it does not. It would make the API more fragmented than it already is.

Let me know if you have any other questions.

@spwats
Copy link
Contributor

spwats commented Mar 16, 2023

Makes sense, thanks @deluan!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Navidrome team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions github-actions bot added the stale label Sep 13, 2023
@Mihara
Copy link

Mihara commented Sep 13, 2023

This bot needs to be adjusted, there is nothing about this feature request to make it obsolete.

@github-actions github-actions bot removed the stale label Sep 14, 2023
@RubenTeixeira
Copy link

RubenTeixeira commented Oct 10, 2023

Question: Is there and endpoint to get exported (smart playlists for instance) playlists?

EDIT: Nevermind, found an answer here which serves me well.

@armadi1809
Copy link

Hello team, is this issue still open? Would like to take a shot at it. Thank you!

deluan pushed a commit that referenced this issue Nov 1, 2023
* wip: API endpoint for creating playlists from m3u files

* wip: get user id from context

* temporarily disable failing test

* custom logic for playlist route to accomodate m3u content type

* incorporate playlist parsing into existing logic in core

* re-enable test

* fix locally failing test

* Address requested changes.

* Improve ImportFile tests.

* Remove ownerID as a parameter of ImportM3U.

* Write tests for ImportM3U.

* Separate ImportM3U test into two.

* Test OwnerID and playlist Name.

---------

Co-authored-by: Sam Watson <SwatsonCodes@users.noreply.github.com>
Co-authored-by: caiocotts <caio@cotts.com.br>
Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants