Created
June 14, 2020 11:32
-
-
Save ScuttleSE/3e27c899dacf845ddee2d8b795177c37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import mpd | |
import random | |
import time | |
import sys | |
import os | |
pidfile = '/tmp/autoplaylist.pid' | |
host = '192.168.0.46' | |
port = 6600 | |
bannedfile = '/home/scuttle/.ncmpcpp/Banned.mpdfiles' | |
max_length = 10 | |
pid = str(os.getpid()) | |
pfile = open(pidfile, 'w').write(pid) | |
client = mpd.MPDClient() | |
playlistfile = str(sys.argv[1]) | |
with open(playlistfile) as f: | |
playlist = f.readlines() | |
client.connect(host, port) | |
while True: | |
playlistlength = int(client.status()['playlistlength']) | |
if playlistlength < max_length: | |
songadded = 0 | |
with open(bannedfile) as f: | |
bannedlist = [line.rstrip() for line in f] | |
while songadded == 0: | |
song = random.choice(playlist).rstrip() | |
if song not in bannedlist: | |
client.add(song) | |
playlistlength = playlistlength + 1 | |
songadded = 1 | |
else: | |
print('Tried to add banned!') | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment