fix: some cleanup and fixing runtime bugs, refs NOISSUE
This commit is contained in:
@@ -5,9 +5,9 @@ public class YoutubeMusicValidator : UriBasedSongValidatorBase
|
||||
{
|
||||
public override string UriValidatorRegex => @"^(https?://)?(music\.youtube\.com/watch\?v=|youtu\.be/)([a-zA-Z0-9_-]{11})";
|
||||
|
||||
public override async Task<bool> CanExtractSongMetadataAsync(Uri songUri)
|
||||
public override Task<bool> CanExtractSongMetadataAsync(Uri songUri)
|
||||
{
|
||||
return this.CanValidateUri(songUri);
|
||||
return Task.FromResult(this.CanValidateUri(songUri));
|
||||
}
|
||||
|
||||
public override async Task<Song> ValidateAsync(Uri songUri)
|
||||
@@ -15,12 +15,12 @@ public class YoutubeMusicValidator : UriBasedSongValidatorBase
|
||||
var title = string.Empty;
|
||||
var artist = string.Empty;
|
||||
|
||||
using(HttpClient httpClient = new HttpClient())
|
||||
using (HttpClient httpClient = new HttpClient())
|
||||
{
|
||||
var response = await httpClient.GetAsync(songUri);
|
||||
var config = Configuration.Default.WithDefaultLoader();
|
||||
var context = BrowsingContext.New(config);
|
||||
using(var document = await context.OpenAsync(async req => req.Content(await response.Content.ReadAsStringAsync())))
|
||||
using (var document = await context.OpenAsync(async req => req.Content(await response.Content.ReadAsStringAsync())))
|
||||
{
|
||||
// document.getElementsByTagName("ytmusic-player-queue-item")[0].getElementsByClassName("song-title")[0].innerHTML
|
||||
title = document.QuerySelector(".ytmusic-player-queue-item")?.QuerySelector(".song-title")?.InnerHtml;
|
||||
@@ -28,7 +28,9 @@ public class YoutubeMusicValidator : UriBasedSongValidatorBase
|
||||
artist = document.QuerySelector(".ytmusic-player-queue-item")?.QuerySelector(".byline")?.InnerHtml;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
var song = new Song
|
||||
{
|
||||
Name = title,
|
||||
@@ -37,6 +39,8 @@ public class YoutubeMusicValidator : UriBasedSongValidatorBase
|
||||
Provider = SongProvider.YouTube,
|
||||
SpotifyId = this.LookupSpotifyId(title, artist)
|
||||
};
|
||||
#pragma warning restore CS8604 // Possible null reference argument.
|
||||
#pragma warning restore CS8604 // Possible null reference argument.
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user