Skip to content

Commit ec8cbc6

Browse files
committed
YouTube Music: Factor out track conversion
1 parent 176cb69 commit ec8cbc6

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

providers/YouTubeMusic/mod.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class YoutubeMusicReleaseLookup extends ReleaseLookup<YoutubeMusicProvide
169169
};
170170
}
171171

172-
protected override async convertRawRelease(rawRelease: YTMusic.Album) {
172+
protected override convertRawRelease(rawRelease: YTMusic.Album) {
173173
if (!this.entity) {
174174
this.entity = this.provider.extractEntityFromUrl(new URL(rawRelease.url!));
175175
}
@@ -209,38 +209,7 @@ export class YoutubeMusicReleaseLookup extends ReleaseLookup<YoutubeMusicProvide
209209
}
210210
}, []);
211211

212-
const tracklist = rawRelease.contents.map((item) => {
213-
const videoId = item.overlay?.content?.endpoint.payload.videoId;
214-
215-
let length;
216-
if (item.duration) {
217-
length = item.duration.seconds * 1000;
218-
}
219-
220-
let number;
221-
if (item.index?.text) {
222-
try {
223-
number = parseInt(item.index.text);
224-
} catch (_e) {
225-
// Leave number undefined if parsing failed
226-
}
227-
}
228-
229-
return {
230-
title: item.title!,
231-
tracktype: 'audio',
232-
recording: {
233-
title: item.title!,
234-
externalIds: [{
235-
type: TRACK,
236-
id: videoId,
237-
provider: this.provider.internalName,
238-
}],
239-
},
240-
length,
241-
number,
242-
} as HarmonyTrack;
243-
});
212+
const tracklist = rawRelease.contents.map(this.processTrack);
244213

245214
const release: HarmonyRelease = {
246215
title,
@@ -260,4 +229,37 @@ export class YoutubeMusicReleaseLookup extends ReleaseLookup<YoutubeMusicProvide
260229

261230
return release;
262231
}
232+
233+
processTrack(item: YTNodes.MusicResponsiveListItem) {
234+
const videoId = item.overlay?.content?.endpoint.payload.videoId;
235+
236+
let length;
237+
if (item.duration) {
238+
length = item.duration.seconds * 1000;
239+
}
240+
241+
let number;
242+
if (item.index?.text) {
243+
try {
244+
number = parseInt(item.index.text);
245+
} catch (_e) {
246+
// Leave number undefined if parsing failed
247+
}
248+
}
249+
250+
return {
251+
title: item.title!,
252+
tracktype: 'audio',
253+
recording: {
254+
title: item.title!,
255+
externalIds: [{
256+
type: TRACK,
257+
id: videoId,
258+
provider: this.provider.internalName,
259+
}],
260+
},
261+
length,
262+
number,
263+
} as HarmonyTrack;
264+
}
263265
}

0 commit comments

Comments
 (0)