Skip to content

Commit

Permalink
add parseVideoItem
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed May 30, 2021
1 parent f475c40 commit fb31929
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions server/services/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,7 @@ export default class YouTubeAdapter extends ServiceAdapter {
});
const results: Video[] = [];
for (const item of res.data.items) {
const video: Video = {
service: this.serviceId,
id: item.id,
};
if (item.snippet) {
video.title = item.snippet.title;
video.description = item.snippet.description;
if (item.snippet.thumbnails) {
if (item.snippet.thumbnails.medium) {
video.thumbnail = item.snippet.thumbnails.medium.url;
}
else {
video.thumbnail = item.snippet.thumbnails.default.url;
}
}
}
if (item.contentDetails) {
video.length = this.parseVideoLength(item.contentDetails.duration);
}
results.push(video);
results.push(this.parseVideoItem(item));
}
try {
await storage.updateManyVideoInfo(_.values(results));
Expand Down Expand Up @@ -427,6 +408,29 @@ export default class YouTubeAdapter extends ServiceAdapter {
}
}

private parseVideoItem(item: YoutubeApiVideo) {
const video: Video = {
service: this.serviceId,
id: item.id,
};
if (item.snippet) {
video.title = item.snippet.title;
video.description = item.snippet.description;
if (item.snippet.thumbnails) {
if (item.snippet.thumbnails.medium) {
video.thumbnail = item.snippet.thumbnails.medium.url;
}
else {
video.thumbnail = item.snippet.thumbnails.default.url;
}
}
}
if (item.contentDetails) {
video.length = this.parseVideoLength(item.contentDetails.duration);
}
return video;
}

private async getManyVideoLengthsFallback(ids: string[]) {
const getLengthPromises = ids.map((id) => this.getVideoLengthFallback(id));
const results = await Promise.all(getLengthPromises);
Expand Down

0 comments on commit fb31929

Please sign in to comment.