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

[radio@driglu4it] Add option to parse custom metadata sources #6581

Open
oleole39 opened this issue Nov 18, 2024 · 5 comments
Open

[radio@driglu4it] Add option to parse custom metadata sources #6581

oleole39 opened this issue Nov 18, 2024 · 5 comments

Comments

@oleole39
Copy link

Applet name and maintainer

radio@driglu4it

What would you like to see?

Hello @jonath92 ,

Suffering from using audio streams in which the applet does not find title metadata (e.g: https://stream.radiofrance.fr/fip/fip_hifi.m3u8), I am looking for a way in such case to indicate a JSON metadata source to the applet for that stream so that it can parse it (e.g. https://www.radiofrance.fr/fip/api/live at { "now": {"firstLine": {"title": SONG_TITLE} } }).

  1. Would you consider a PR for this ?
  2. Would you have a preferred way for implementing this ?
    1. I am thinking to add a fourth column to the "My Stations" that could be "Metadata URL" (default value could be an empty value or string "embedded").
    2. I am still unsure on which basis querying the JSON file - how and where to have the user indicate the JSON path in a simple way?
    3. Then I guess the parsing should happen in src/services/mpv/MpvHandler.ts. Should the parsing function be added as well to files/radio%40driglu4it/4.6/radio-applet.js ?
  3. Should we add cover art support ({ "now": {"visuals": {"card": {"src": COVER_ART_URL} } } }) in addition as an option?

Best regards,
oleole39

@jonath92
Copy link
Contributor

jonath92 commented Nov 18, 2024

1.Would you consider a PR for this ?

Yes. I am happy to support you, but you should be aware that it is not an easy task to implement.

I am still unsure on which basis querying the JSON file - how and where to have the user indicate the JSON path in a simple way?

Yes that is a tricky part .I don't think it's feasible to realize this for the user in a simple way without an enormous maintenance effort. When you implement a simple way for a json, than the next user wants a simple way for xml and so on. Also some users might want to combine several fields from a json. What I would do instead is, to allow the users to add a bash script which returns the title. Than you call the bash script in the code eyery 5 seconds or so. For this example, you could add a bashcript with:

curl "https://www.radiofrance.fr/fip/api/live" | jq ".now.secondLine.title" 

Then I guess the parsing should happen in src/services/mpv/MpvHandler.ts.

No, I don't think this is the right place because this is not related to Mpv. But you can start adding it here and than later on we can discuss how to improve.

Should the parsing function be added as well to files/radio%40driglu4it/4.6/radio-applet.js ?

Yes, the javascript file is what is used from cinnamon. Typescript is just add an addition to js. But you can build the js file by running: npm install and npm run build within the radio applet directory

Should we add cover art support ({ "now": {"visuals": {"card": {"src": COVER_ART_URL} } } }) in addition as an option?

That is something you can think about later. But this is very,very complicated and I don't think it makes sense to implement at the moment.

@oleole39
Copy link
Author

oleole39 commented Nov 18, 2024

Thanks for your feedback.

What I would do instead is, to allow the users to add a bash script which returns the title.

So one .sh file per station in a folder ? That could be an option, but thinking more about it, as a user I'd probably like better something like a 5th column in the "My Stations" DB:

  • as mentioned earlier the 4th column would be the JSON file URL (e.g. https://www.radiofrance.fr/fip/api/live)
  • the 5th column would be the JSON path in such way {.now.firstLine.title} - {.now.secondLine.title} (or maybe without curly braces). Or maybe even one column for each variable: title path, album path, year path, cover art path to be filled with a string of this format: .now.firstLine.title. Then it won't be so difficult to parse the expression and replace the JSON paths with their values using curl & jq as you suggested.

How do you feel about this way?

We could even imagine a way for users to propose their JSON file URL & JSON Path entries to the central radio file by submitting a PR (adding column to those too). However that would be a second step because format of allStations.json may not be so convenient for easy collaborative editing.

Than you call the bash script in the code eyery 5 seconds or so.

I am under the impression that currently the title change when listening to a same station is triggered inside activateMprisPropsListener() in MpvHandler.ts (hence why I thought about adding my functions there, but you are right it is not directly related with mpv). But I don't get what is the actual trigger - something related to connectSignal method that I have not identified ?

@oleole39 oleole39 changed the title Applet Feature Request - Add option to parse custom metadata sources [radio@driglu4it] Add option to parse custom metadata sources Nov 19, 2024
@jonath92
Copy link
Contributor

Hi, sorry for not answering before. I currently don`t have much time. I would says, start coding and once we have a first working Version we can discuss how to improve

@oleole39
Copy link
Author

oleole39 commented Nov 20, 2024

Nothing too urgent, but that would help if you were able to find time to answer the last question of my last message

@jonath92
Copy link
Contributor

jonath92 commented Nov 24, 2024

I am under the impression that currently the title change when listening to a same station is triggered inside activateMprisPropsListener() in MpvHandler.ts (hence why I thought about adding my functions there, but you are right it is not directly related with mpv). But I don't get what is the actual trigger - something related to connectSignal method that I have not identified ?

Ok I have reviewed it now. In the function activateMprisPropsListener we are passing an anonymous callback function ( (proxy, nameOwner, [interfaceName, props]) => {...}. The activateMprisPropsListener function is only called when mpris starts or at the start of the applet. The annoymous callback function is always triggered when a title is changed in the mpv player. The mpv player knows when a title changed when a station set a new title via the mpris standard. Then the mpv player sends this signal via dbus to all listeners e.g. the applet. I am no dbus expert and I don't know exactly how it is working but for us it is only important that the method is called when a title changes in mpris metadata.

But as you want to parse metadata when no metadata are already provided, this is definitely the wrong place. As the radio title is used in multiple places of the applet (in the tooltip, in the popup menu, for the youtube download... and maybe more), I would suggest to provide it first at one place and test that it is working and than also add it to the other place. E.g you could change something in the "createRadioAppletTooltip" function and play around there and test if it is working. Once it is working you can think about how to make it available everywhere. Here you need to provide a function which fetches and parses a json every 5 seconds or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants