Pergunta

I am using a webclient to download a file from media fire but the download link changes every few days and it only works on my computer. I don't want to have to use some kind of API or anything because it shoudl be a simple process. I've considered other sites but none of them give me a direct download link to this. Here's my code:

    public void downloadMod(string url, string location, string destination)
    {

        this.location = location;
        this.destination = destination;

        using (WebClient webClient = new WebClient()) {

            Show();

            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(onModDownloadCompleted);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(onModDownloadProgressChanged);

            Uri URL = url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(url) : new Uri("http://" + url);

            try
            {

                webClient.DownloadFileAsync(URL, location);

            }
            catch (Exception ex)
            {

                Console.Write(ex.Message);

                Close();

            }

        }

    }

    private void onModDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {

        lblProgress.Text = e.ProgressPercentage.ToString() + " %";
        progress.Value = e.ProgressPercentage;

    }

    private void onModDownloadCompleted(object sender, AsyncCompletedEventArgs e)
    {

        unZipFile(location, destination);

    }

Help would be appreciated

Foi útil?

Solução

Why don't you want to use the API that Media Fire seems to provide for exactly what you want to do? Just browsing through the API, there is a call to get the download link you are looking for. Suppose you somehow can figure out today how the download link is generated, what happens tomorrow when Media Fire changes the way it generates those links? Your code probably no longer works. If you use their API, it should work regardless of what changes they make.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top