• TeamSpeak has reported a vulnerability in it's client that can potentially lead to RCE. A new version has been released that fixes it. So please update the client in your bot installation as soon as possible as well. Click here for more information.
  • If you need help or want to discuss things, you now can also join us on our Discord Server!

EN [Outdated][Python] Add all of your sinusbot files into a playlist

Wippinho

Member
Hey!

This was just a workaround and a little playing from 2 years ago. i'll keep this up as reference.



Background:

Sinusbot had a feature some time ago where the bot would just autoplay the "all music" playlist if there were no playlist and/or shuffle was enabled.
(GER thread: https://forum.sinusbot.com/threads/nach-play-keine-wiedergabe.648/)

Since the feature hasn't made it back(I haven't seen it documented) I've created an "All music" playlist by myself as a workaround.
But this was quite a hassle since me and my friends upload a lot of music - so I've decided to develop a little python script which can help me with that.


Technical:
Everything in sinusbot is stored in a SQLite Database. You can find your personal bot database in <sinusbotdir>/data/db/{bot-uuid}.sqlite

You can download this file and open it with a tool like SQLite browser.
Take a look at your beautiful bot database!
(You should never upload this because it contains everything about your bot!)

Since SQL is quite easy - we can take a look at the structure and use this to our advantage!

Lets do this:
Create a new, empty playlist.
Shutdown your bot.

Download your database and put it in a folder.
Open your database with any SQLite browser and find the UUID of your playlist in the table 'playlists'.

Save this python script into the same folder as your sqlite database.
Code:
#This script is written in python2.7
import sqlite3

#the ID of your created playlist in the table 'playlists'
playlist_id = '<playlist-uuid>'

# Example for the next line: conn = sqlite3.connect('84d08941-0d15-42cc-8aab-826fb7d00000.sqlite')
conn = sqlite3.connect('<name of your sqlite file in the same folder>')
c = conn.cursor()

i = 0
for row in c.execute('SELECT * FROM files').fetchall():

    #I've seen just these 2 filetypes - so we'll distinct them
    if row[7] == 'url':
        url = 'url://'+row[0]
    else:
        url = 'track://'+row[0]  
    c.execute('INSERT INTO playlists_files(playlist, file, url, position) VALUES (?,?,?,?)',[playlist_id, row[0], url, i])
    i = i+1
conn.commit()
Now insert your data into the placeholders inside the script and run it once.
It'll insert all of your files into your newly generated playlist.
Upload your database and put it back into the folder.
Make sure so change the user and group back to your bot-user if you're on linux.


After you restart your bot you should have a playlist with all of your currently uploaded files in a playlist.

Notes:

I've chosen python because it offers an easy way to mess with sqlite - you could to this with any programming language (or even in SQL itself?)

If you've run it twice you can delete everything easily from your database, since you have the playlistId.

Writing this up took longer to write than the script - it is quick and dirty, but it fits my needs.

Almost everything in this bot is available via a REST-API. You should really use the API provided by the bot to create your applications - unless you know what you're doing.


Greetings,

Wippinho
 
Last edited:

flyth

is reticulating splines
Staff member
Developer
Contributor
Just a short notice, will have a deeper look later on. The feature you are talking about is now available as a play button at the top of the directory view. It's however missing as a command, which I will readd soon :)
 

Wippinho

Member
Yeah I've seen the button - but after every !yt or !ytdl the bot just went quiet.
And instead of keeping the browser to press the button, the workaround is fine for me. :)
 

nhOmega

Member
Added 1 line to this to get it to work for me.
Code:
conn.text_factory = str
Code:
#This script is written in python2.7
import sqlite3

#the ID of your created playlist in the table 'playlists'
playlist_id = '<playlist-uuid>'

# Example for the next line: conn = sqlite3.connect('84d08941-0d15-42cc-8aab-826fb7d00000.sqlite')
conn = sqlite3.connect('<name of your sqlite file in the same folder>')
# Use this to avoid issues with UTF-8 rows
conn.text_factory = str
c = conn.cursor()

i = 0
for row in c.execute('SELECT * FROM files').fetchall():

    #I've seen just these 2 filetypes - so we'll distinct them
    if row[7] == 'url':
        url = 'url://'+row[0]
    else:
        url = 'track://'+row[0] 
    c.execute('INSERT INTO playlists_files(playlist, file, url, position) VALUES (?,?,?,?)',[playlist_id, row[0], url, i])
    i = i+1
conn.commit()
 

Similar threads

Top