iTunes2 is a Library.export viewer for the popular iTunes (version 2) music player created by Apple computers. It reads the entire file into an array and then cycles through each line of the file to extract wanted information.
Support is included to convert time (in seconds) to a more readable format (minutes:seconds), as well as export file size, genere, bit and sample rates, and track numbers. Optional headers/footers can be set by un-commenting the appropriate lines.
By : RobertDX
<?php
// Name: iTunes 2
// Author: Robert Baird
/* Description:
iTunes2 is a Library.export viewer for the popular iTunes (version 2)
music player created by Apple computers. It reads the entire file into
an array and then cycles through each line of the file to extract
wanted information. It take awhile to execute on slower systems or
with large music libraries.
The script is designed to work with the playlist being grouped by
"Artists", although it will work otherwise, just not as intended.
Support is included to convert time (in seconds) to a more readable
format (minutes:seconds), as well as export file size, genere, bit and
sample rates, and track numbers. Optional headers/footers can be set by
un-commenting the appropriate lines.
Trademarked names such as Apple computers and iTunes are held by Apple
Computers, code is copyrighted by Robert Baird.
*/
// set the location of your exported library
$filepath = "/home/user/Library.export";
// set the URI of the script on your server
$scripturl = "http://domain.host/itunes2.php";
// include an optional header file if you wish
// include("/home/user/public_html/include/header.php.inc");
// read the file into an array named $readfile
$readfile = file($filepath);
// *** working backwards, if the user has selected both
// an artist and a song, display the info for that song
if ($song && $artist) {
// start a for loop the cycles through the entire file line by line
for ($k=1; $k<=count($readfile)-1; $k++) {
// split each line into a sepearte array $fields
$fields = split("\t",$readfile[$k]);
// when we get to the line that matches the song we want this
// if loop trips and displays the song info
if (($artist == $fields[1]) && ($song == $fields[0])) {
// time conversion, seconds -> minutes:seconds
// I couldn't find any easier ways to do this
$minutes = floor(($fields[5] / 60));
$seconds = round(($fields[5] - ($minutes * 60)), 0);
if (strlen($seconds) == 1) { $seconds = "0". $seconds; }
// format the filesize value from bytes -> kb
$size = round(($fields[4]/1024),2);
// expore the data, this is all customizable
print("
Song - $fields[0]<br>
Artist - $fields[1]<br>
Album - $fields[2]<br>
Genre - $fields[3]<br>
Size - $size K<br>
Time - $minutes:$seconds<br>
Track - $fields[6]/$fields[7]<br>
Date - $fields[9]<br>
Date Added - $fields[10]<br>
Bit Rate - $fields[11]<br>
Sample Rate - $fields[12]<br>
Volume Adjustment - $fields[13]<br>
Kind - $fields[14]<br>
Comments - $fields[15]<br>
"); }
}
}
// *** continueing to work backwards, if no song has been selected, but
// but an artist has, display all songs by that particular artist
elseif ($artist) {
// start a for loop the cycles through the entire file line by line
for ($k=1; $k<=count($readfile)-1; $k++) {
// split each line into a sepearte array $fields
$fields = split("\t",$readfile[$k]);
// when we find a line that matches the artist we want this if conditional
// trips and prints out a link to the song's info
if ($artist == $fields[1]) {
print("<a href=\"$scripturl?artist=$fields[1]&song=$fields[0]\">$fields[0]<br>");
}
}
}
// *** continueing to work backwards, if no song has been selected, and
// and no artist has been selected, we need to print out a list of artists
else {
// the $last variable is used within the next for loop, basically, we look at
// each line in file and group them together. the first song in the list is
// displayed because it does not match "101668871488" (probably)
$last = "101668871488";
// start a for loop the cycles through the entire file line by line
for ($k=1; $k<=count($readfile)-1; $k++) {
// split each line into a sepearte array $fields
$fields = split("\t",$readfile[$k]);
// print out the artists name with a link to all of their songs
if ($last != $fields[1]) {
print("<a href=\"$scripturl?artist=$fields[1]\">$fields[1]</a><br>"); }
// this is the trick, at the end of the for loop, we reset $last to this
// particular artist. any of the next songs that have the name of $last
// will be skipped until we get to a new artist
$last = $fields[1];
}
}
// include an optional footer file if you wish
// include("/home/user/public_html/include/footer.inc.php");
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
|
|
|
|
This paper is about the critical role that a discipline called integrated requirements management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrating, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |