[Slim-Checkins] r33950 - in /7.8/trunk: ./ server/Changelog7.html server/Slim/Plugin/RadioTime/Metadata.pm server/Slim/Plugin/RadioTime/Plugin.pm server/strings.txt

[email protected] Wed, 25 Apr 2012 12:17:35 -0000
Newsgroups gmane.music.equipment.slimdevices.cvs
Message-ID <[email protected]>
Author: agrundman
Date: Wed Apr 25 05:17:35 2012
New Revision: 33950

URL: http://svn.slimdevices.com/slim?rev=33950&view=rev
Log:
 r81012@macbookpro (orig r33940):  mherger | 2012-04-19 05:37:17 -0400
 Bug: n/a
 Description: add support for TuneIn Radio artwork
 r81013@macbookpro (orig r33941):  mherger | 2012-04-19 08:10:10 -0400
 Bug: n/a
 Description: station logo needs to be stored in the song object, not the player, or it would survive station changes.
 r81014@macbookpro (orig r33942):  mherger | 2012-04-19 08:37:23 -0400
 Bug: n/a
 Description: no need to deal with the $song object unless we have a station logo. Store the same in the client object as well, for simpler access.
 r81015@macbookpro (orig r33943):  mherger | 2012-04-19 09:53:38 -0400
 Bug: n/a
 Description: It's just Radio, not Internet Radio
 r81016@macbookpro (orig r33944):  mherger | 2012-04-19 10:03:14 -0400
 Bug: n/a
 Description: fix EN localization...
 r81017@macbookpro (orig r33945):  mherger | 2012-04-19 10:04:00 -0400
 Bug: n/a
 Description: fix Russian
 r81021@macbookpro (orig r33949):  mherger | 2012-04-25 03:42:25 -0400
 Bug: n/a
 Description: if TuneIn stream comes with ICY metadata, only look for artwork if it's not part of that tag (eg. Radio Paradise)

Modified:
    7.8/trunk/   (props changed)
    7.8/trunk/server/Changelog7.html
    7.8/trunk/server/Slim/Plugin/RadioTime/Metadata.pm
    7.8/trunk/server/Slim/Plugin/RadioTime/Plugin.pm
    7.8/trunk/server/strings.txt

Propchange: 7.8/trunk/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Wed Apr 25 05:17:35 2012
@@ -25,7 +25,7 @@
 60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/7.5/trunk:32834
 60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/7.6/branches/onebrowser:32502
 60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/7.6/trunk:33593
-60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/7.7/trunk:33913
+60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/7.7/trunk:33949
 60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/branches/7.0:17793
 60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/branches/cometd-refactor:13305
 60ad55ce-86ed-0310-8cf8-f9d879be5ea1:/private-branches/ray-svk:15970

Modified: 7.8/trunk/server/Changelog7.html
URL: http://svn.slimdevices.com/slim/7.8/trunk/server/Changelog7.html?rev=33950&r1=33949&r2=33950&view=diff
==============================================================================
--- 7.8/trunk/server/Changelog7.html (original)
+++ 7.8/trunk/server/Changelog7.html Wed Apr 25 05:17:35 2012
@@ -26,6 +26,7 @@
 <ul>
 	<li>Server Changes:</li>
 	<ul>
+		<li>Improved support for radio station artwork. Improved radio station browsing.</li>
 		<li>Remove legacy Napster plugin. Napster now is a Rhapsody company.</li>
 	</ul>
 	<br />

Modified: 7.8/trunk/server/Slim/Plugin/RadioTime/Metadata.pm
URL: http://svn.slimdevices.com/slim/7.8/trunk/server/Slim/Plugin/RadioTime/Metadata.pm?rev=33950&r1=33949&r2=33950&view=diff
==============================================================================
--- 7.8/trunk/server/Slim/Plugin/RadioTime/Metadata.pm (original)
+++ 7.8/trunk/server/Slim/Plugin/RadioTime/Metadata.pm Wed Apr 25 05:17:35 2012
@@ -8,6 +8,8 @@
 use Slim::Formats::XML;
 use Slim::Music::Info;
 use Slim::Networking::SimpleAsyncHTTP;
+use Slim::Plugin::RadioTime::Plugin;
+use Slim::Utils::Cache;
 use Slim::Utils::Log;
 use Slim::Utils::Prefs;
 
@@ -16,7 +18,9 @@
 my $log   = logger('formats.metadata');
 my $prefs = preferences('plugin.radiotime');
 
-use constant META_URL => 'http://opml.radiotime.com/NowPlaying.aspx?partnerId=16';
+use constant PARTNER_ID => 16;
+use constant META_URL   => 'http://opml.radiotime.com/NowPlaying.aspx?partnerId=' . PARTNER_ID;
+use constant CONFIG_URL => 'http://opml.radiotime.com/Config.ashx?c=api&partnerId=' . PARTNER_ID . '&serial=';
 
 my $ICON = Slim::Plugin::RadioTime::Plugin->_pluginDataFor('icon');
 
@@ -32,6 +36,48 @@
 		match => qr/(?:radiotime|tunein)\.com/,
 		func  => \&provider,
 	);
+}
+
+sub getConfig {
+	my $client = shift;
+	
+	Slim::Utils::Timers::killTimers( $client, \&getConfig );
+	
+	my $http = Slim::Networking::SimpleAsyncHTTP->new(
+		\&_gotConfig,
+		\&_gotConfig, # TODO - error handler
+		{
+			client  => $client,
+			timeout => 30,
+		},
+	);
+	
+	Slim::Utils::Timers::setTimer(
+		$client,
+		time() + 60*60*23,	# repeat at least every 24h
+		\&getConfig,
+	);
+
+	$http->get( CONFIG_URL . Slim::Plugin::RadioTime::Plugin->getSerial($client) );
+}
+
+sub _gotConfig {
+	my $http   = shift;
+	my $client = $http->params('client');
+	
+	my $feed = eval { Slim::Formats::XML::parseXMLIntoFeed( $http->contentRef ) };
+
+	if ( $@ ) {
+		main::DEBUGLOG && $log->debug( "Error fetching TuneIn artwork configuration: $@" );
+	}
+	elsif ( $feed && $feed->{items} && (my $config = $feed->{items}->[0]) ) {
+		if ( (my $lookup = $config->{'albumart.lookupurl'}) && (my $url = $config->{'albumart.url'}) ) {
+			$client->pluginData( artworkConfig => {
+				lookupurl   => $lookup,
+				albumarturl => $url,
+			} );
+		}
+	}
 }
 
 sub defaultMeta {
@@ -47,6 +93,10 @@
 sub parser {
 	my ( $client, $url, $metadata ) = @_;
 	
+	if ( $client && !$client->pluginData('artworkConfig') ) {
+		getConfig($client);
+	}
+
 	# If a station is providing Icy metadata, disable metadata
 	# provided by RadioTime
 	if ( $metadata =~ /StreamTitle=\'([^']+)\'/ ) {
@@ -57,6 +107,18 @@
 				Slim::Utils::Timers::killTimers( $client, \&fetchMetadata );
 				$client->master->pluginData( metadata => undef );
 			}
+
+			# Check for an image URL in the metadata.
+			my $artworkUrl;
+			if ( $metadata =~ /StreamUrl=\'([^']+)\'/ ) {
+				$artworkUrl = $1;
+				if ( $artworkUrl !~ /\.(?:jpe?g|gif|png)$/i ) {
+					$artworkUrl = undef;
+				}
+			}
+
+			# lookup artwork unless it's been defined in the metadata (eg. Radio Paradise)
+			fetchArtwork($client, $url, 'delayed') unless $artworkUrl;
 			
 			# Let the default metadata handler process the Icy metadata
 			$client->master->pluginData( hasIcy => $url );
@@ -73,6 +135,8 @@
 			Slim::Utils::Timers::killTimers( $client, \&fetchMetadata );
 			$client->master->pluginData( metadata => undef );
 		}
+
+		fetchArtwork($client, $url, 'delayed');
 		
 		# Let the default metadata handler process the WMA metadata
 		$client->master->pluginData( hasIcy => $url );
@@ -216,12 +280,7 @@
 	
 	# Also cache the image URL in case the stream has other metadata
 	if ( $meta->{cover} ) {
-		my $cache = Slim::Utils::Cache->new();
-		$cache->set( "remote_image_$url" => $meta->{cover}, 86400 * 7 );
-
-		if ( my $song = $client->playingSong() ) {
-			$song->pluginData( httpCover => $meta->{cover} );
-		}
+		setArtwork($client, $url, $meta->{cover});
 	}
 	
 	if ( main::DEBUGLOG && $log->is_debug ) {
@@ -229,6 +288,8 @@
 	}
 	
 	$client->master->pluginData( metadata => $meta );
+	
+	fetchArtwork($client, $url);
 	
 	main::DEBUGLOG && $log->is_debug && $log->debug( "Will check metadata again in $ttl seconds" );
 	
@@ -258,4 +319,129 @@
 	$client->master->pluginData( metadata => $meta );
 }
 
+
+sub fetchArtwork {
+	my ($client, $url, $delayed) = @_;
+	
+	main::DEBUGLOG && $log->debug( "Getting artwork for $url" );
+	
+	Slim::Utils::Timers::killTimers( $client, \&_fetchArtwork );
+
+	if ($delayed) {
+		$delayed = Slim::Music::Info::getStreamDelay($client);
+
+		# if the stream has ICY metadata, give it a moment to parse it
+		Slim::Utils::Timers::setTimer(
+			$client,
+			time() + $delayed + 1,
+			\&_fetchArtwork,
+			$url
+		);
+	}
+	else {
+		_fetchArtwork($client, $url);
+	}
+}
+
+sub _fetchArtwork {
+	my ( $client, $url ) = @_;
+	
+	my $config  = $client->pluginData('artworkConfig') || return;
+	my $handler = Slim::Player::ProtocolHandlers->handlerForURL($url);
+
+	if ( $handler && $handler->can('getMetadataFor') ) {
+		my $track = $handler->getMetadataFor( $client, $url );
+
+		main::DEBUGLOG && $log->debug( 'Getting TuneIn artwork based on metadata:', Data::Dump::dump($track) );
+		
+		# keep track of the station logo in case we don't get track artwork
+		#                                             [ps] => podcast or station
+		#                                                     t => Thumbnail
+		#                                                      q => sQuare
+		#                                                       g => Giant
+		#                                                        d => meDium
+		if ( $track->{cover} && $track->{cover} =~ m{/[ps]\d+[tqgd]\.(?:jpg|jpeg|png|gif)$}i && (my $song = $client->playingSong()) ) {
+			if ( !$song->pluginData('stationLogo') ) {
+				main::DEBUGLOG && $log->debug( 'Storing default station artwork: ' . $track->{cover} );
+				
+				$song->pluginData( stationLogo => $track->{cover} );
+				$client->pluginData( stationLogo => $track->{cover} );
+			}
+		}
+		
+		if ( $track && $track->{title} && $track->{artist} ) {
+			
+			my $lookupurl = sprintf($config->{lookupurl} . '?partnerId=%s&serial=%s&artist=%s&title=%s',
+				PARTNER_ID,
+				Slim::Plugin::RadioTime::Plugin->getSerial($client),
+				$track->{artist},
+				$track->{title},
+			);
+			
+			return if $client->master->pluginData('fetchingArtwork') && $client->master->pluginData('fetchingArtwork') eq $lookupurl;
+			
+			$client->master->pluginData( fetchingArtwork => $lookupurl );
+	
+			my $http = Slim::Networking::SimpleAsyncHTTP->new(
+				\&_gotArtwork,
+				\&_gotArtwork, # we'll happily fall back to the station artwork if we fail
+				{
+					client     => $client,
+					url        => $url,
+					timeout    => 30,
+				},
+			);
+			
+			$http->get( $lookupurl );
+		}
+		# fallback to station artwork
+		elsif ( my $artworkUrl = $client->pluginData('stationLogo') ) {
+			setArtwork($client, $url, $artworkUrl);
+		}
+	}
+}
+
+sub _gotArtwork {
+	my $http   = shift;
+	my $client = $http->params('client');
+	my $url    = $http->params('url');
+	
+	$client->master->pluginData( fetchingArtwork => 0 );
+
+	my $feed = eval { Slim::Formats::XML::parseXMLIntoFeed( $http->contentRef ) };
+	
+	if ( $@ || !$feed ) {
+		main::DEBUGLOG && $log->debug( "Error fetching TuneIn artwork: $@" );
+	}
+	else  {
+		main::DEBUGLOG && $log->debug( 'Received TuneIn track artwork information: ', Data::Dump::dump($feed) );
+	}
+	
+	if ( $feed && $feed->{items} && $feed->{items}->[0] && (my $key = $feed->{items}->[0]->{album_art} || $feed->{items}->[0]->{artist_art}) ) {
+		my $config = $client->pluginData('artworkConfig');
+		# grab "g"iant artwork
+		my $artworkUrl = $config->{albumarturl} . $key . 'g.jpg';
+		
+		setArtwork($client, $url, $artworkUrl);
+	}
+	# fallback to station artwork
+	elsif ( my $artworkUrl = $client->pluginData('stationLogo') ) {
+		setArtwork($client, $url, $artworkUrl);
+	}
+}
+
+sub setArtwork {
+	my ($client, $url, $artworkUrl) = @_;
+			
+	my $cache = Slim::Utils::Cache->new();
+	$cache->set( "remote_image_$url", $artworkUrl, 3600 );
+	
+	if ( my $song = $client->playingSong() ) {
+		$song->pluginData( httpCover => $artworkUrl );
+
+		main::DEBUGLOG && $log->debug("Updating stream artwork to $artworkUrl");
+		Slim::Control::Request::notifyFromArray( $client, [ 'newmetadata' ] );
+	}
+}
+
 1;

Modified: 7.8/trunk/server/Slim/Plugin/RadioTime/Plugin.pm
URL: http://svn.slimdevices.com/slim/7.8/trunk/server/Slim/Plugin/RadioTime/Plugin.pm?rev=33950&r1=33949&r2=33950&view=diff
==============================================================================
--- 7.8/trunk/server/Slim/Plugin/RadioTime/Plugin.pm (original)
+++ 7.8/trunk/server/Slim/Plugin/RadioTime/Plugin.pm Wed Apr 25 05:17:35 2012
@@ -59,7 +59,7 @@
 	
 	# Bug 15569, special case for RadioTime stations, use their trackinfo menu
 	my $rtinfo = URI->new($url)->query_form_hash;
-	my $serial = Digest::MD5::md5_hex( $client->uuid || $client->id );
+	my $serial = $class->getSerial($client);
 	
 	my $uri = URI->new('http://opml.radiotime.com/Options.ashx');
 	$uri->query_form( id => $rtinfo->{id}, partnerId => $rtinfo->{partnerId}, serial => $serial );
@@ -67,4 +67,11 @@
 	return $uri->as_string;
 }
 
+sub getSerial {
+	my ( $class, $client ) = @_;
+
+	return '' unless $client;
+	return Digest::MD5::md5_hex( $client->uuid || $client->id );
+}
+
 1;

Modified: 7.8/trunk/server/strings.txt
URL: http://svn.slimdevices.com/slim/7.8/trunk/server/strings.txt?rev=33950&r1=33949&r2=33950&view=diff
==============================================================================
--- 7.8/trunk/server/strings.txt (original)
+++ 7.8/trunk/server/strings.txt Wed Apr 25 05:17:35 2012
@@ -616,22 +616,19 @@
 	ZH_CN	屏幕保护程序
 
 RADIO
-	CS	Internetové rádio
-	DA	Internetradio
-	DE	Internetradio
-	EN	Internet Radio
-	ES	Radio por Internet
-	FI	Nettiradio
-	FR	Radio Internet
-	HE	רדיו באינטרנט
-	IT	Radio Internet
-	JA	インターネットラジオ
-	NL	Internetradio
-	NO	Internett-radio
-	PL	Radio internetowe
-	RU	Радиостанции Интернета
-	SV	Webbradio
-	ZH_CN	互联网收音机
+	CS	Rádio
+	DA	Radio
+	DE	Radio
+	EN	Radio
+	ES	Radio
+	FI	Radio
+	FR	Radio
+	IT	Radio
+	NL	Radio
+	NO	Radio
+	PL	Radio
+	RU	Радиостанции
+	SV	Radio
 
 MUSIC_SERVICES
 	CS	Hudební služby
@@ -23426,19 +23423,19 @@
 	SV	Bläddra till Våra favoriter och tryck på mittenknappen.
 
 INTERNET_RADIO
-	CS	Internetové rádio
-	DA	Internetradio
-	DE	Internetradio
-	EN	Internet Radio
-	ES	Radio por Internet
-	FI	Nettiradio
-	FR	Radio Internet
-	IT	Radio Internet
-	NL	Internetradio
-	NO	Internett-radio
-	PL	Radio internetowe
-	RU	Радиостанции Интернета
-	SV	Webbradio
+	CS	Rádio
+	DA	Radio
+	DE	Radio
+	EN	Radio
+	ES	Radio
+	FI	Radio
+	FR	Radio
+	IT	Radio
+	NL	Radio
+	NO	Radio
+	PL	Radio
+	RU	Радиостанции
+	SV	Radio
 
 HOWTO_INTERNET_RADIO
 	CS	Rolujte na "Best of Internet Radio" a stiskněte tlačítko DOPRAVA.

_______________________________________________
checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/checkins