#!/usr/bin/python3 # # Copyright (c) 2019 deathspawn aka poxifide # # deathspawn.net // poxifide.net # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # REQUIRES: gpmdp needs to be installed or this will not work! # Import the necessary modules. import os, json, time, random try: homedir = os.environ['XDG_CONFIG_HOME'] except KeyError: try: homedir = os.environ['HOME'] except KeyError: homedir = os.path.expanduser("~") jsonfile = homedir+"/.config/Google Play Music Desktop Player/json_store/playback.json" with open(jsonfile) as json_file: data = json.load(json_file) status = data["playing"] title = data["song"]["title"] artist = data["song"]["artist"] album = data["song"]["album"] rating = [data["rating"]["liked"], data["rating"]["disliked"]] time_current = data["time"]["current"] time_total = data["time"]["total"] lyrics = random.choice(data["songLyrics"].split("

")) shuffle = data["shuffle"] repeat = data["repeat"] volume = data["volume"] def convert(cur_mil, tot_mil): #current cur_sec = float(int(cur_mil) / 1000) #total tot_sec = float(int(tot_mil) / 1000) #ifs if tot_sec >= 3599: cur_out = time.strftime('%H:%M:%S', time.gmtime(cur_sec)) tot_out = time.strftime('%H:%M:%S', time.gmtime(tot_sec)) else: cur_out = time.strftime('%M:%S', time.gmtime(cur_sec)) tot_out = time.strftime('%M:%S', time.gmtime(tot_sec)) return cur_out, tot_out conversion = convert(time_current, time_total) if status == True: status = "Playing" else: status = "Paused" if rating[0] == True: rating_s = " <3 " elif rating[1] == True: rating_s = " </3 " else: rating_s = " " print("Now "+status+": "+title+" by "+artist+" ("+album+") ["+str(conversion[0])+"/"+str(conversion[1])+"] on Google Play Music ~gpmdp-np-companion~")