diff --git a/.cache b/.cache index 46e333b..c2c3a99 100644 --- a/.cache +++ b/.cache @@ -1 +1 @@ -{"access_token": "BQALcKusPjd5akQ3U_q5i2tQANIonOR6yv-Ec9WtGBjeip5n22b82jJQRzLHhDxQI8bztKCyuqHmiiY_gA3NUqANrbqZ2ei5cG1DySXnsMIQePD__mvGikehGbfBPHJkmKTTMk2xx56jiN9Xrg2JAtjSnTxckhgT5xqxyKbpZBvQIKEsX14VIDeGgA0ZvRxmrA9n0y67bWer5Lr411k", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1686382188, "refresh_token": "AQAby3zEGc-H8o8zciCRMZm-O6Gj3FAup6Vb0sRrbtiO48VyMTJMzU4DoJ_wrhk8LmOiN8Hvt0Fb_Ag-09XVEDgQe3VUBDD3HdoMk6aZA1n02VLygxQNMNUQgAGw6oUUdI0"} \ No newline at end of file +{"access_token": "BQDochOG-kBM3GV43moO6zgHlLbsleUy9lT5bYHi1bMBm621i-8AMWUjRDimSFAC2bUaRbh-Qv-5DA2DwwT8_hfT93s6CB1kivAESd8q7teETG2wfFFfWSv-bKvyZu5FNvDK8ofekKNy-pYwiKxeUhYuqnpMB2l0-R1ysKkkUgeqiAH3bIXrCn2HaZeya7_zrbA5uN97R38BaE22DIE", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1689301138, "refresh_token": "AQAby3zEGc-H8o8zciCRMZm-O6Gj3FAup6Vb0sRrbtiO48VyMTJMzU4DoJ_wrhk8LmOiN8Hvt0Fb_Ag-09XVEDgQe3VUBDD3HdoMk6aZA1n02VLygxQNMNUQgAGw6oUUdI0"} \ No newline at end of file diff --git a/README.md b/README.md index 3d90060..446c3cd 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ Control Spotify remotely with a nice and functional touchscreen interface ## Running - Get a Spotify API Client ID and Secret from the [Spotify Developer Dashboard](https://developer.spotify.com/). Put these in the config.json file. -- Clone the repository +- Install required dependencies ```sh pip install -r requirements.txt ``` -- Configure the env variables +- Run ```sh python spotifycontroller.py ``` diff --git a/_notify.py b/_notify.py new file mode 100644 index 0000000..06f60b9 --- /dev/null +++ b/_notify.py @@ -0,0 +1,30 @@ +import tkinter as ttk +from tkinter import ttk as tk +from tkinter import PhotoImage +import os +import sv_ttk + +def draw(cid, num, img, title="Notification"): + root = ttk.Tk() + root.title(title) + root.geometry("1280x50") + root.attributes("-topmost", True) + if os.name == 'posix': + root.overrideredirect(1) + try: + sv_ttk.use_dark_theme() + except: + pass + + phone = PhotoImage(file=img) + phone_image = tk.Label(root, image=phone) + cid_label = tk.Label(root, text=cid, font=("Arial", 32)) + num_label = tk.Label(root, text=num, font=("Arial", 32)) + + phone_image.grid(row=0, column=0, padx=10) + cid_label.grid(row=0, column=1, padx=10) + num_label.grid(row=0, column=2, padx=10) + + root.after(15000, lambda: root.destroy()) + + root.mainloop() \ No newline at end of file diff --git a/freepbx.py b/freepbx.py new file mode 100644 index 0000000..f327ec7 --- /dev/null +++ b/freepbx.py @@ -0,0 +1,24 @@ +from flask import Flask, request +import threading +from _notify import draw + +app = Flask(__name__) + +@app.route('/hook', methods=['GET']) +def wait_for_call(): + # Get information from URL variables + num = request.args.get('num') + cid = request.args.get('CID') + img = "phone.png" + + # Process the received information (you can customize this part) + print(f"Received param1: {num}") + print(f"Received param2: {cid}") + # Add more processing logic as needed + threading.Thread(target=draw, args=(cid, num, img)).start() + + # Respond to the webhook request (optional) + return 'Webhook received successfully!', 200 + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) \ No newline at end of file diff --git a/phone.png b/phone.png new file mode 100644 index 0000000..dc25ea8 Binary files /dev/null and b/phone.png differ diff --git a/phone_orig.png b/phone_orig.png new file mode 100644 index 0000000..8e8b023 Binary files /dev/null and b/phone_orig.png differ diff --git a/spotifycontroller.py b/spotifycontroller.py index a3665e8..4d50427 100644 --- a/spotifycontroller.py +++ b/spotifycontroller.py @@ -210,26 +210,29 @@ def get_devices(): # unloadDevices_list() # loadSleep() # root.after(3600, get_devices) - if spotify.current_playback() != None: - count = 0 - # unloadSearching_Devices() - unloadDevices_list() - loadNow_playing() - root.after(800, update_song_label) - else: - count += 1 - if count > 420: - kill(kill=sleep) - # unloadSearching_Devices() - # loadDevices_list() + try: + if spotify.current_playback() != None: + count = 0 + # unloadSearching_Devices() + unloadDevices_list() + loadNow_playing() + root.after(800, update_song_label) else: - devices_list.delete(0, ttk.END) - list_of_devices = spotify.devices() - for num_of_device, garbage in enumerate(list_of_devices["devices"]): - # exec(f'dev_{num_of_device} = tk.Button(root, text=list_of_devices["devices"][num_of_device]["name"], command=start_playback_on_device(device_id=num_of_device))') - # exec(f'dev_{num_of_device}.grid(row={num_of_device}, column=1)') - devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"]) - root.after(8500, get_devices) + count += 1 + if count > 420: + kill(kill=sleep) + # unloadSearching_Devices() + # loadDevices_list() + else: + devices_list.delete(0, ttk.END) + list_of_devices = spotify.devices() + for num_of_device, garbage in enumerate(list_of_devices["devices"]): + # exec(f'dev_{num_of_device} = tk.Button(root, text=list_of_devices["devices"][num_of_device]["name"], command=start_playback_on_device(device_id=num_of_device))') + # exec(f'dev_{num_of_device}.grid(row={num_of_device}, column=1)') + devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"]) + root.after(8500, get_devices) + except: + root.after(5000, get_devices) # def wakeup(): # global count @@ -563,6 +566,7 @@ def unloadNow_playing(): song_label.grid_forget() previous_button.grid_forget() play_button.grid_forget() + pause_button.grid_forget() next_button.grid_forget() progress_bar.grid_forget() lyrics_label.grid_forget() diff --git a/update.py b/update.py index c8689de..dc5bc6a 100644 --- a/update.py +++ b/update.py @@ -6,7 +6,8 @@ from time import sleep import subprocess from pynput import mouse from functools import partial -from os import name, path, remove, system +from os import name, path, remove, system, kill, popen +import signal # while True: @@ -53,7 +54,16 @@ while True: except urllib.error.HTTPError: print("No update available.") pass + for line in popen("ps ax | grep " + "web.py" + " | grep -v grep"): + fields = line.split() + pid = fields[0] + kill(int(pid), signal.SIGKILL) subprocess.Popen(['python3', 'web/web.py']) + for line in popen("ps ax | grep " + "freepbx.py" + " | grep -v grep"): + fields = line.split() + pid = fields[0] + kill(int(pid), signal.SIGKILL) + subprocess.Popen(['python3', 'freepbx.py']) subprocess.check_call(['python3', 'spotifycontroller.py']) except Exception as e: if e.args[0] == 1: diff --git a/update.zip b/update.zip new file mode 100644 index 0000000..95ec7c6 Binary files /dev/null and b/update.zip differ