added the stuff that is needed for spotify sync

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-27 15:42:04 +02:00
parent 7c55166e32
commit b64d7789b8
2 changed files with 40 additions and 0 deletions

35
main.py
View File

@ -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)

View File

@ -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