【问题标题】:Cannot download a subsite with a video无法下载包含视频的子网站
【发布时间】:2012-07-27 01:11:52
【问题描述】:

我制作了一个简单的程序(紧靠this 示例)来可视化我的问题。它只从指定的 URL 下载文件,仅此而已;在我尝试使用此类数据之前一切正常:

http://www.youtube.com/watch?v=pqaARDsiJv4

令人惊讶的是,什么也没发生。为什么不下载相关视频和HTML源代码?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Net;
using System.IO;
using System.ComponentModel;

namespace downloader
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            WebClient client = new WebClient();

            string fileName;

            try
            {
                fileName = System.IO.Path.GetFileName(URLBox.Text);
                Uri currentURL = new Uri(URLBox.Text);

                client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

                client.DownloadFileAsync(currentURL, fileName);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                progressBar.Value = 0;
            }

        }

        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Download Completed!");


        }

        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar.Value = e.ProgressPercentage;

        }


    }
}

【问题讨论】:

  • @JohnMitchell 在这种情况下没有下载任何内容。
  • 因为它是一个 YouTube 链接...Google 正在保护他们的知识产权...

标签: c# wpf youtube


【解决方案1】:

对于这样的 URL 这行...

fileName = System.IO.Path.GetFileName(URLBox.Text);

...将fileName 设置为"watch?v=pqaARDsiJv4",这不是合法的文件名。

【讨论】:

  • 没有抛出异常,多么疏忽!
  • 嗯,下载在另一个线程上,那些往往会默默地失败。
【解决方案2】:

我认为您不能像这样从 Youtube 下载视频。我将向您推荐去年有关从 Youtube 下载内容的 Stack Exchange 问题;有很多链接,甚至还有一种方法。但是所有这些解决方案都已经 3 年了,它们现在可能不再有效;这是您想要做的问题的一部分; Google 不断做出改变,这很可能会破坏任何当前的解决方案。

您可以查看此处提供的任何解决方案是否仍然有效:https://stackoverflow.com/questions/1852029/how-can-i-download-youtube-videos-using-net-code 或使用提供的信息创建您自己的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多