3 Commits
Author SHA1 Message Date
nutty 2a6a0bdc29 Merge branch 'main' of https://github.com/nuttylmao/smtc-bridge 2026-09-01 15:54:20 +10:00
nutty 5f2a103513 Final cleaup - updated to v1.0.0 2026-09-01 15:54:18 +10:00
nutty 91e4e81a6c Update README.md 2026-08-27 11:36:18 +10:00
2 changed files with 46 additions and 42 deletions
+2 -2
View File
@@ -8,10 +8,10 @@ Simply run the application, and a local web server will run in the background. B
[http://127.0.0.1:5000/now-playing/](http://127.0.0.1:5000/now-playing/) [http://127.0.0.1:5000/now-playing/](http://127.0.0.1:5000/now-playing/)
A ready-to-use "Now Playing" widget utilizing SMTC Bridge is available to try here:<br> A ready-to-use "Now Playing" widget utilizing SMTC Bridge is available to try here:<br>
**[IF YOU FOUND THIS PAGE EARLY, DON'T SHARE IT WITH ANYONE YET OR I'LL FUCKING CUM](https://widgets.nutty.gg/now-playing/settings/)** **[https://widgets.nutty.gg/now-playing/settings/](https://widgets.nutty.gg/now-playing/settings/)**
## Quick Start ## Quick Start
1. Download the latest `.exe` from the [Releases page](releases). 1. Download the latest `.exe` from the [Releases page](https://github.com/nuttylmao/smtc-bridge/releases).
2. Run the application — a tray icon will appear. 2. Run the application — a tray icon will appear.
3. Right-click the icon to view the API. 3. Right-click the icon to view the API.
+44 -40
View File
@@ -1,15 +1,43 @@
# Versioning # Versioning
APP_VERSION = "0.0.6" APP_VERSION = "1.0.0"
DEVELOPER = "nutty" DEVELOPER = "nutty"
# IMPORTANT SHIT STARTS HERE ###############
### IMPORTS ###
###############
import sys
import traceback
import os
import datetime import datetime
import traceback
import asyncio
import json
import base64
import threading
import os
import sys
import psutil
import tempfile
import atexit
import pystray
import webbrowser
import configparser
import time
import platform
import socket
import hashlib
from PIL import Image
from flask import Flask, jsonify
from flask_cors import CORS
from winsdk.windows.media.control import GlobalSystemMediaTransportControlsSessionManager as SMTC
from winsdk.windows.storage.streams import DataReader
from plyer import notification
import winsdk._winrt as winrt
from collections import OrderedDict
# IMPORTANT SHIT STARTS HERE
def log_crash(e): def log_crash(e):
# 1. Ensure the 'logs' folder exists # 1. Ensure the 'logs' folder exists
@@ -44,37 +72,6 @@ def log_crash(e):
pass # Ignore errors if file is locked or already gone pass # Ignore errors if file is locked or already gone
try: try:
###############
### IMPORTS ###
###############
import asyncio
import json
import base64
import io
import threading
import os
import sys
import psutil
import tempfile
import atexit
import pystray
import webbrowser
import configparser
import time
import platform
import socket
from PIL import Image
from flask import Flask, jsonify
from flask_cors import CORS
from winsdk.windows.media.control import GlobalSystemMediaTransportControlsSessionManager as SMTC
from winsdk.windows.storage.streams import DataReader
from plyer import notification
import winsdk._winrt as winrt
############################# #############################
### SINGLE INSTANCE CHECK ### ### SINGLE INSTANCE CHECK ###
############################# #############################
@@ -177,7 +174,10 @@ try:
smtc_manager = None smtc_manager = None
last_execution_time = 0.0 last_execution_time = 0.0
last_payload = None last_payload = None
thumb_cache = {}
# Thumbnail cache to avoid reprocessing the same artwork repeatedly
MAX_CACHE_SIZE = 50 # Maximum number of unique thumbnails to cache
thumb_cache = OrderedDict()
async def get_all_media_info(): async def get_all_media_info():
try: try:
@@ -330,15 +330,14 @@ try:
buffer = bytearray(stream.size) buffer = bytearray(stream.size)
reader.read_bytes(buffer) reader.read_bytes(buffer)
import hashlib
import base64
# Hash the raw bytes to see if the artwork is unique # Hash the raw bytes to see if the artwork is unique
img_hash = hashlib.md5(buffer).hexdigest() img_hash = hashlib.md5(buffer).hexdigest()
# If we've already processed this exact image bytes, grab it from cache instantly # If we've already processed this exact image bytes, grab it from cache instantly
if img_hash in thumb_cache: if img_hash in thumb_cache:
thumb_cache.move_to_end(img_hash)
thumb_url = thumb_cache[img_hash] thumb_url = thumb_cache[img_hash]
# print(f"Using cached artwork for: {media_data['Artist']} - {media_data['Title']}")
else: else:
print(f"Processing new artwork for: {media_data['Artist']} - {media_data['Title']}") print(f"Processing new artwork for: {media_data['Artist']} - {media_data['Title']}")
@@ -349,6 +348,11 @@ try:
# Store it in the cache so we never process it again for this track # Store it in the cache so we never process it again for this track
thumb_cache[img_hash] = thumb_url thumb_cache[img_hash] = thumb_url
# If the cache is full, remove the least recently used item
if len(thumb_cache) > MAX_CACHE_SIZE:
thumb_cache.popitem(last=False)
print(f"Removed least recently used artwork from cache. Current cache size: {len(thumb_cache)}")
except Exception as e: except Exception as e:
thumb_url = None thumb_url = None