Working with iTunesSpy
Declarations
the ony thing you have to declare is the wp_iTunesSpy class if exists
<?php
if (class_exists('wp_iTunesSpy')) {
$iTunesSpy = new wp_iTunesSpy();
}
?>
Sample functions
-
sample 1 - get the last 5 tracks
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getLastTracks(5); if ($tracks) { // The argument sets the amount of tracks you want to display foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); $Out .= $iTunesSpy->getTrackInfo($track->id); } echo $Out; } ?> </ul>
-
sample 2 - get the last 5 tracks (Extended function)
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getLastTracks(5); if ($tracks) { // The argument sets the amount of tracks you want to display foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); // You can also use the other supported variables - listed // on the iTunesSpy homepage - instead of // '%title% - %artist% - %album%' // The arguments: // 1) the track id: without this id you won't be able to get any info // 2) the start-tag // 3) the end-tag // 4) the schema-tag: here you put all the variables... // $Out .= $iTunesSpy->getTrackInfoEx($track->id, '<li>', '</li>', '%title% - %artist% - %album%'); } echo $Out; } ?> </ul>
-
sample 3 - get the album covers of last 5 tracks
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getLastTracks(5); if ($tracks) { foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); // we use the variable %art% to get the album cover $Out .= $iTunesSpy->getTrackInfoEx($track->id, '<li>', '</li>', '%art%'); } echo $Out; } ?> </ul>
-
sample 4 - get extended info for the last 5 tracks
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getLastTracks(5); if ($tracks) { foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); $Out .= '<li>'; $schema = ''; //Clear the variable $schema .= '%art%'; $schema .= '<ul>'; $schema .= '<li>title: %title%</li>'; $schema .= '<li>artist: %artist%</li>'; $schema .= '<li>artist: %artist%</li>'; $schema .= '<li>composer: %composer%</li>'; $schema .= '<li>genre: %genre%</li>'; $schema .= '<li>year: %year%</li>'; $schema .= '<li>time: %time%</li>'; $schema .= '<li>count: %count%</li>'; $schema .= '<li>file: %file%</li>'; $schema .= '<li>bitrate: %bitrate%</li>'; $schema .= '<li>rating: %rating%</li>'; $lastplayed = $iTunesSpy->getTrackLastPlayTime($track->id); $schema .= '<li>last played: ' . date($iTunesSpy->date_time_format, $lastplayed->date+(3600 * $iTunesSpy->gmt_offset)) . '</li>'; $schema .= '<li>played ' . $iTunesSpy->getTrackPlayTimesCount($track->id) . ' time(s)</li>'; $schema .= '<ul>'; $playtimes = $iTunesSpy->getTrackPlayTimes($track->id); $out_playtimes = ''; //Clear the variable foreach ($playtimes as $playtime) { $out_playtimes .= '<li>' . date($iTunesSpy->date_time_format, $playtime->date+(3600 * $iTunesSpy->gmt_offset)) . '</li>'; } $schema .= $out_playtimes; $schema .= '<ul>'; $schema .= '<ul>'; $schema .= '</li>'; $Out .= $iTunesSpy->getTrackInfoEx($track->id, '', '', $schema); } echo $Out; } ?> </ul>
-
sample 5 - get the last 5 tracks + resize cover art image
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getLastTracks(5); if ($tracks) { foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); // set the width attribute to 60px... // edit the width attribute for different image sizes $Out .= $iTunesSpy->getTrackArtEx($track->art_id, '<img ', ' />', 'src="%art_small_url%" width="60px" alt=""'); } echo $Out; } ?> </ul>
-
sample 6 - get 5 random tracks
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getRandomTracks(5); if ($tracks) { foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); $Out .= $iTunesSpy->getTrackInfo($track->id); } echo $Out; } ?> </ul>
-
<ul> <?php $Out = ''; //Clear the variable $tracks = $iTunesSpy->getLastTracks(5); if ($tracks) { foreach ($tracks as $track) { // load the track data into the variable $track = $iTunesSpy->getTrack($track->id); $Out .= $iTunesSpy->getTrackInfoEx($track->id, '<li>', '</li>', '<a href="%link_amazon_partner%">%title% - %artist% - %album%</a>'); } echo $Out; } ?> </ul>
Add tracks to posts
To add tracks to posts you have to do the following:
- Install iTunesSpy version 2.1.9 or higher
- Download, install and activate the PHPExec plugin from priyadi.net
- Now insert the following code snippet into every post where you want to display the tracks
<phpcode> <?php if (class_exists('wp_iTunesSpy_Hacks')) { $Hacks = new wp_iTunesSpy_Hacks(); echo $Hacks->getTodaysTracks2Post(); } ?> </phpcode>Note: The displayed tracks depend on the timestamp of the post.
This means that the track has to be played on the day the post was published.
Cover-Rotation
If you want to display the covers with the flash cover-rotator then you have to use the following code:
(Watch out: The following lines of code have line breaks due to better readability. Remove these line breaks because otherwise the code isn't functional at all)
<?php $url = parse_url(get_settings('siteurl')); ?>
<object type="application/x-shockwave-flash" width="160" height="160"
bgcolor="#EEEEEE" data="<?= $url['path'] . '/wp-content/plugins/
wp-itunesspy/pages/cover-rotation/' ?>rotator.swf?file=
<?= rawurlencode($url['path'] . '/?itunesspy=pages&itunesspy_page=
cover-rotation/covers.php') ?>">
<param name="movie" value="<?= $url['path'] .
'/wp-content/plugins/wp-itunesspy/pages/cover-rotation/' ?>
rotator.swf?file=<?= rawurlencode($url['path'] .
'/?itunesspy=pages&itunesspy_page=cover-rotation/covers.php') ?>" />
<param name="bgcolor" value="#EEEEEE" />
</object>
Insert custom covers
If you want to display covers of an album where no info is available from amazon you have the posibillity to link your own covers!
Simply select the desired Track in the management screen and click on the 'x' (or 'Add') in the 'Artwork'-column.
Then just insert the urls to your covers.
That's it!
Variables
The variables in iTunesSpy must have a %-char before the variale name and after it. For example if you want to display the 'title' value you have to use %title%.
Variables in version 2.1 and above
| variable | description |
|---|---|
| id | the track's unique id |
| art_id | identifies the cover in the artcache table in the database |
| title | the track's title |
| artist | the track's artist |
| album | the track's album |
| composer | the track's composer |
| genre | the track's genre |
| year | release year |
| time | lenght of the track |
| count | how often the track was played in iTunes |
| file | the filename (e.g. song.mp3) |
| bitrate | bitrate of the track |
| rating | the rating in iTunes |
| art | returns the album cover as image e.g. <img src="..." alt=""> |
| art_small | like 'art' but small cover |
| art_medium | like 'art' but medium cover |
| art_large | like 'art' but large cover |
| link_itunes | returns the iTunes MusicStore link |
| link_amazon_partner | returns the Amazon associate link |
| link_amazon | returns the Amazon link |
| link_lyrics | returns the Lyrics link |
| link_google | returns the Google link |
| art_link_itunes | returns the album cover with the iTunes MusicStore link |
| art_link_itunes_small | like 'art_link_itunes' but small cover |
| art_link_itunes_medium | like 'art_link_itunes' but medium cover |
| art_link_itunes_large | like 'art_link_itunes' but large cover |
| art_link_lyrics | returns the album cover with the Lyrics link |
| art_link_lyrics_small | like 'art_link_lyrics' but small cover |
| art_link_lyrics_medium | like 'art_link_lyrics' but medium cover |
| art_link_lyrics_large | like 'art_link_lyrics' but large cover |
| art_link_amazon | returns the album cover with the Amazon link |
| art_link_amazon_small | like 'art_link_amazon' but small cover |
| art_link_amazon_medium | like 'art_link_amazon' but medium cover |
| art_link_amazon_large | like 'art_link_amazon' but large cover |
| art_link_amazon_partner | returns the album cover with the Amazon associate link |
| art_link_amazon_partner_small | like 'art_link_amazon_partner' but small cover |
| art_link_amazon_partner_medium | like 'art_link_amazon_partner' but medium cover |
| art_link_amazon_partner_large | like 'art_link_amazon_partner' but large cover |
| art_link_google | returns the album cover with the Google link |
| art_link_google_small | like 'art_link_google' but small cover |
| art_link_google_medium | like 'art_link_google' but medium cover |
| art_link_google_large | like 'art_link_google' but large cover |
Step by Step - Get iTunesSpy working with your theme...
-
Open the sidebar.php of your current theme - you can find it in the '<worpress>/wp-content/themes/<current theme>/'-folder - in an editor like notepad or dreamweaver.
-
Decide where you want to display the iTunesSpy output.
- Insert the appropriate php code and declarations...
- First of all check if the class 'wp_iTunesSpy' is available - otherwise the iTunesSpy plugin is disabled.
- Then insert a new sidebar section
- And now insert the php code from e.g. sample 1
-
And here is the result...
iTunesSpy and the WordPress Widgets
iTunesSpy now supports the WordPress Widgets functionality!
So you can display your iTunes tracks also in your sidebar using the 'widgets' plugin. (Only if your theme supports widgets!)
To do that just activate the 'iTunesSpy SidebarWidget' plugin and drag-drop the iTunesSpy widget onto your sidebar.
If you want to edit the iTunesSpy output just edit the 'wp-itunesspySidebarWidgetContents.php' file in the iTunesSpy directory.
Note: The widget functionality is not officially supported!!!! So please send support questions concerning the widget at all!
