Splamy / TS3AudioBot

Advanced Musicbot for Teamspeak 3
https://splamy.de/TSAudioBot/Home
Open Software License 3.0
679 stars 138 forks source link

Play Playlist from Json file #627

Open marv-th opened 5 years ago

marv-th commented 5 years ago

Is it possible to play an playlist from an json url? If this isn't possible it could be an very nice feature to implement that. Thanks for ur request

Flakebi commented 5 years ago

Hm, how would you encode a playlist in json? Just a list of links? The first results on Google turn up a bunch of different formats.

marv-th commented 5 years ago

Yes. I mean you have an json syntax and this syntax can played by the bot

Splamy commented 5 years ago

That was not a yes/no question, you might want to read that again. Also I have planned to implement/support xspf and jspf (xspf in json) (see here). I think that should be be a suitable json format

marv-th commented 5 years ago

I mean an json array and in that you have following fields: url/filename, title?, cover?, id. With the id i mean, that you can specif an id for the entry and can edit or delete them.

The json array can be read by their path name or an valid url

!jsonlist read "path/url" !jsonlist start - Play, Load and Synchron the list with the bot !jsonlist stop - Stop playing the list !jsonlist repeat <on/off> - Start the Playlist again, if the last song was played. !jsonlist shuffle <on/off> - Shuffle the current playlist

An unique identifier (id) is important to set. The bot identifier the current played song and play the next song after that. If the next song is not possible the bot will be stop playing music or start it aggain if the "!jsonlist repeat" set to on. If the json file was edit the bot will be take over this automatically (before the next song will be played).

I would be try to code an plugin what exactly do this for our system (compatible with Database, ...). I would be happy if you tell me the current media stop event and give an example.

Splamy commented 5 years ago

Most of that can already be done now with the curren setup. !jsonlist read "path/url" -> !list get "path/url" !jsonlist start - !list play !jsonlist stop - !stop !jsonlist repeat <on/off> - !repeat one/off/all !jsonlist shuffle <on/off> - !shuffle on/off

the only thing that is not supported is a json format; currently supported are m3u, pls, wpl and zpl Also I don't know what you mean with id; the name already is unique

Please note that the upcomming rework for playlists will change some of that syntax

marv-th commented 5 years ago

I already know that..

First i thought its easier to handle with the id. But in this way it is not needed.

I wants to build an plugin for us, cause its easier than to connect this to an database. So can you tell me how to use the stopped after event? Maybe can give an example?

Splamy commented 5 years ago
public class NowPlaying : IBotPlugin {
    public PlayManager PlayManager { get; set; }

    public void Initialize() {
        // will be called when a song ended and the bot will try to play a new song, either from the queue or the next in the playlist
        PlayManager.BeforeResourceStopped += BeforeStop;
        // will be called when playback actually stopped
        PlayManager.AfterResourceStopped += AfterStop;
    }

    private void BeforeStop(object sender, EventArgs e) {
    }

    private void AfterStop(object sender, EventArgs e) {
    }

    public void Dispose() {
        PlayManager.BeforeResourceStopped -= BeforeStop;
        PlayManager.AfterResourceStopped -= AfterStop;
    }
}
marv-th commented 5 years ago

Thanks a lot!😃

marv-th commented 5 years ago

Is it possible, that this doesn't work anymore in the newest ts3ab version?

Splamy commented 5 years ago

Still works; have you added all namespaces?:

using System;
using TS3AudioBot;
using TS3AudioBot.Audio;
using TS3AudioBot.Plugins;
using TS3AudioBot.CommandSystem;
// ...
marv-th commented 5 years ago

problem already clarified