コード例 #1
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem listItem in ResultsBox.SelectedItems)
     {
         WaitLabel.Focus();
         WaitLabel.Visible = true;
         WaitLabel.Enabled = true;
         WebClient myWebClient = new WebClient(); // Create a new WebClient instance.
         myWebClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
         string file_loc = "http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=";
         //Get station file number to get the file
         SHOUTcastStation radiostation = listItem.Tag as SHOUTcastStation;
         if (radiostation != null)
         {
             file_loc = file_loc + radiostation.url + "&file=filename.pls";
         }
         //Download the file to extract url information
         myWebClient.DownloadFile(file_loc, "SCtemp.tmp");
         //Open file and check if we have met our daily limit if so quit
         StreamReader tr       = File.OpenText("SCtemp.tmp");
         string       parse_me = tr.ReadToEnd();
         tr.Close();
         File.Delete("SCtemp.tmp");
         if (parse_me.StartsWith("Too many requests.  Try again tomorrow."))
         {
             MessageBox.Show(this, "Too many requests, try again in a few minutes.");
             WaitLabel.Enabled     = false;
             WaitLabel.Visible     = false;
             Selected_Radiostation = null;
             return;
         }
         //Get our station info
         Regex           url_loc = new Regex("http://[^\r\n>]*");
         MatchCollection mc      = url_loc.Matches(parse_me);
         if (mc.Count < 1)
         {
             MessageBox.Show(this, "Something weird happened try again.");
             WaitLabel.Enabled     = false;
             WaitLabel.Visible     = false;
             Selected_Radiostation = null;
             return;
         }
         //Get the first link of the collected streams
         if (radiostation != null)
         {
             radiostation.url      = mc[0].Value.Replace("Title", "");
             Selected_Radiostation = radiostation;
         }
         WaitLabel.Enabled = false;
         WaitLabel.Visible = false;
         Close();
         return;
     }
 }
コード例 #2
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            //Check if the user has entered any text
            if (string.IsNullOrEmpty(SearchText.Text))
            {
                return;
            }
            //Show wait window
            WaitLabel.Focus();
            WaitLabel.Visible = true;
            WaitLabel.Enabled = true;
            ArrayList Station_List = Search(SearchText.Text);

            WaitLabel.Enabled = false;
            WaitLabel.Visible = false;
            if (Station_List == null)
            {
                MessageBox.Show(this, "No stations found please search again.");
                return;
            }
            if (ResultsBox.Items != null)
            {
                ResultsBox.Items.Clear();
            }
            foreach (SHOUTcastStation station in Station_List)
            {
                SHOUTcastStation radiostation = new SHOUTcastStation();
                radiostation.name    = station.name;
                radiostation.url     = station.url;
                radiostation.bitrate = station.bitrate;
                ListViewItem listItem = new ListViewItem(new string[]
                {
                    radiostation.bitrate.ToString(),
                    radiostation.name,
                    radiostation.url
                });
                listItem.Tag = radiostation;
                if (ResultsBox.Items != null)
                {
                    ResultsBox.Items.Add(listItem);
                }
            }
            ResultsBox.Focus();
        }
コード例 #3
0
 private void AddButton_Click(object sender, EventArgs e)
 {
   foreach (ListViewItem listItem in ResultsBox.SelectedItems)
   {
     WaitLabel.Focus();
     WaitLabel.Visible = true;
     WaitLabel.Enabled = true;
     WebClient myWebClient = new WebClient(); // Create a new WebClient instance.	
     myWebClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
     string file_loc = "http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=";
     //Get station file number to get the file
     SHOUTcastStation radiostation = listItem.Tag as SHOUTcastStation;
     if (radiostation != null) file_loc = file_loc + radiostation.url + "&file=filename.pls";
     //Download the file to extract url information
     myWebClient.DownloadFile(file_loc, "SCtemp.tmp");
     //Open file and check if we have met our daily limit if so quit
     StreamReader tr = File.OpenText("SCtemp.tmp");
     string parse_me = tr.ReadToEnd();
     tr.Close();
     File.Delete("SCtemp.tmp");
     if (parse_me.StartsWith("Too many requests.  Try again tomorrow."))
     {
       MessageBox.Show(this, "Too many requests, try again in a few minutes.");
       WaitLabel.Enabled = false;
       WaitLabel.Visible = false;
       Selected_Radiostation = null;
       return;
     }
     //Get our station info
     Regex url_loc = new Regex("http://[^\r\n>]*");
     MatchCollection mc = url_loc.Matches(parse_me);
     if (mc.Count < 1)
     {
       MessageBox.Show(this, "Something weird happened try again.");
       WaitLabel.Enabled = false;
       WaitLabel.Visible = false;
       Selected_Radiostation = null;
       return;
     }
     //Get the first link of the collected streams
     if (radiostation != null)
     {
       radiostation.url = mc[0].Value.Replace("Title", "");
       Selected_Radiostation = radiostation;
     }
     WaitLabel.Enabled = false;
     WaitLabel.Visible = false;
     Close();
     return;
   }
 }
コード例 #4
0
 private void SearchButton_Click(object sender, EventArgs e)
 {
   //Check if the user has entered any text
   if (string.IsNullOrEmpty(SearchText.Text)) return;
   //Show wait window
   WaitLabel.Focus();
   WaitLabel.Visible = true;
   WaitLabel.Enabled = true;
   ArrayList Station_List = Search(SearchText.Text);
   WaitLabel.Enabled = false;
   WaitLabel.Visible = false;
   if (Station_List == null)
   {
     MessageBox.Show(this, "No stations found please search again.");
     return;
   }
   if (ResultsBox.Items != null) ResultsBox.Items.Clear();
   foreach (SHOUTcastStation station in Station_List)
   {
     SHOUTcastStation radiostation = new SHOUTcastStation();
     radiostation.name = station.name;
     radiostation.url = station.url;
     radiostation.bitrate = station.bitrate;
     ListViewItem listItem = new ListViewItem(new string[]
                                                {
                                                  radiostation.bitrate.ToString(),
                                                  radiostation.name,
                                                  radiostation.url
                                                });
     listItem.Tag = radiostation;
     if (ResultsBox.Items != null) ResultsBox.Items.Add(listItem);
   }
   ResultsBox.Focus();
 }
コード例 #5
0
    private static ArrayList Search(string search)
    {
      //Create needed variables
      const int count = 100;
      int total; // Used to keep track of file numbering
      const int counter = 1;
      int[] found = new int[count];

      string[] SCstaindex = new string[count]; //Index info
      string[] SCstanum = new string[count]; // Second part holds file number on Shoutcast
      string[] SCstaname = new string[count]; // Extracted station name
      string[] SCstabr = new string[count]; //Bitrate info
      WebClient myWebClient = new WebClient(); // Create a new WebClient instance.	
      myWebClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
      // Create Regex objects and define the search criteria.
      Regex nterm = new Regex("Unfortunately, there weren't any SHOUTcast streams found containing the term");
      Regex ngenre = new Regex("Unfortunately, there weren't any SHOUTcast streams found under the genre");
      Regex snum = new Regex("rn=[0-9]*");
      Regex sname = new Regex("target=\"_scurl\" href=.*</a>");
      Regex namerepstr = new Regex("target.*\">");
      Regex sbr = new Regex("<font face=\"Arial, Helvetica\" size=\"2\" color=\"#FFFFFF\">[0-9]*</font>");
      Regex brrepstr = new Regex("<font face=\"Arial, Helvetica\" size=\"2\" color=\"#FFFFFF\">");

      //Connect to remote server and download HTML
      string address = "http://www.shoutcast.com/directory/?s=" + search + "&numresult=100&orderby=bitrate";
      byte[] HTMLbuffer = myWebClient.DownloadData(address);
      string HTMLdownload = Encoding.ASCII.GetString(HTMLbuffer);

      //Check requested if genre or search exists
      if (search == "")
      {
        return null;
      }

      MatchCollection mc = nterm.Matches(HTMLdownload);
      if (mc.Count > 0)
      {
        return null;
      }
      mc = ngenre.Matches(HTMLdownload);
      if (mc.Count > 0)
      {
        return null;
      }

      try
      {
        //Build index numbers for stations
        int ind = 0;
        for (int i = counter; i < counter + count; i++)
        {
          if (i < 10)
          {
            SCstaindex[ind] = "0" + i;
          }
          else SCstaindex[ind] = i.ToString();
          ind++;
        }

        //Extract Station Number and store in SCstanum[]
        mc = snum.Matches(HTMLdownload);
        // Loop through the match collection to retrieve all 
        // matches and positions.
        total = mc.Count;
        for (int i = 0; i < mc.Count; i++)
        {
          // Add the match string to the string array.   
          SCstanum[i] = mc[i].Value.Replace("rn=", "");
          // Record the character position where the match was found.
          found[i] = mc[i].Index;
        }


        //Extract Station Name and store in SCstaname
        mc = sname.Matches(HTMLdownload);
        for (int i = 0; i < mc.Count; i++)
        {
          // Add the match string to the string array.   
          SCstaname[i] = mc[i].Value;
          SCstaname[i] = namerepstr.Replace(SCstaname[i], "");
          SCstaname[i] = SCstaname[i].Replace("</a>", "");
          // Record the character position where the match was found.
          found[i] = mc[i].Index;
        }


        //Extract bitrate and store in SCstabr
        mc = sbr.Matches(HTMLdownload);
        for (int i = 0; i < mc.Count; i++)
        {
          // Add the match string to the string array.   
          SCstabr[i] = mc[i].Value;
          SCstabr[i] = brrepstr.Replace(SCstabr[i], "");
          SCstabr[i] = SCstabr[i].Replace("</font>", "");
          // Record the character position where the match was found.
          found[i] = mc[i].Index;
        }
      }
      catch (IndexOutOfRangeException)
      {
        return null;
      }
      catch (WebException)
      {
        return null;
      }
      catch (Exception)
      {
        return null;
      }

      //Write stuff to array list
      ArrayList stations = new ArrayList();
      for (int i = 0; i < total; i++)
      {
        SHOUTcastStation station = new SHOUTcastStation();
        station.url = SCstanum[i];
        station.name = SCstaname[i];
        station.bitrate = Convert.ToInt32(SCstabr[i]);
        stations.Add(station);
      }
      return stations;
    }
コード例 #6
0
        private static ArrayList Search(string search)
        {
            //Create needed variables
            const int count = 100;
            int       total; // Used to keep track of file numbering
            const int counter = 1;

            int[] found = new int[count];

            string[]  SCstaindex  = new string[count]; //Index info
            string[]  SCstanum    = new string[count]; // Second part holds file number on Shoutcast
            string[]  SCstaname   = new string[count]; // Extracted station name
            string[]  SCstabr     = new string[count]; //Bitrate info
            WebClient myWebClient = new WebClient();   // Create a new WebClient instance.

            myWebClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
            // Create Regex objects and define the search criteria.
            Regex nterm      = new Regex("Unfortunately, there weren't any SHOUTcast streams found containing the term");
            Regex ngenre     = new Regex("Unfortunately, there weren't any SHOUTcast streams found under the genre");
            Regex snum       = new Regex("rn=[0-9]*");
            Regex sname      = new Regex("target=\"_scurl\" href=.*</a>");
            Regex namerepstr = new Regex("target.*\">");
            Regex sbr        = new Regex("<font face=\"Arial, Helvetica\" size=\"2\" color=\"#FFFFFF\">[0-9]*</font>");
            Regex brrepstr   = new Regex("<font face=\"Arial, Helvetica\" size=\"2\" color=\"#FFFFFF\">");

            //Connect to remote server and download HTML
            string address = "http://www.shoutcast.com/directory/?s=" + search + "&numresult=100&orderby=bitrate";

            byte[] HTMLbuffer   = myWebClient.DownloadData(address);
            string HTMLdownload = Encoding.ASCII.GetString(HTMLbuffer);

            //Check requested if genre or search exists
            if (search == "")
            {
                return(null);
            }

            MatchCollection mc = nterm.Matches(HTMLdownload);

            if (mc.Count > 0)
            {
                return(null);
            }
            mc = ngenre.Matches(HTMLdownload);
            if (mc.Count > 0)
            {
                return(null);
            }

            try
            {
                //Build index numbers for stations
                int ind = 0;
                for (int i = counter; i < counter + count; i++)
                {
                    if (i < 10)
                    {
                        SCstaindex[ind] = "0" + i;
                    }
                    else
                    {
                        SCstaindex[ind] = i.ToString();
                    }
                    ind++;
                }

                //Extract Station Number and store in SCstanum[]
                mc = snum.Matches(HTMLdownload);
                // Loop through the match collection to retrieve all
                // matches and positions.
                total = mc.Count;
                for (int i = 0; i < mc.Count; i++)
                {
                    // Add the match string to the string array.
                    SCstanum[i] = mc[i].Value.Replace("rn=", "");
                    // Record the character position where the match was found.
                    found[i] = mc[i].Index;
                }


                //Extract Station Name and store in SCstaname
                mc = sname.Matches(HTMLdownload);
                for (int i = 0; i < mc.Count; i++)
                {
                    // Add the match string to the string array.
                    SCstaname[i] = mc[i].Value;
                    SCstaname[i] = namerepstr.Replace(SCstaname[i], "");
                    SCstaname[i] = SCstaname[i].Replace("</a>", "");
                    // Record the character position where the match was found.
                    found[i] = mc[i].Index;
                }


                //Extract bitrate and store in SCstabr
                mc = sbr.Matches(HTMLdownload);
                for (int i = 0; i < mc.Count; i++)
                {
                    // Add the match string to the string array.
                    SCstabr[i] = mc[i].Value;
                    SCstabr[i] = brrepstr.Replace(SCstabr[i], "");
                    SCstabr[i] = SCstabr[i].Replace("</font>", "");
                    // Record the character position where the match was found.
                    found[i] = mc[i].Index;
                }
            }
            catch (IndexOutOfRangeException)
            {
                return(null);
            }
            catch (WebException)
            {
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }

            //Write stuff to array list
            ArrayList stations = new ArrayList();

            for (int i = 0; i < total; i++)
            {
                SHOUTcastStation station = new SHOUTcastStation();
                station.url     = SCstanum[i];
                station.name    = SCstaname[i];
                station.bitrate = Convert.ToInt32(SCstabr[i]);
                stations.Add(station);
            }
            return(stations);
        }