Youtubeexplode: Getting a video comment

Created on 12 Nov 2018  路  17Comments  路  Source: Tyrrrz/YoutubeExplode

Is there any method to get comments from a video?

If not, that would be such a nice feature to add.

enhancement wontfix

All 17 comments

What is your use case for it?

I guess it would be nice, but don't think Tyrrrz intended it to be within the scope and usage of YE

Yeah but two features that would make this package really great would be Searching based on keywords and retrieving comments.

Yeah but two features that would make this package really great would be Searching based on keywords and retrieving comments.

But what is your use case for the comments? Just curious how you intend to use the library.

I want to display some videos in an app for but would want to moderate comments to ensure there is no offending/spam.

...that would make this package really great would be Searching based on keywords...

Why is SearchVideosAsync not good enough for you?

@remiX- is right, I think the current feature set is good enough. Remember that adding new features such as this one means that I will have to maintain it and fix it every time it breaks, which happens often.

SearchVideosAsync is wonderful!

Do you know how a proxy can be set?

There is YoutubeClient ctor where you can pass HttpClient, use proxy on HttpClient.
Note: there are some stuff @Tyrrrz did on HttpClient So you might need to do that too.

There is YoutubeClient ctor where you can pass HttpClient, use proxy on HttpClient.
Note: there are some stuff @Tyrrrz did on HttpClient So you might need to do that too.

Could you please provide an example?

#r "nuget: YoutubeExplode, *"

using System.Net;
using System.Net.Http;
using YoutubeExplode;
using YoutubeExplode.Models;

HttpMessageHandler CreateProxiedHttpMessageHandler(string proxyServer)
{
    var proxiedHttpClientHandler = new HttpClientHandler
    {
        Proxy = new WebProxy(proxyServer),
        UseProxy = true
    };

    //Stuff from YoutubeExplode library:
    if (proxiedHttpClientHandler.SupportsAutomaticDecompression)
        proxiedHttpClientHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

    proxiedHttpClientHandler.UseCookies = false;
    return proxiedHttpClientHandler;
}

async Task<Video> GetVideoInfoThroughProxyAsync(string proxyServer, string videoId)
{
    using (var httpClient = new HttpClient(CreateProxiedHttpMessageHandler(proxyServer), true))
    {
        //Stuff from YoutubeExplode library:
        httpClient.DefaultRequestHeaders.Add("User-Agent", "YoutubeExplode (github.com/Tyrrrz/YoutubeExplode)");
        //Let's get video info:
        var youtubeClient = new YoutubeClient(httpClient);
        return await youtubeClient.GetVideoAsync(videoId);
    }
}
var proxyServer = "http://localhost:8888";
var videoInfo = await GetVideoInfoThroughProxyAsync(proxyServer, "zyluU2OpqDA");

Unless by proxy you meant something else..

Great example, @slowlogicboy!
Make sure that you await tasks inside using blocks, otherwise it will be disposed too early.

So do I need to modify the library鈥檚 code?

Is there any override?

Great example, @SlowLogicBoy!
Make sure that you await tasks inside using blocks, otherwise it will be disposed too early.

Oh right didn't notice that, thanks for the catch. Modified my code accordingly.

So do I need to modify the library鈥檚 code?

Is there any override?

No you don't need to override anything.

just use YoutubeClient(HttpClient httpClient) constructor.

Thanks!

Now I can use:

var clientt = new YoutubeClient(httpClient);

But wouldn't it be nice to write:

var client = new YoutubeClient(); client.httpClient = httpClient();

or even better:

client.httpClient.Proxy = new Proxy();

btw, I am struggling to run 10 concurrent requests in parallel as it seems to be very slow still.
Is there any slow for that?

I have tried Task.WhenAll but it's still slow

Then it wouldn't be immutable.

.NET limits to 2 simultaneous connections, so you have to raise that limit using ServivePointManager or using MaxConnectionsPerServer in HttpClientHandler

I tried that but it is still the same. I can't even use MaxConnectionsPerServer because it's not implemented (according to https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs). Any other ideas/suggestions?

Thanks

I have no idea how it works on mono

I decided that comments are out of scope, at least now.
Currently the scope is downloading videos, getting video metadata which is shown on the watch page (which comes from different sources) and getting playlist metadata.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jvitoroc picture jvitoroc  路  8Comments

vsjtechnologies picture vsjtechnologies  路  7Comments

severino65 picture severino65  路  3Comments

spoikbr picture spoikbr  路  5Comments

NoobInTraining picture NoobInTraining  路  5Comments