parent
b2825bed3d
commit
3d0c6561a8
59
main.py
59
main.py
|
@ -2,22 +2,10 @@ 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()
|
||||
|
@ -44,29 +32,6 @@ 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)
|
||||
|
@ -156,30 +121,6 @@ if __name__ == '__main__':
|
|||
elif payload == "Random Color per LED":
|
||||
mode = 4
|
||||
|
||||
if os.path.isfile(current_path+r'/.env') == False:
|
||||
# If not create it and add content
|
||||
with open(current_path+r'/.env', 'w') as f:
|
||||
var_lines = ["SPOTIPY_CLIENT_ID = ", "SPOTIPY_CLIENT_SECRET = ", "SPOTIPY_USER_NAME = ", "SPOTIPY_REDIRECT_URI = "]
|
||||
for var_line in var_lines:
|
||||
f.write(var_line+'\n')
|
||||
print('Please fill out the variables in the .env file ( '+current_path+r'/.env )')
|
||||
exit()
|
||||
else:
|
||||
load_dotenv()
|
||||
|
||||
sp_scopes = 'user-read-currently-playing user-read-playback-state streaming user-read-email user-read-private user-read-currently-playing user-read-playback-position user-read-playback-state'
|
||||
global sp
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=sp_scopes))
|
||||
one_device_is_active = False
|
||||
for x in sp.devices()['devices']:
|
||||
if x['is_active'] == True:
|
||||
try:
|
||||
sp.start_playback(x['id'])
|
||||
except:
|
||||
pass
|
||||
one_device_is_active = True
|
||||
break
|
||||
|
||||
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||
strip.begin()
|
||||
|
||||
|
|
Loading…
Reference in New Issue