Skip to content

Commit

Permalink
fix dominant_color
Browse files Browse the repository at this point in the history
  • Loading branch information
teticio committed Nov 22, 2024
1 parent cea830d commit 98c599b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,15 @@ async def make_playlist_widget(track_ids, waypoints='[]', playlist_id=''):
except aiohttp.ClientError as error:
raise HTTPException(status_code=400, detail=str(error)) from error
image_url = re.findall(r'(https://[^/]*/image/[a-z0-9]*)', text)[0]
dominant_color = re.findall(r'"backgroundColor":"(#[A-F0-9]{1,6})"', text)
dominant_color = dominant_color[0] if len(dominant_color) > 0 else '#000000'
dominant_color = re.findall(
r'"backgroundBase":\{"alpha":(\d+),"blue":(\d+),"green":(\d+),"red":(\d+)\}',
text,
)
if len(dominant_color) > 0:
_, blue, green, red = map(int, dominant_color[0])
dominant_color = f"#{red:02X}{green:02X}{blue:02X}"
else:
dominant_color = '#000000'
text = playlist_widget
soup = BeautifulSoup(text, 'html.parser')
tag = soup.find(id="resource")
Expand Down

0 comments on commit 98c599b

Please sign in to comment.