From b64d7789b88eb004e08fd3718c33ea5f126e2996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Wed, 27 Jul 2022 15:42:04 +0200 Subject: [PATCH] added the stuff that is needed for spotify sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 35 +++++++++++++++++++++++++++++++++++ requirements.txt | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/main.py b/main.py index 3e132ed..12f2221 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,22 @@ from base64 import b16decode import time from datetime import datetime from random import * +from ctypes.wintypes import VARIANT_BOOL +from multiprocessing.spawn import old_main_modules +import os +from unicodedata import decimal +import requests +current_path = os.path.dirname(os.path.abspath(__file__)) try: from rpi_ws281x import * import RPi.GPIO as GPIO import paho.mqtt.client as mqtt + import spotipy + import urllib.request + import colorgram + import numpy as np + from PIL import Image + from dotenv import load_dotenv except ImportError: print('Some modules are missing. Try to install them with "pip3 install -r requirements.txt"') exit() @@ -32,6 +44,29 @@ def debug_print(message: str): current_time = now.strftime("%H:%M:%S") print('[DEBUG]['+current_time+'] '+message) +def convertColor(hexCode): + R = int(hexCode[:2],16) + G = int(hexCode[2:4],16) + B = int(hexCode[4:6],16) + total = R + G + B + if R == 0: + firstPos = 0 + else: + firstPos = R / total + if G == 0: + secondPos = 0 + else: + secondPos = G / total + return [firstPos, secondPos] + +def getRandomHex(): + return "%06x" % random.randint(0, 0xFFFFFF) + +def extract_colors(url, n=4): + urllib.request.urlretrieve(url, current_path+r"/cover.jpg") + img = current_path+r"/cover.jpg" + return colorgram.extract(img, n) + def wheel(pos): if pos < 85: return Color(pos * 3, 255 - pos * 3, 0) diff --git a/requirements.txt b/requirements.txt index 43e9b6d..829f954 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,7 @@ +numpy==1.23.1 paho_mqtt==1.6.1 +Pillow==9.2.0 +python-dotenv==0.20.0 +requests==2.28.1 rpi_ws281x==4.3.4 +spotipy==2.20.0