Skip to content

Commit

Permalink
add youtube music
Browse files Browse the repository at this point in the history
  • Loading branch information
SuspiciousLookingOwl committed Jun 22, 2024
1 parent 84785c3 commit 7ef384d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/libs/media-source/utils/factory.util.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ISpotifyTrack } from "@spotify";
import type { IVideoCompact } from "@youtube";
import type { IMusicSong, IMusicVideo, IVideoCompact } from "@youtube";
import { MediaSourceTypes, type IMediaSource } from "../apis";

export class MediaSourceFactory {
Expand All @@ -19,6 +19,22 @@ export class MediaSourceFactory {
return media;
}

static fromYoutubeMusic(music: IMusicSong | IMusicVideo) {
const media: IMediaSource = {
...music,
id: `youtube/${music.id}`,
creator: music.artists.map((a) => a.name).join(", "),
maxThumbnailUrl: music.thumbnails.at(-1)?.url || "",
minThumbnailUrl: music.thumbnails.at(0)?.url || "",
type: MediaSourceTypes.Youtube,
url: `https://youtu.be/${music.id}`,
sourceId: music.id,
playedYoutubeVideoId: music.id,
};

return media;
}

static fromSpotifyTrack(track: ISpotifyTrack) {
const media: IMediaSource = {
...track,
Expand Down

0 comments on commit 7ef384d

Please sign in to comment.