omansak / libvideo

A lightweight .NET library to download YouTube videos.
BSD 2-Clause "Simplified" License
550 stars 164 forks source link

Troubles with certain youtube links. #68

Closed sommmen closed 7 years ago

sommmen commented 7 years ago

Hi,

I am using #61 to download about 180 youtube videos. For some reason however I get errors with the following youtube videos:

24-Feb-17 00:08:18  iHNKroqw2qQ Crystal Lake - Handzup Motherfuckers - Video Edit
Path: D:\Users\sommmen\Music\clipjes-downloader-dump\Crystal Lake - Handzup Motherfuckers - Video Edit
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at sommmen.clipjes_downloader.Program.DownloadVid(String id, String title)

24-Feb-17 00:08:26  5zCy3EWs9Q0 Calvin Harris, Ne-Yo - Let's Go
Path: D:\Users\sommmen\Music\clipjes-downloader-dump\Calvin Harris, Ne-Yo - Let's Go
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at sommmen.clipjes_downloader.Program.DownloadVid(String id, String title)

24-Feb-17 00:08:50  foE1mO2yM04 Mike Posner - I Took A Pill In Ibiza
Path: D:\Users\sommmen\Music\clipjes-downloader-dump\Mike Posner - I Took A Pill In Ibiza
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at sommmen.clipjes_downloader.Program.DownloadVid(String id, String title)

Code:

var allVideos = YouTube.Default.GetAllVideos(uri);
                video = allVideos.Where(_ => _.Format == VideoFormat.Mp4).OrderByDescending(_ => _.AudioBitrate).First(); //TODO try to get vid as mp3 here first.
                Console.WriteLine("Writing to: " + path + ".");
                File.WriteAllBytes(path + video.FileExtension, video.GetBytes());
                Console.WriteLine("Done writing.");

Ofcourse the error occurs in allvideos as getAllVideos couldn't retrieve the video data somehow.

I haven't the slightest clue why. Videolib just returns an InvalidOperationException which points out that my allvideos is empty; thus something goes wrong with the web request or something.

Occurs at the following links: https://youtube.com/watch?v=iHNKroqw2qQ https://youtube.com/watch?v=5zCy3EWs9Q0 https://youtube.com/watch?v=foE1mO2yM04

omansak commented 7 years ago

some videos unavaible so use custom ex

sommmen commented 7 years ago

"use custom ex" i'm afraid i do not know what you mean. The second one is indeed unavailable in my country but the first and third i can acces just fine...

omansak commented 7 years ago

https://github.com/hig-dev/libvideo this works, download source codes and copy src->libvideo

sommmen commented 7 years ago

@omansak was already using that :) (forking and rebuilding works better btw)

still issues with these out of like 300 links or something. Quite peculiar.

Tyrrrz commented 7 years ago

They are age-restricted videos. Check out YoutubeExplode to download those.

sommmen commented 7 years ago

Age restricted it is. if you're having the same issue;

I will be using the first method since i am already doing some stuff with google+ cookies etc. We need a fix for this library though. i'm closing this issue for now.