Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Los mejores trucos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 25-03-2025
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 280
Poder: 2
navbuoy Va por buen camino
Truco para listar emisoras de Radio Browser (web)

Hola amigos, esto creo que os va a gustar:

Estaba ahi experimentando con una API de Radio Browser y mirad que guapo
https://de2.api.radio-browser.info/

NECESITA LAS DLL DE SSL:
https://indy.fulgan.com/SSL/




aqui os dejo el codigo en C++ Builder y Delphi:

Código:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <System.JSON.hpp>
#include <IdHTTP.hpp>
#include <IdSSLOpenSSL.hpp>
#include <memory>

#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{

	try
	{
        std::unique_ptr<TIdHTTP> http(new TIdHTTP(nullptr));
        std::unique_ptr<TIdSSLIOHandlerSocketOpenSSL> ssl(new TIdSSLIOHandlerSocketOpenSSL(nullptr));
        std::unique_ptr<TStringStream> response(new TStringStream());

        // Configurar SSL correctamente
        ssl->SSLOptions->Method = sslvTLSv1_2;
        ssl->SSLOptions->Mode = sslmClient;
        ssl->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
		ssl->SSLOptions->VerifyDepth = 0;

		http->IOHandler = ssl.get();  // Asignar SSL a HTTP
		http->HandleRedirects = true;
		http->Request->UserAgent = "Mozilla/5.0";

         // URL de la API de Radio Browser
		String url = "http://de2.api.radio-browser.info/json/stations";

        // Hacer la solicitud GET
        http->Get(url, response.get());


		// Parsear la respuesta JSON
		std::unique_ptr<TJSONArray> jsonResponse(static_cast<TJSONArray*>(TJSONObject::ParseJSONValue(response->DataString)));

		if (jsonResponse)
		{
			ListBox1->Items->Clear();

			for (int i = 0; i < jsonResponse->Count; i++)
			{
				TJSONObject *station = dynamic_cast<TJSONObject*>(jsonResponse->Items[i]);

				if (station)
				{
					TJSONString *jsonName = dynamic_cast<TJSONString*>(station->GetValue("name"));
					TJSONString *jsonUrl = dynamic_cast<TJSONString*>(station->GetValue("url"));

                    UnicodeString name = jsonName ? jsonName->Value() : "Desconocido";
                    UnicodeString streamUrl = jsonUrl ? jsonUrl->Value() : "URL no disponible";

                    ListBox1->Items->Add(name + " - " + streamUrl);
                }
            }
		}
    }
	catch (const Exception &e)
	{
		ShowMessage("Error: " + e.Message);
	}
}
//---------------------------------------------------------------------------

Delphi:
Código Delphi [-]
unit Unit1;

interface

uses
  System.SysUtils, System.Classes, System.JSON, Vcl.Controls, Vcl.Forms,
  Vcl.StdCtrls, IdHTTP, IdSSLOpenSSL;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  http: TIdHTTP;
  ssl: TIdSSLIOHandlerSocketOpenSSL;
  response: TStringStream;
  jsonResponse: TJSONArray;
  station: TJSONObject;
  jsonName, jsonUrl: TJSONString;
  i: Integer;
  name, streamUrl: string;
begin
  try
    http := TIdHTTP.Create(nil);
    ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    response := TStringStream.Create;
    
    try
      // Configurar SSL
      ssl.SSLOptions.Method := sslvTLSv1_2;
      ssl.SSLOptions.Mode := sslmClient;
      ssl.SSLOptions.VerifyMode := [];
      ssl.SSLOptions.VerifyDepth := 0;

      http.IOHandler := ssl;
      http.HandleRedirects := True;
      http.Request.UserAgent := 'Mozilla/5.0';

      // URL de la API de Radio Browser
      http.Get('http://de2.api.radio-browser.info/json/stations', response);

      // Parsear la respuesta JSON
      jsonResponse := TJSONObject.ParseJSONValue(response.DataString) as TJSONArray;

      if Assigned(jsonResponse) then
      begin
        ListBox1.Items.Clear;
        
        for i := 0 to jsonResponse.Count - 1 do
        begin
          station := jsonResponse.Items[i] as TJSONObject;
          
          if Assigned(station) then
          begin
            jsonName := station.GetValue('name') as TJSONString;
            jsonUrl := station.GetValue('url') as TJSONString;

            name := IfThen(Assigned(jsonName), jsonName.Value, 'Desconocido');
            streamUrl := IfThen(Assigned(jsonUrl), jsonUrl.Value, 'URL no disponible');

            ListBox1.Items.Add(name + ' - ' + streamUrl);
          end;
        end;
      end;
    finally
      response.Free;
      ssl.Free;
      http.Free;
      jsonResponse.Free;
    end;
  except
    on E: Exception do
      ShowMessage('Error: ' + E.Message);
  end;
end;

end.

Última edición por navbuoy fecha: 25-03-2025 a las 18:06:22.
Responder Con Cita
  #2  
Antiguo 25-03-2025
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 280
Poder: 2
navbuoy Va por buen camino
Lo he dividido en 2 List Box para que la URL sea mas facilmente accesible cuando usemos
el reproductor para tocar la emisora en la tarjeta de sonido



Código:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <System.JSON.hpp>
#include <IdHTTP.hpp>
#include <IdSSLOpenSSL.hpp>
#include <memory>

#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{

	try
	{
        std::unique_ptr<TIdHTTP> http(new TIdHTTP(nullptr));
        std::unique_ptr<TIdSSLIOHandlerSocketOpenSSL> ssl(new TIdSSLIOHandlerSocketOpenSSL(nullptr));
        std::unique_ptr<TStringStream> response(new TStringStream());

		// Configurar SSL correctamente
		ssl->SSLOptions->Method = sslvTLSv1_2;
		ssl->SSLOptions->Mode = sslmClient;
		ssl->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
		ssl->SSLOptions->VerifyDepth = 0;

		http->IOHandler = ssl.get();  // Asignar SSL a HTTP
		http->HandleRedirects = true;
		http->Request->UserAgent = "Mozilla/5.0";

		 // URL de la API de Radio Browser
		String url = "http://de2.api.radio-browser.info/json/stations";

		// Hacer la solicitud GET
		http->Get(url, response.get());


		// Parsear la respuesta JSON
		std::unique_ptr<TJSONArray> jsonResponse(static_cast<TJSONArray*>(TJSONObject::ParseJSONValue(response->DataString)));

		if (jsonResponse)
		{
			ListBox1->Items->Clear();
			ListBox2->Items->Clear();

			for (int i = 0; i < jsonResponse->Count; i++)
			{
				TJSONObject *station = dynamic_cast<TJSONObject*>(jsonResponse->Items[i]);

				if (station)
				{
					TJSONString *jsonName = dynamic_cast<TJSONString*>(station->GetValue("name"));
					TJSONString *jsonUrl = dynamic_cast<TJSONString*>(station->GetValue("url"));

                    UnicodeString name = jsonName ? jsonName->Value() : "Desconocido";
                    UnicodeString streamUrl = jsonUrl ? jsonUrl->Value() : "URL no disponible";

					ListBox1->Items->Add(name);
					ListBox2->Items->Add(streamUrl);

				}
            }
		}
    }
	catch (const Exception &e)
	{
		ShowMessage("Error: " + e.Message);
	}
}
//---------------------------------------------------------------------------
Responder Con Cita
  #3  
Antiguo 25-03-2025
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 280
Poder: 2
navbuoy Va por buen camino


https://www.quazardev.net/RADIO_BROWSER_APP.rar

por si os resulta de utilidad ahi os lo dejo, si faltase algun BPL o algo decidmelo
Responder Con Cita
  #4  
Antiguo 26-03-2025
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.405
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Responder Con Cita
  #5  
Antiguo 26-03-2025
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.874
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Muchas gracias por la aportación.
La verdad es que está chulo...
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #6  
Antiguo Hace 4 Semanas
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 280
Poder: 2
navbuoy Va por buen camino


le he puesto unos slots de memorias para guardar emisoras
Responder Con Cita
  #7  
Antiguo Hace 4 Semanas
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.405
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Implementar truco para antidebug en mi clase debugger aguml C++ Builder 2 01-06-2020 21:32:56
Algun Truco para imitar el onkeydown madmai Internet 2 24-02-2009 14:00:37
Busco un truco para Grid edca OOP 4 30-01-2009 22:56:55
necesito un truco para escribir en 2 o mas lineas.. locotenentul Varios 2 26-07-2008 00:10:44
Truco para mayusculas en DBGrid Johnny Q OOP 6 16-10-2005 17:10:14


La franja horaria es GMT +2. Ahora son las 16:05:49.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi