You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code will throw an ObjectDisposedException in libvideo 1.3.0:
stringuri="https://www.youtube.com/watch?v=NUsoVlDFqZg";varvideo= YouTube.Default.GetVideo(uri);stringresult= video.Uri;// right here
Why? The gist of it is: when we run GetVideo, we create a new HttpClient to visit YouTube. After getting the source code of the page, we dispose the HttpClient so we don't leak resources.
Next, when we try getting the Uri, we have to visit another webpage if the video is encrypted. To avoid wasting resources, we try to reuse the HttpClient we just used to go to YouTube. Except we just disposed it.
Now once we try to use the HttpClient again, it realizes it's disposed and throws an ObjectDisposedException.
Oops.
Potential fixes:
Use VideoClient to visit the new webpage. While this would be neater and less code, it may not be a good solution because VideoClient is mainly intended for downloading the video binaries. The HTTP configurations (see bottom) you may want to make for a VideoClient may not apply for text-based files.
Create a new HttpClient each time a URL is decrypted. While is one of the simpler solutions, this may not be such a good idea. Consider the following code:
Seems innocuous, right? Well, pretend the video is encrypted. If we chose this option, and the video had, say 7 URLs to decrypt, then 7 new HttpClients would be created. This is definitely not good for performance.
Eagerly decrypt the URLs. Also a simple solution, but with big reprecussions. If we did this and the video is encrypted, then a simple line like YouTube.Default.GetVideos("...") will automatically decrypt all of the URLs. Basically, 7 HTTP requests. Even if we only needed 1, and didn't care about the other 6.
Alright, so those are the options I've come up with so far. At this moment I think 1) seems to be the best choice, it might not be so bad to share some HTTP configurations in VideoClient. If anyone else understood that, feel free to suggest any alternatives/give your opinion. I'll be fixing this issue by tomorrow evening.
The text was updated successfully, but these errors were encountered:
This code will throw an
ObjectDisposedException
in libvideo 1.3.0:Why? The gist of it is: when we run
GetVideo
, we create a newHttpClient
to visit YouTube. After getting the source code of the page, we dispose theHttpClient
so we don't leak resources.Next, when we try getting the
Uri
, we have to visit another webpage if the video is encrypted. To avoid wasting resources, we try to reuse theHttpClient
we just used to go to YouTube. Except we just disposed it.Now once we try to use the
HttpClient
again, it realizes it's disposed and throws anObjectDisposedException
.Oops.
Potential fixes:
Use
VideoClient
to visit the new webpage. While this would be neater and less code, it may not be a good solution becauseVideoClient
is mainly intended for downloading the video binaries. The HTTP configurations (see bottom) you may want to make for aVideoClient
may not apply for text-based files.Create a new
HttpClient
each time a URL is decrypted. While is one of the simpler solutions, this may not be such a good idea. Consider the following code:Seems innocuous, right? Well, pretend the video is encrypted. If we chose this option, and the video had, say 7 URLs to decrypt, then 7 new
HttpClients
would be created. This is definitely not good for performance.YouTube.Default.GetVideos("...")
will automatically decrypt all of the URLs. Basically, 7 HTTP requests. Even if we only needed 1, and didn't care about the other 6.Alright, so those are the options I've come up with so far. At this moment I think 1) seems to be the best choice, it might not be so bad to share some HTTP configurations in
VideoClient
. If anyone else understood that, feel free to suggest any alternatives/give your opinion. I'll be fixing this issue by tomorrow evening.The text was updated successfully, but these errors were encountered: