1

I'm not experienced with C#, but I got the basics down. Now I'm trying to download videos from YouTube with the Video Library (in the VS package manager: Install-Package VideoLibrary).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.IO;
using VideoLibrary;

namespace TubeDemo
{
    public partial class MainWindow : Window
    {
        string link = "https://www.youtube.com/watch?v=8SbUC-UaAxE";
        string link2 = "https://www.youtube.com/watch?v=BlRqTNkgEuo";
        public MainWindow()
        {
            InitializeComponent();
        }
        void SaveVideoToDisk_Click(object sender, EventArgs e)
        {
            var youTube = YouTube.Default; // starting point for YouTube actions
            var video = youTube.GetVideo(link2); // gets a Video object with info about the video
            File.WriteAllBytes(@"C:\testfire\" + video.FullName, video.GetBytes());
        }
    }
}

Above functions SaveVideoToDisk_Click gets called from a .xaml button, which works fine. But not every video works OK. video.URI gets awfully big, over 800 characters. Some of the URLs turn out to cause the video.URI to throw an exception:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

In the code provided, passing link as argument throws while passing link2 works just fine.

  1. Can I fix this?
  2. If not, how should I handle these exceptions? Just try, catch and report or is checking before a better idea?
Nick
  • 11
  • 2
  • Please provide [MCVE] - make sure all necessary values are available inline in the post instead of result of execution of unknown code against external site. When you sort out your sample code you may find out that you are actually asking more than one question - make sure each post has just one concrete question. – Alexei Levenkov Nov 15 '15 at 19:02
  • @AlexeiLevenkov I'd say this is about as minimal as it gets. What part could be more minimized? – Nick Nov 15 '15 at 19:32
  • I seriously doubt one needs to install any external libraries to reproduce particular problem. Such requirement on the code significantly limits number of people who can even consider answering your question. But they exist - so hopefully someone eventually answers. – Alexei Levenkov Nov 15 '15 at 19:54
  • @AlexeiLevenkov Yes, this won't be a popular question. However, it's a method of that particular library causing the error, so IMO it can't be stripped further. I hope someone is willing to help out though, would be plain awesome. – Nick Nov 15 '15 at 20:46

0 Answers0