Search code examples
pythonkodi

Python code to create playlist from multiple folders


This is my first ever question on Stack Overflow, I am terribly sorry if this has been repeated. I have been searching for the last month or so for some code, to create a random playlist that would run each night on my Raspberry Pi (Raspbian) using Python. But have had no luck!

The playlist would be made up of content from 2 folders. Music in 1 (about 200 files) Ads/Jingles (5 files) in the other. I want to be able to create a playlist (m3u format) that would randomize the music each day but still have an ad/jingle playing every 5 songs. So the only thing that should repeat each day is the ads/jingles.

I am currently running Kodi for the music player, as I want movies as well.

Is there anyone that would be able to help me with this?


Solution

  • For others wanting to do this, I found a good way around it using bash. Got this from: https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=63568

    #!/bin/bash
    if [ -f /home/pi/music.lock ]; then
    echo "Lock Exists, exiting"
    exit 0
    fi
    touch /home/pi/music.lock
    target="21"
    cur=$(date '+%H')
    while [ $target != $cur ]
    do
    cd /home/pi/music
    mpg321 "$(ls *.mp3 | shuf -n1)"
    mpg321 "$(ls *.mp3 | shuf -n1)"
    mpg321 "$(ls *.mp3 | shuf -n1)"
    mpg321 "$(ls *.mp3 | shuf -n1)"
    mpg321 "$(ls *.mp3 | shuf -n1)"
    cd /home/pi/messages
    mpg321 "$(ls *.mp3 | shuf -n1)"
    cur=$(date '+%H')
    done
    rm /home/pi/music.lock