Recuperacion de Emisoras de ShoutCast a través de Json Object

P

Bueno, recientemente hable con un amigo mio y me proporcionó un código para recuperar las emisoras por géneros del directorio publico de shoutcast

en fin, si os sirve (como a mi) esta es la función clave

void __fastcall TfrmMain::RellenarListView(String genero)
{
	Caption = "Recibiendo...";

std::unique_ptr<TStringList> sl(new TStringList);
sl->Add("genrename=" + genero);

std::unique_ptr<TStringStream> s(new TStringStream);
String page = (genero.IsEmpty() || cbGeneros->ItemIndex < 1) ? "Top" : "BrowseByGenre";
NetHTTPClient->Post(L"https://www.shoutcast.com/Home/" + page, sl.get(), s.get());

std::unique_ptr<TJSONArray> jsonArray(static_cast<TJSONArray*>(
	TJSONObject::ParseJSONValue(TEncoding::UTF8->GetBytes(s->DataString), 0)));

Caption = jsonArray->Count;
ListView->Clear();
Memo1->Clear();

TJSONArrayEnumerator* jsonArrayEnum = jsonArray->GetEnumerator();
while (jsonArrayEnum->MoveNext()) {


	TJSONValue* jsonValue = jsonArrayEnum->Current;
	TListItem* item = ListView->Items->Add();

	item->Caption = jsonValue->GetValue<String>("Name");
	item->SubItems->Add(jsonValue->GetValue<int>(L"Bitrate"));
	item->SubItems->Add(jsonValue->GetValue<int>(L"Listeners"));
	item->SubItems->Add(jsonValue->GetValue<int>(L"ID"));

}
}
//---------------------------------------------------------------------------

gracias _Leo, como siempre, un crack

unit1.cpp:

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <System.JSON.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
	: TForm(Owner)
{
	PostMessage(Handle, WM_USER+1, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::RellenarListView(String genero)
{
	Caption = "Recibiendo...";

std::unique_ptr<TStringList> sl(new TStringList);
sl->Add("genrename=" + genero);

std::unique_ptr<TStringStream> s(new TStringStream);
String page = (genero.IsEmpty() || cbGeneros->ItemIndex < 1) ? "Top" : "BrowseByGenre";
NetHTTPClient->Post(L"https://www.shoutcast.com/Home/" + page, sl.get(), s.get());

std::unique_ptr<TJSONArray> jsonArray(static_cast<TJSONArray*>(
	TJSONObject::ParseJSONValue(TEncoding::UTF8->GetBytes(s->DataString), 0)));

Caption = jsonArray->Count;
ListView->Clear();
Memo1->Clear();

TJSONArrayEnumerator* jsonArrayEnum = jsonArray->GetEnumerator();
while (jsonArrayEnum->MoveNext()) {


	TJSONValue* jsonValue = jsonArrayEnum->Current;
	TListItem* item = ListView->Items->Add();

	item->Caption = jsonValue->GetValue<String>("Name");
	item->SubItems->Add(jsonValue->GetValue<int>(L"Bitrate"));
	item->SubItems->Add(jsonValue->GetValue<int>(L"Listeners"));
	item->SubItems->Add(jsonValue->GetValue<int>(L"ID"));

}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::cbGenerosCloseUp(TObject *Sender)
{
	RellenarListView(cbGeneros->Text);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ListViewSelectItem(TObject *Sender, TListItem *Item, bool Selected)
{
	if (!Selected) return;
	String ID = Item->SubItems->Strings[2];
	Memo1->Clear();
	Memo1->Lines->Add(L"     Winamp : http://yp.shoutcast.com/sbin/tunein-station.pls?id=" + ID);
	Memo1->Lines->Add(L" Any player : http://yp.shoutcast.com/sbin/tunein-station.m3u?id=" + ID);
	Memo1->Lines->Add(L"Open Format : http://yp.shoutcast.com/sbin/tunein-station.xspf?id=" + ID);
}
//---------------------------------------------------------------------------

unit1.hpp:

//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <System.Net.HttpClient.hpp>
#include <System.Net.HttpClientComponent.hpp>
#include <System.Net.URLClient.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <System.JSON.hpp>
#include <memory>
//---------------------------------------------------------------------------
class TfrmMain : public TForm
{
__published:	// IDE-managed Components
	TNetHTTPClient *NetHTTPClient;
	TListView *ListView;
	TPanel *Panel1;
	TComboBox *cbGeneros;
	TLabel *Label1;
	TMemo *Memo1;
	void __fastcall cbGenerosCloseUp(TObject *Sender);
	void __fastcall ListViewSelectItem(TObject *Sender, TListItem *Item, bool Selected);


private:	// User declarations

void __fastcall RellenarListView(String genero = L"");

MESSAGE void __fastcall WmUser1(TMessage& Msg)
{
	Application->ProcessMessages();
	RellenarListView();
}
BEGIN_MESSAGE_MAP
	VCL_MESSAGE_HANDLER(WM_USER+1, TMessage, WmUser1)
END_MESSAGE_MAP(inherited)

public:		// User declarations
	__fastcall TfrmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
//---------------------------------------------------------------------------
#endif

Project Example RAD Studio 10.1 Berlin: Shoutcast_prueba.zip

E

Gracias _Leo

Usuarios habituales