#Playlist Folder Sync
1 messages · Page 1 of 1 (latest)
I made a macro that does just this ```js
let p = game.playlists.getName("Ambience Folder");
const soundsList = await FilePicker.browse("data", "dragupload/uploaded/ambient/");
let sounds = soundsList.files;
for (let s of p.data.sounds) {
if (sounds.includes(s.path)){
var index = sounds.indexOf(s.path);
if (index !== -1) {
sounds.splice(index, 1);
}
}
}
let soundsToAdd = sounds.map(s => {return {name: decodeURIComponent(s).replace(soundsList.target, ''), path: s , repeat: true, volume: 0.03}});
await p.createEmbeddedDocuments("PlaylistSound", soundsToAdd);
@cursive musk
Oh very cool, I need to try this out. Thank you
this works well, thank you very much @obtuse mulch. Is there any way to modify it so that the name of the song when added is just the filename and doesn't include the folder that it's in?
actually, it doesn't look like it deletes removed songs (which is probably a pretty niche functionality) but it does add new ones
I probably should rewrite it to sync rather than just add to prevent there being unplayable sounds
this bit should prevent the directory from being in the name
it does for me
i basically only know enough about macros to run this and change the folder location and playlist name
post your changed code and screenshot the result in your playlist tab
const soundsList = await FilePicker.browse("data", "audio/sci fi ambient/");
let sounds = soundsList.files;
for (let s of p.data.sounds) {
if (sounds.includes(s.path)){
var index = sounds.indexOf(s.path);
if (index !== -1) {
sounds.splice(index, 1);
}
}
}
let soundsToAdd = sounds.map(s => {return {name: decodeURIComponent(s).replace(soundsList.target, ''), path: s , repeat: true, volume: 0.03}});
await p.createEmbeddedDocuments("PlaylistSound", soundsToAdd);```
spaces in your target ```js
let p = game.playlists.getName("Scifi Ambience");
await p.deleteEmbeddedDocuments("PlaylistSound", p.sounds.contents.map(s=>s.id));
const soundsList = await FilePicker.browse("data", "audio/sci fi ambient/");
let soundsToAdd = soundsList.files.map(s => {return {name: decodeURIComponent(s).replace(decodeURIComponent(soundsList.target), ''), path: s , repeat: true, volume: 0.03}});
await p.createEmbeddedDocuments("PlaylistSound", soundsToAdd);
this will clear the playlist and re-add everything and do the replace properly
Thank you very much. I'll have to try this version out when I get home from work
it's working well. thanks again.