mirror of
https://github.com/shadoll/playing_now_2_mm.git
synced 2026-02-04 11:03:23 +00:00
initial commit
This commit is contained in:
17
connectors/apple_music.py
Normal file
17
connectors/apple_music.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from appscript import app # type: ignore
|
||||
|
||||
class AppleMusic:
|
||||
def __init__(self):
|
||||
self.music_app = app("Music")
|
||||
|
||||
def get_current_track_info(self) -> tuple:
|
||||
try:
|
||||
current_track = self.music_app.current_track.get()
|
||||
return (
|
||||
current_track.name.get(),
|
||||
current_track.artist.get(),
|
||||
current_track.duration.get(),
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Failed to get current track info: {e}")
|
||||
return None, None, None
|
||||
17
connectors/spotify.py
Normal file
17
connectors/spotify.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import osascript # type: ignore
|
||||
|
||||
class Spotify:
|
||||
def get_current_track_info(self) -> tuple:
|
||||
try:
|
||||
name_code = 'tell application "Spotify" to name of current track as string'
|
||||
artist_code = 'tell application "Spotify" to artist of current track as string'
|
||||
duration_code = 'tell application "Spotify" to duration of current track as string'
|
||||
|
||||
name = osascript.osascript(name_code)[1]
|
||||
artist = osascript.osascript(artist_code)[1]
|
||||
duration = int(osascript.osascript(duration_code)[1]) / 1000 # Convert duration from ms to s
|
||||
|
||||
return name, artist, duration
|
||||
except Exception as e:
|
||||
print(f"Failed to get current track info: {e}")
|
||||
return None, None, None
|
||||
Reference in New Issue
Block a user