Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions .github/workflows/dart.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.
> This branch aim at rewriting orbit in python for an easier code to read and use
30 changes: 0 additions & 30 deletions analysis_options.yaml

This file was deleted.

30 changes: 0 additions & 30 deletions bin/orbit.dart

This file was deleted.

27 changes: 27 additions & 0 deletions bin/orbit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

from dotenv import load_dotenv

from lib.api import LastFM, Params
from lib.display.display_manager import DisplayManager
from lib.display.view import Interface

if __name__ == "__main__":
load_dotenv()
api_key = os.getenv("API_KEY")
assert api_key is not None, "No LastFM api key found"

displayManager = DisplayManager(
LastFM(
Params(apiKey=api_key, user="apoleon33"),
)
)

displayManager.displays.append(Interface(
LastFM(
Params(apiKey=api_key, user="apoleon33"),
)
))

while True:
displayManager.display()
66 changes: 0 additions & 66 deletions lib/api.dart

This file was deleted.

61 changes: 61 additions & 0 deletions lib/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import requests

from lib.track import Track


class Params:
apiKey: str

user: str

format: str
method: str

_totalScrobbles: int | None = None

def __init__(self, apiKey, user, format="json", method="user.getrecenttracks"):
self.apiKey = apiKey
self.user = user
self.format = format
self.method = method

def __str__(self):
return f"?api_key={self.apiKey}&method={self.method}&user={self.user}&format={self.format}"


class LastFM:
params: Params

baseUrl: str = "https://ws.audioscrobbler.com/2.0/"

totalScrobbles: str | None

def __init__(self, params: Params):
self.params = params

def _callApi(self) -> dict:
call = requests.get(f"{self.baseUrl}{self.params}").json()

if "error" in call:
raise RuntimeError(f"Error occured while fetching LastmFM's api: {call['message']}")

self._totalScrobbles = call["recenttracks"]["@attr"]["total"]

return call

def isUserNowPlaying(self) -> bool:
"""Check if the user is currently playing a track on Last.fm"""
apiCall = self._callApi()
return "@attr" in apiCall["recenttracks"]["track"][0]

def getLastTrack(self) -> Track:
"""Retrieves the most recent track played by the user."""

return Track.createFromData(self._callApi()["recenttracks"]["track"][0])

@property
def username(self): return self.params.user

@property
def totalScrobbles(self): return self.totalScrobbles if self.totalScrobbles is not None else \
self._callApi()["recenttracks"]["@attr"]["total"]
45 changes: 0 additions & 45 deletions lib/display/display.dart

This file was deleted.

32 changes: 32 additions & 0 deletions lib/display/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from abc import ABC, abstractmethod

import requests
from Pylette import extract_colors, Palette

from lib.api import LastFM


class Display(ABC):
api: LastFM

# The number of colors extracted from the album cover.
colorNumber:int = 6

def __init__(self, api: LastFM):
self.api = api

def getColorPalette(self, imageUrl:str) -> Palette:
img = requests.get(imageUrl).content
tempFile = open("temp.jpg", "wb")

tempFile.write(img)
tempFile.close()

palette = extract_colors(image='temp.jpg', palette_size=self.colorNumber)

return palette

@abstractmethod
def display(self): pass


37 changes: 0 additions & 37 deletions lib/display/display_manager.dart

This file was deleted.

Loading