aboutsummaryrefslogtreecommitdiff
path: root/code/custom_sources.py
diff options
context:
space:
mode:
Diffstat (limited to 'code/custom_sources.py')
-rw-r--r--code/custom_sources.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/code/custom_sources.py b/code/custom_sources.py
index 400c645..96ae3a9 100644
--- a/code/custom_sources.py
+++ b/code/custom_sources.py
@@ -122,3 +122,82 @@ class SpotifySource(Source):
)
return LoadResult(LoadType.PLAYLIST, tracks, playlist_info=PlaylistInfo.none())
+
+
+"""
+Custom Source for Apple Music links
+"""
+
+
+class AppleSource(Source):
+ def __init__(self):
+ super().__init__(name="custom")
+
+ async def load_item(self, user, metadata):
+ track = CustomAudioTrack(
+ { # Create an instance of our CustomAudioTrack.
+ "identifier": metadata["data"][0]["id"],
+ "isSeekable": True,
+ "author": metadata["data"][0]["attributes"]["artistName"],
+ "length": metadata["data"][0]["attributes"]["durationInMillis"],
+ "isStream": False,
+ "title": metadata["data"][0]["attributes"]["name"],
+ "uri": metadata["data"][0]["attributes"]["url"],
+ "duration": metadata["data"][0]["attributes"]["durationInMillis"],
+ "artworkUrl": metadata["data"][0]["attributes"]["artwork"]["url"].replace(
+ "{w}x{h}", "300x300"
+ ),
+ },
+ requester=user,
+ )
+ return LoadResult(LoadType.TRACK, [track], playlist_info=PlaylistInfo.none())
+
+ async def load_album(self, user, metadata):
+ tracks = []
+ for track in metadata["data"][0]["relationships"]["tracks"][
+ "data"
+ ]: # Loop through each track in the album.
+ tracks.append(
+ CustomAudioTrack(
+ { # Create an instance of our CustomAudioTrack.
+ "identifier": track["id"],
+ "isSeekable": True,
+ "author": track["attributes"]["artistName"],
+ "length": track["attributes"]["durationInMillis"],
+ "isStream": False,
+ "title": track["attributes"]["name"],
+ "uri": track["attributes"]["url"],
+ "duration": track["attributes"]["durationInMillis"],
+ "artworkUrl": track["attributes"]["artwork"]["url"].replace(
+ "{w}x{h}", "300x300"
+ ),
+ },
+ requster=user,
+ )
+ )
+
+ return LoadResult(LoadType.PLAYLIST, tracks, playlist_info=PlaylistInfo.none())
+
+ async def load_playlist(self, user, metadata):
+ tracks = []
+ for track in metadata["data"]: # Loop through each track in the playlist.
+ tracks.append(
+ CustomAudioTrack(
+ { # Create an instance of our CustomAudioTrack.
+ "identifier": track["id"],
+ "isSeekable": True,
+ "author": track["attributes"]["artistName"],
+ "length": track["attributes"]["durationInMillis"],
+ "isStream": False,
+ "title": track["attributes"]["name"],
+ "uri": track["attributes"]["url"],
+ "duration": track["attributes"]["durationInMillis"],
+ "artworkUrl": track["attributes"]["artwork"]["url"].replace(
+ "{w}x{h}", "300x300"
+ ),
+ },
+ requster=user,
+ )
+ )
+
+ return LoadResult(LoadType.PLAYLIST, tracks, playlist_info=PlaylistInfo.none())