package Plugins::Rhapsody::Plugin;

# SlimServer Copyright (c) 2001-2007 Logitech
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2.

use strict;

use Slim::Networking::SimpleAsyncHTTP;
use Slim::Player::ProtocolHandlers;
use Slim::Utils::Misc;
use Slim::Utils::Timers;
use Slim::Utils::UPnPMediaServer;
use Plugins::Rhapsody::ProtocolHandler;

# This holds a mapping between Rhapsody servers and dynamic port numbers
my $ports = {};

sub getDisplayName {
	return 'PLUGIN_RHAPSODY_MODULE_NAME';
}

sub enabled {
	return ($::VERSION ge '6.5');
}

sub getFunctions {
	return '';
}

sub findCallback {
	my $device = shift;
	my $event = shift;

	if ( $device->getmodelname =~ /Rhapsody/ ) {
		
		my ($host, $port) = $device->getlocation =~ m|//([0-9.]+):(\d+)|;
		
		if ( $event eq 'add' ) {
			$ports->{ $host } = {
				'port'   => $port,
				'device' => $device,
			};
			$::d_plugins && msgf("Rhapsody: New server detected: %s (%s)\n",
				$device->getfriendlyname,
				$device->getlocation,
			);
		}
		else {
			delete $ports->{ $host };
			$::d_plugins && msgf("Rhapsody: Server went away: %s (%s)\n",
				$device->getfriendlyname,
				$device->getlocation,
			);
		}
	}
	
	return;
}

sub getPortForHost {
	my $host = shift;
	
	return $ports->{$host}->{'port'};
}

sub initPlugin {
	unless ( $::noupnp ) {
		Slim::Player::ProtocolHandlers->registerHandler('rhap', 'Plugins::Rhapsody::ProtocolHandler');
	
		Slim::Utils::UPnPMediaServer::registerCallback( \&findCallback );
	}
}

sub strings {
	return "
PLUGIN_RHAPSODY_MODULE_NAME
	DE	Real Rhapsody
	EN	Real Rhapsody
	ES	Real Rhapsody
	FR	Real Rhapsody
	HE	Real Rhapsody
	IT	Real Rhapsody
	NL	Real Rhapsody

RHAPSODY
	DE	Rhapsody
	EN	Rhapsody
	ES	Rhapsody
	FR	Rhapsody
	HE	Rhapsody
	IT	Rhapsody
	NL	Rhapsody

PLUGIN_RHAPSODY_UNSUPPORTED
	DE	Fehler: Rhapsody benötigt SB2 oder neuer
	EN	Error: Rhapsody requires SB2 or higher
	ES	Error: Rhapsody requiere SB2 o posterior
	FR	Erreur: Rhapsody nécessite la SB2 ou version ultérieure.
	HE	שגיאה: עבור Rhapsody יש צורך ב-SB2 ואילך.
	IT	Errore: Rhapsody richiede SB2 o versioni successive
	NL	Fout: Rhapsody vereist SB2 of hoger

PLUGIN_RHAPSODY_ERROR_UNAUTH
	DE	Rhapsody: Unberechtigte Anforderung.
	EN	Rhapsody: Unauthorized request.
	ES	Rhapsody: Solicitud no autorizada.
	FR	Rhapsody: requête non autorisée.
	HE	Rhapsody: בקשה לא מורשית.
	IT	Rhapsody: richiesta non autorizzata.
	NL	Rhapsody: Niet-geautoriseerd verzoek

PLUGIN_RHAPSODY_ERROR_FORBIDDEN
	DE	Rhapsody: Unzulässige Anforderung.
	EN	Rhapsody: Request forbidden.
	ES	Rhapsody: No se permite la solicitud.
	FR	Rhapsody: requête non autorisée.
	HE	Rhapsody: בקשה אסורה.
	IT	Rhapsody: richiesta vietata.
	NL	Rhapsody: Verzoek verboden.

PLUGIN_RHAPSODY_ERROR_FILE_NOT_FOUND
	DE	Rhapsody: Datei nicht gefunden.
	EN	Rhapsody: File not found.
	ES	Rhapsody: No se ha encontrado el archivo.
	FR	Rhapsody: fichier introuvable.
	HE	Rhapsody: הקובץ לא נמצא.
	IT	Rhapsody: file non trovato.
	NL	Rhapsody: Bestand niet gevonden.

PLUGIN_RHAPSODY_ERROR_BUSY
	DE	Rhapsody: Die Anwendung ist ausgelastet.
	EN	Rhapsody: Application is busy.
	ES	Rhapsody: La aplicación está ocupada.
	FR	Rhapsody: application occupée.
	HE	Rhapsody: היישום נמצא בשימוש.
	IT	Rhapsody: l'applicazione è occupata.
	NL	Rhapsody: Toepassing is bezig.

PLUGIN_RHAPSODY_ERROR_STALE
	DE	Rhapsody: Zeitlimit überschritten.
	EN	Rhapsody: Session has timed out.
	ES	Rhapsody: La sesión ha caducado.
	FR	Rhapsody: la session a expiré.
	HE	Rhapsody: פג תוקף ההפעלה.
	IT	Rhapsody: sessione scaduta.
	NL	Rhapsody: Time-out van sessie.

PLUGIN_RHAPSODY_ERROR_INTERNAL
	DE	Rhapsody: Interner Serverfehler, überprüfen Sie Rhapsody.
	EN	Rhapsody: Internal server error, please check the Rhapsody application.
	ES	Rhapsody: Error interno del servidor, compruebe la aplicación Rhapsody.
	FR	Rhapsody: erreur de serveur interne, veuillez vérifier l'application Rhapsody.
	HE	Rhapsody: שגיאה פנימית בשרת, בדוק את היישום Rhapsody.
	IT	Rhapsody: errore interno del server. Controllare l'applicazione Rhapsody.
	NL	Rhapsody: Interne serverfout. Controleer de Rhapsody-toepassing.
";
}

1;


# Local Variables:
# tab-width:4
# indent-tabs-mode:t
# End:
