Miscellaneous Code

  Home arrow Miscellaneous Code arrow iTunes2
MISCELLANEOUS CODE

iTunes2
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-06-15

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    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

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap