Downloading an audio file from a website

audio c# download html-agility-pack web

Question

Trying to get an audio file from a website is what I'm attempting to accomplish. When you press the little earmuffs, an audio file starts playing and a sound is activated. If it's feasible to locate and download the sound, that is what I was asking.

My search for it went like this:

public void grabAudio()
    {
        string s = "http://pokedream.com/pokedex/pokemon/bulbasaur";

        HtmlWeb hw = new HtmlWeb();
        HtmlAgilityPack.HtmlDocument doc = hw.Load(s);

        var audio = doc.DocumentNode.SelectNodes("//div[@class='triggers']//img#pokecry-trigger")[0];
        if (doc.DocumentNode.SelectNodes("//div[@class='triggers']//img#pokecry-trigger")[0] != null)
        {
            //I have no idea what im doing :(
        }

    }

a picture of what I'm attempting to get and URL of a website

Any assistance is much appreciated:)

1
0
3/24/2013 10:28:38 AM

Accepted Answer

First off, you probably shouldn't be doing this if the site's creator hasn't given you permission to.

If you have the necessary authorization and a good cause, you can analyze the code and notice that the picture doesn't seem to have any functions, and it doesn't play sound either. Therefore, JavaScript is probably used to control the functionality.

You then begin searching through the JavaScript for anything that relates to the interesting element. This code should be located inpokedex.js :

$('#pokecry-trigger').click(function() {
    $('#pokecry').html('<embed src="/pokedex/images/cries/' + $('#identifier').text() + '.mp3" />');
  });

hence, when you click the picture, aembed markup includes a tag. You may infer that the files are in by looking at the source tag./pokedex/images/cries/<id>.mp3 It produces the ID as a tag alongside the ID#identifier .

The next step is to download each sound you need by simply finding its ID. To achieve this, download the HTML markup, locate the letter DIV, and then type it into the URL template as previously mentioned:

string id = "001"; // found in the markup
string url = String.Format("http://pokedream.com/pokedex/images/cries/{0}.mp3", id);
using(var cli = new System.Net.WebClient()) 
{
    var mp3Data = cli.DownloadData(url);
}
3
3/24/2013 10:42:27 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow