title: C# find highest available youtube resolution on a video
body: <p>I'm making a playlist downloader which downloads every video on the playlist, but so far i can only make it download in 360p. I want to automatically find the highest resolution for the video and download it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>                    IEnumerable&lt;VideoInfo&gt; videoInfos = DownloadUrlResolver.GetDownloadUrls("www.youtube.com/watch?v=" + vid.ToString());
  
                      VideoInfo video = videoInfos.First(info =&gt; info.VideoType == VideoType.Mp4 &amp;&amp; info.Resolution == 360);
  
                      string filename = video.Title;
  
                      if (video.RequiresDecryption)
                      {
                          DownloadUrlResolver.DecryptDownloadUrl(video);
                      }
  
                      string invalidChars = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
                      foreach (char c in invalidChars)
                      {
                          filename = filename.Replace(c.ToString(), "");
                      }
  
                      var videoDownloader = new VideoDownloader(video, Path.Combine(corpath, filename + video.VideoExtension));
  
  
                      Console.Write("\rVideo #{0} is currently being downloaded...", i.ToString());
  
                      videoDownloader.Execute();
                      i++;
                  }
                  catch (Exception ex)
                  {
  
                  }
  </code></pre>
  
  <p>I'm using this library: <a href="https://github.com/flagbug/YoutubeExtractor/" rel="nofollow">https://github.com/flagbug/YoutubeExtractor/</a></p>