Skip to content

Commit

Permalink
refactor: enum convention and circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
sacklippe committed Jun 24, 2024
1 parent 8151e00 commit 10e856c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
9 changes: 1 addition & 8 deletions musync/entity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
from enum import IntEnum

from .artist import Artist
from .origin import Origin
from .playlist import Playlist
from .track import Track
from .user import User


class Origin(IntEnum):
unknown = 0
spotify = 1
tidal = 2
8 changes: 4 additions & 4 deletions musync/entity/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

import tidalapi as tidal

from musync.entity import Origin
from musync.entity.origin import Origin


@dataclass
class Artist:
artist_id: str
name: str
origin: Origin = Origin.unknown
origin: Origin = Origin.UNKNOWN

@classmethod
def from_spotify(cls, artist: dict) -> Artist:
return cls(artist_id=artist["id"], name=artist["name"], origin=Origin.spotify)
return cls(artist_id=artist["id"], name=artist["name"], origin=Origin.SPOTIFY)

@classmethod
def from_tidal(cls, artist: tidal.Artist) -> Artist:
return cls(
artist_id="" if artist.id is None else str(artist.id),
name="" if artist.name is None else artist.name,
origin=Origin.tidal,
origin=Origin.TIDAL,
)
7 changes: 7 additions & 0 deletions musync/entity/origin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from enum import IntEnum


class Origin(IntEnum):
UNKNOWN = 0
SPOTIFY = 1
TIDAL = 2
8 changes: 4 additions & 4 deletions musync/entity/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import tidalapi as tidal

from musync.entity import Origin
from musync.entity.origin import Origin


@dataclass
Expand All @@ -13,7 +13,7 @@ class Playlist:
owner_id: str
name: str
n_tracks: int
origin: Origin = Origin.unknown
origin: Origin = Origin.UNKNOWN

@classmethod
def from_spotify(cls, playlist: dict) -> Playlist:
Expand All @@ -22,7 +22,7 @@ def from_spotify(cls, playlist: dict) -> Playlist:
owner_id=playlist["owner"]["id"],
name=playlist["name"],
n_tracks=playlist["tracks"]["total"],
origin=Origin.spotify,
origin=Origin.SPOTIFY,
)

@classmethod
Expand All @@ -36,5 +36,5 @@ def from_tidal(cls, playlist: tidal.Playlist) -> Playlist:
),
name="" if playlist.name is None else playlist.name,
n_tracks=playlist.num_tracks,
origin=Origin.tidal,
origin=Origin.TIDAL,
)
8 changes: 4 additions & 4 deletions musync/entity/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytz
import tidalapi as tidal

from musync.entity import Origin
from musync.entity.origin import Origin


@dataclass
Expand All @@ -16,7 +16,7 @@ class Track:
artist_id: str
name: str
date_added: Optional[dt] # relates to playlist, requires better structure
origin: Origin = Origin.unknown
origin: Origin = Origin.UNKNOWN

@classmethod
def from_spotify(cls, track: dict) -> Track:
Expand All @@ -31,7 +31,7 @@ def from_spotify(cls, track: dict) -> Track:
tzinfo=pytz.utc
)
),
origin=Origin.spotify,
origin=Origin.SPOTIFY,
)

@classmethod
Expand All @@ -49,5 +49,5 @@ def from_tidal(cls, track: tidal.Track) -> Track:
if track.user_date_added is None
else track.user_date_added.replace(microsecond=0)
),
origin=Origin.tidal,
origin=Origin.TIDAL,
)
8 changes: 4 additions & 4 deletions musync/entity/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

import tidalapi as tidal

from musync.entity import Origin
from musync.entity.origin import Origin


@dataclass
class User:
user_id: str
name: str
origin: Origin = Origin.unknown
origin: Origin = Origin.UNKNOWN

@classmethod
def from_spotify(cls, user: dict) -> User:
return cls(
user_id=user["id"],
name=user["display_name"],
origin=Origin.spotify,
origin=Origin.SPOTIFY,
)

@classmethod
def from_tidal(cls, user: tidal.LoggedInUser) -> User:
return cls(
user_id="" if user.id is None else str(user.id),
name="" if user.username is None else user.username,
origin=Origin.tidal,
origin=Origin.TIDAL,
)

0 comments on commit 10e856c

Please sign in to comment.