omansak / libvideo

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

"Sequence contains no elements" #197

Closed Wryal closed 3 years ago

Wryal commented 3 years ago

var vid = youtube.GetVideo(link);

this line throws the exeption "sequence contains no elements", even though it used to work fine the first times. is it something youtube-related? Am I the only one who experienced this?

arogerm commented 3 years ago

Dear Wryal It's the same error that tis ticket https://github.com/omansak/libvideo/issues/196#issue-847270981

omansak commented 3 years ago

can you guys share any example id's ?

HannahKiekens commented 3 years ago

I get the same exception on https://www.youtube.com/watch?v=9BUlNO09UgA

Trying downloading from Belgium

omansak commented 3 years ago

I get the same exception on https://www.youtube.com/watch?v=9BUlNO09UgA

Trying downloading from Belgium

i tried seems no problem :) idk can you give code snippet or error responses

omansak commented 3 years ago

can you guys share any example id's ?

I had an issue with downloading "V5Cb_vX6CcQ", switching back to 3.0.8 fixed it though (at least for now).

interesting i wll check that

HannahKiekens commented 3 years ago
                using (var service = Client.For(YouTube.Default))
                {
                    var video = service.GetVideo(this.url);
                    File.WriteAllBytes(this.file, video.GetBytes());
                }
ex.ToString()
"System.InvalidOperationException: Sequence contains no elements\r\n   at System.Linq.ThrowHelper.ThrowNoElementsException()\r\n   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)\r\n   at VideoLibrary.ServiceBase`1.VideoSelector(IEnumerable`1 videos)\r\n   at VideoLibrary.ServiceBase`1.GetVideoAsync(String videoUri, Func`2 sourceFactory)\r\n   at VideoLibrary.ServiceBase`1.GetVideo(String videoUri, Func`2 sourceFactory)\r\n   at VideoLibrary.Client`1.GetVideo(String videoUri)\r\n   at Scoops.TaskRunner.Tasks.youtube.LibVideoTask.DoDownload() in C:\\Users\\haki\\Documents\\GitHub\\Scoops.TaskRunner\\src\\Tasks\\youtube\\LibVideoTask.cs:line 82"
HannahKiekens commented 3 years ago

csproj info:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

<PackageReference Include="VideoLibrary" Version="3.1.0" />
JaniNagy commented 3 years ago

Hi!

I have the same problem.

Code:

                YouTube youtube = YouTube.Default;
                var vid = await youtube.GetVideoAsync(lv.Items[i].SubItems[0].Text);
                File.WriteAllBytes(source + vid.FullName, vid.GetBytes());
                MediaFile inputFile = new MediaFile { Filename = source + vid.FullName };
                MediaFile outputFile = new MediaFile { Filename = $"{source + Path.GetFileNameWithoutExtension(vid.FullName)}.mp3" };
                using (var engine = new Engine())
                {
                    engine.GetMetadata(inputFile);
                    engine.Convert(inputFile, outputFile);
                }

Videos what i tried: https://www.youtube.com/watch?v=rHDwzOYMwI0 https://www.youtube.com/watch?v=qK_NeRZOdq4 https://www.youtube.com/watch?v=qK_NeRZOdq4

SMarconetto commented 3 years ago

Hi all, have some problem here

The code

List<YouTubeVideo> videos = YouTube.Default
    .GetAllVideos(url)
    .ToList();

if (videos != null && videos.Count > 0)
{
    videos = videos
        .Where(v => v.Resolution == Configuration.VIDEO_WANTED_RESOLUTION)
        .OrderByDescending(v => v.Resolution)
         .ToList();

        if (videos.Count > 0)
        {
            return videos.FirstOrDefault();
        }
}

"videos" count is 0.

The video i'm trying: https://www.youtube.com/watch?v=0z0iMvZfa5E

omansak commented 3 years ago

please test #201

omansak commented 3 years ago

please test 3.1.1 on github and nuget