Created
February 20, 2021 01:17
-
-
Save ssssssssk/47dad4633050282861e5ff852dbda7a4 to your computer and use it in GitHub Desktop.
Shuffles and plays one play list for focus sessions and then pauses that playback and then shuffles and plays another playlist for break times. When it's time to focus again the playlist from before resumes.
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
import time | |
from mpd import MPDClient | |
from subprocess import Popen, PIPE | |
import os | |
# Create MPD Client | |
client = MPDClient() | |
client.timeout = 10 | |
client.idletimeout = None | |
# Connect to client and set details | |
client.connect("SERVERNAME", 6600) | |
client.random(0) | |
client.repeat(0) | |
client.consume(1) | |
client.clear() | |
# Get the list of playlists | |
playlists = client.listplaylists() | |
# class for each pomodoro section. Takes section name, playlist and time (in secs) | |
class section: | |
def __init__(self, n, pl, t): | |
self.name = n | |
self.playlist = pl | |
self.time = t | |
if not any(d['playlist'] == self.name for d in playlists): | |
pass | |
else: | |
client.rm(self.name) | |
client.load(self.playlist) | |
client.shuffle() | |
client.save(self.name) | |
client.clear() | |
self.restart_time = 0 | |
def function(self): | |
# restart time is gathered when the playlist stops. | |
global client | |
client.clear() | |
client.load(self.name) | |
global restart_time | |
if self.restart_time == 0: | |
client.play() | |
else: | |
client.play() | |
client.seekcur(self.restart_time) | |
client.rm(self.name) | |
countdown = self.time | |
## Fancy Version Using TermDown for Display | |
# os.system(f"termdown {countdown} -T '{self.name}' -f poison && echo 'Break over'") | |
while countdown: | |
mins, secs = divmod(countdown, 60) | |
timer = '{:02d}:{:02d}'.format(mins, secs) | |
on_now = client.currentsong() | |
artist = on_now.get('artist') | |
title = on_now.get('title') | |
rows, columns = os.popen('stty size', 'r').read().split() | |
#print((self.name, timer, artist, " - ", title).center(80, '%') ) | |
## | |
# print(self.name, timer, artist, " - ", title, end="\r") | |
## Fancy Single Line Display | |
info_display = ' {0} {1} {2} - {3} '.format(self.name, timer, artist, title) | |
screenW = (int(columns)) | |
print(info_display.center(screenW, '%'), end='\r') | |
time.sleep(1) | |
countdown -= 1 | |
last_point = client.status() | |
self.restart_time = last_point.get('elapsed') | |
client.pause() | |
client.save(self.name) | |
focus = section("Work", "Zoner", 1500) | |
pause = section("Relax", "Party", 300) | |
while True: | |
focus.function() | |
pause.function() | |
# TO DO accept keyboard input anywhere in the process, make an ncurses or whiptail interface so that I can watch the timer happen. ALTERNATIVELY: find some way to use termdown to make display nice. However, it's really hard to exit when termdown is running. Would be good to fade down audio before segment ends. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment