feat: improve parsing (#145)

* fix: err in `MusicDetailHeader` when no duration

* feat: get video duration from more places
This commit is contained in:
Patrick Kan
2022-08-19 17:02:01 +08:00
committed by GitHub
parent ecdac38458
commit dc2f0055cc
2 changed files with 3 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ class MusicDetailHeader extends YTNode {
this.second_subtitle = new Text(data.secondSubtitle);
this.year = this.subtitle.runs.find((run) => (/^[12][0-9]{3}$/).test(run.text))?.text || null;
this.song_count = this.second_subtitle.runs[0].text;
this.total_duration = this.second_subtitle.runs[2].text;
this.total_duration = this.second_subtitle.runs[2]?.text || '';
this.thumbnails = Thumbnail.fromResponse(data.thumbnail.croppedSquareThumbnailRenderer.thumbnail);
this.badges = Parser.parse(data.subtitleBadges);

View File

@@ -178,7 +178,8 @@ class MusicResponsiveListItem extends YTNode {
}));
}
const duration_text = this.#flex_columns[1].key('title').instanceof(Text).runs?.find((run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text;
const duration_text = this.#flex_columns[1].key('title').instanceof(Text).runs?.find((run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text ||
this.#fixed_columns[0]?.key('title').instanceof(Text).runs?.find((run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text;
duration_text && (this.duration = {
text: duration_text,
seconds: timeToSeconds(duration_text)