0

I am making a YouTube downloader and i have come to a problem that i do not understand how to fix. Basically, you select which YouTube videos you want to download and it adds it to a queue. After they are downloaded i have used the MP4File .dll to write the mp4 metadata tags.

Most of the YouTube downloads and the metadata tags work but i think when the YouTube title contains symbols it doesn't change the metadata tags and instead just crashes.

I have debugged the program and found the problem within this method:

    public static void UpdateMP4Details(string path, string title, string imagePreview)
    {
        try
        {
            MP4File file = MP4File.Open(@path); // Something wrong with the path

            file.Tags.Title = title; // Crashes here
            file.Tags.Artist = "Youtube";
            file.Tags.Artwork = DownloadImageFromUrl(imagePreview);
            file.Save();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n\nUnable to save video details", title);
        }
    }

The error i get is: 'Object reference not set to an instance of an object' i believe this is because it cannot find the path due to the symbols.

Sometimes the error is: 'Must specify a valid file name' Path:

"C:\Users\MyUserName\Documents\Visual Studio 2015\Projects\MusicDownloader\MusicDownloader\bin\Debug\TByte\User1\Videos\General\Ed Sheeran - Perfect Duet (with Beyoncé) [Official Audio].mp4"

It's a very stange problem and i have tried many alternatives but i believe it's to do with the symbols in the path as all the other YouTube videos without symbols work.

Is there a way round this? Could anyone help?

R. Jacobs
  • 41
  • 6
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – HaveSpacesuit Dec 29 '17 at 20:18

1 Answers1

0

Windows should have no problem with the characters in that filename, but perhaps the MP4File library does.

Would it be possible to download the file with a filename that didn't cause the problem in the first place? Perhaps using something like the youtube video ID instead of the video's title would work, since that is an ASCII-only string.

Ryan S
  • 501
  • 2
  • 6