【问题标题】:Youtube downloader: illegal characters in pathYoutube 下载器:路径中有非法字符
【发布时间】:2016-12-10 08:58:59
【问题描述】:

我正在开发一个 Youtube 下载器,我使用 Path.combine,但是当我启动我的程序并在字段中放置一个 url 时,我收到了这个错误:

路径中有非法字符

progressBar.Minimum = 0;
        progressBar.Maximum = 100;
        if (!(txturl.Text == string.Empty))
        {
            try
            {
                IEnumerable<VideoInfo> videos = DownloadUrlResolver.GetDownloadUrls(txturl.Text);
                VideoInfo video = videos.First(p => p.VideoType == VideoType.Mp4 && p.Resolution == Convert.ToInt32(cmbResolution.Text));
                if (video.RequiresDecryption)
                    DownloadUrlResolver.DecryptDownloadUrl(video);
                VideoDownloader downloader = new VideoDownloader(video, Path.Combine(Application.StartupPath, video.Title + video.VideoExtension));
                downloader.DownloadProgressChanged += downloader_DownloadProgressChanged;
                Thread thread = new Thread(() => { downloader.Execute(); }) { IsBackground = true };
                thread.Start();
            }
            catch (Exception yt) { MessageBox.Show(yt.Message); }
        }
        else { MessageBox.Show("Input field cannot be empty."); }

【问题讨论】:

    标签: c# video youtube


    【解决方案1】:

    您不需要添加 "\\",因为 Path.Combine() 会为您添加它们。

    编辑:

    示例:Path.Combine(Application.StartupPath, "hello"); 返回类似 C:\path\to\exe\hello\ 的内容

    【讨论】:

    • 谢谢,但仍然拒绝工作。请问我不能使用“Directory GetCurrentDirectory”之类的东西,请不要介意我的错误。
    • 试试这个:Path.Combine(Application.StartupPath, string.Format("{0}.{1}", video.Title, video.VideoExtension));
    • 我已将整个代码复制到这里,请帮我查看和调试它。谢谢先生
    • 仅用于调试,将其添加到 VideoDownloader 调用下方:MessageBox.Show(Path.Combine(Application.StartupPath, string.Format("{0}.{1}", video.Title, video.VideoExtension)));
    • Jean Luc Nürrenberg,非常感谢您,先生。它现在对我有用。它是我复制的 Youtube 网址,但现在我尝试了另一个网址并下载了它。
    猜你喜欢
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 2019-08-30
    • 1970-01-01
    相关资源
    最近更新 更多