Example #1
0
    private Channel Extract(ChannelPageExtractor channelPage)
    {
        var channelId =
            channelPage.TryGetChannelId() ??
            throw new YoutubeExplodeException("Could not extract channel ID.");

        var title =
            channelPage.TryGetChannelTitle() ??
            throw new YoutubeExplodeException("Could not extract channel title.");

        var logoUrl =
            channelPage.TryGetChannelLogoUrl() ??
            throw new YoutubeExplodeException("Could not extract channel logo URL.");

        var logoSize = Regex
                       .Matches(logoUrl, @"\bs(\d+)\b")
                       .Cast <Match>()
                       .LastOrDefault()?
                       .Groups[1]
                       .Value
                       .NullIfWhiteSpace()?
                       .ParseIntOrNull() ?? 100;

        var thumbnails = new[] { new Thumbnail(logoUrl, new Resolution(logoSize, logoSize)) };

        return(new Channel(channelId, title, thumbnails));
    }