Jump to content

trimming itunes song export list


thewood68

Recommended Posts

for those of you who are familiar with itunes, if you export the song list into a .txt file it prints tons of extra trash as well... so basically heres what i want to happen and any help would be VERY appreciated.

 

Below is a single line out of the text file when exported. I want to read the .txt file with php and then trim it so all I am left with are the first two items (song title, artist). However with all artists and song names being different I cant trim based on characters. Thanks Again

 

Current Output:

Green & Grey Nickel Creek This Side Bluegrass 3476627 217 7 4/14/2007 3:32 PM 4/10/2007 12:26 AM 128 44100 MPEG audio file 53 1/10/2008 11:12 PM C:\Documents and Settings\Mike\Shared\Nickel Creek - Green and Gray.mp3

Desired Output:

Green & Grey

Nickel Creek

Link to comment
https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/
Share on other sites

The problem that I can see with trying to do that is, is that there's nothing really for you to split the records up by.  If there was say a | in between each field it would be really simple to do, but considering there's just a space (and there can be spaces in the song / artists name too) there's nothing (that I can see) which you'd be able to tell where one starts and one ends.

ok the explode worked perfectly and i know this is a trivial question and i think i could figure it out in an hour or two but i just want to save the headache, could someone explain how i can grab just a piece of the array?

 

I want to grab brackets 27 and the song title which is not in a bracket.

 

Current Output, with code provided by cooldude:

 

 

Array

(

    [0] => Name

    [1] => Artist

    [2] => Composer

    [3] => Album

    [4] => Grouping

    [5] => Genre

    [6] => Size

    [7] => Time

    [8] => Disc Number

    [9] => Disc Count

    [10] => Track Number

    [11] => Track Count

    [12] => Year

    [13] => Date Modified

    [14] => Date Added

    [15] => Bit Rate

    [16] => Sample Rate

    [17] => Volume Adjustment

    [18] => Kind

    [19] => Equalizer

    [20] => Comments

    [21] => Play Count

    [22] => Last Played

    [23] => Skip Count

    [24] => Last Skipped

    [25] => My Rating

    [26] => Location

Green & Grey

    [27] => Nickel Creek

    [28] =>

    [29] => This Side

    [30] =>

    [31] => Bluegrass

    [32] => 3476627

    [33] => 217

    [34] =>

    [35] =>

    [36] => 7

    [37] =>

    [38] =>

    [39] => 4/14/2007 3:32 PM

    [40] => 4/10/2007 12:26 AM

    [41] => 128

    [42] => 44100

    [43] =>

    [44] => MPEG audio file

    [45] =>

    [46] =>

    [47] => 53

    [48] => 1/10/2008 11:12 PM

    [49] =>

    [50] =>

    [51] =>

    [52] => C:\Documents and Settings\Mike\Shared\Nickel Creek - Green and Gray.mp3

 

)

 

 

this look good try it on a bigger list

<?php
$itunes_file = "Music.txt";
$data = file_get_contents($itunes_file);
$data = explode("\n",$data);
$labels = array();
$temp =  explode("\t",$data[0]);
$i = 0;
#Builds the text labels for fields based on the first row
foreach($temp as $value){
$labels[$i] = $value;
$i++;
}
unset($temp);
array_pop($data);  #The last one was empty
for($i = 1; $i <count($data); $i++){
$temp = explode("\t",$data[$i]);
$j = 0;
foreach($temp as $value){
	$song_data[$i][$labels[$j]] = $value;
	$j++;
}
}
print_r($song_data);

?>

this look good try it on a bigger list

<?php
$itunes_file = "Music.txt";
$data = file_get_contents($itunes_file);
$data = explode("\n",$data);
$labels = array();
$temp =  explode("\t",$data[0]);
$i = 0;
#Builds the text labels for fields based on the first row
foreach($temp as $value){
$labels[$i] = $value;
$i++;
}
unset($temp);
array_pop($data);  #The last one was empty
for($i = 1; $i <count($data); $i++){
$temp = explode("\t",$data[$i]);
$j = 0;
foreach($temp as $value){
	$song_data[$i][$labels[$j]] = $value;
	$j++;
}
}
print_r($song_data);

?>

 

produces

 

http://pira00.worldispnetwork.com/itunes.php

Ok running into a problem. I got everything running on my laptop but then i went and tested it on a different laptop and it didnt work correctly. I ran an output from my itunes "Music2.txt" and I ran an output on his computer "Music.txt". When looking at the two .txt files side by side I cannot find any differences. Thanks for the help.

 

Output from working "Music2.txt"

 

    [1] => Array

        (

            [Name] => Tuesday Night

            [Artist] => Adam Hood

            [Composer] => A. Hood

            [Album] => 6th Street

            [Grouping] =>

            [Genre] => Rock

            => 4605952

            [Time] => 190

            [Disc Number] =>

            [Disc Count] =>

            [Track Number] => 1

            [Track Count] =>

            [Year] => 2004

            [Date Modified] => 9/19/2006 11:56 PM

            [Date Added] => 8/23/2006 1:54 AM

            [bit Rate] => 192

            [sample Rate] => 44100

            [Volume Adjustment] =>

            [Kind] => MPEG audio file

            [Equalizer] =>

            [Comments] =>                           

            [Play Count] => 35

            [Last Played] => 10/21/2007 4:51 PM

            [skip Count] =>

            [Last Skipped] =>

            [My Rating] =>

            [Location

] => C:\Documents and Settings\All Users\Documents\My Music\Sample Music\ah.tuesday.night.192.mp3

        )

 

Output from Non-Working

 

[1] => Array

        (

            [ÿþN a m e ] =>  T u e s d a y  N i g h t

            [ A r t i s t ] =>  A d a m  H o o d

            [ C o m p o s e r ] =>  A .  H o o d

            [ A l b u m ] =>  6 t h  S t r e e t

            [ G r o u p i n g ] => 

            [ G e n r e ] =>  R o c k

            [ S i z e ] =>  4 6 0 5 9 5 2

            [ T i m e ] =>  1 9 0

            [ D i s c  N u m b e r ] => 

            [ D i s c  C o u n t ] => 

            [ T r a c k  N u m b e r ] =>  1

            [ T r a c k  C o u n t ] => 

            [ Y e a r ] =>  2 0 0 4

            [ D a t e  M o d i f i e d ] =>  1 2 / 2 3 / 2 0 0 6  6 : 3 7  P M

            [ D a t e  A d d e d ] =>  8 / 2 6 / 2 0 0 7  4 : 3 4  P M

            [ B i t  R a t e ] =>  1 9 2

            [ S a m p l e  R a t e ] =>  4 4 1 0 0

            [ V o l u m e  A d j u s t m e n t ] => 

            [ K i n d ] =>  M P E G  a u d i o  f i l e

            [ E q u a l i z e r ] => 

            [ C o m m e n t s ] =>                                                         

            [ P l a y  C o u n t ] =>  2

            [ L a s t  P l a y e d ] =>  1 2 / 1 0 / 2 0 0 7  8 : 0 0  P M

            [ S k i p  C o u n t ] =>  3

            [ L a s t  S k i p p e d ] =>  1 / 2 0 / 2 0 0 8  9 : 3 0  P M

            [ M y  R a t i n g ] => 

            [ L o c a t i o n

] =>  C : \ D o c u m e n t s  a n d  S e t t i n g s \ A l l  U s e r s \ D o c u m e n t s \ M y  M u s i c \ S a m p l e  M u s i c \ a h . t u e s d a y . n i g h t . 1 9 2 . m p 3

 

        )

 

[attachment deleted by admin]

for compatibilty purposes i've decided to go from using .txt files to using .xml files. again theres so much extra information with the export that i need to get rid of it all and only keep the title of the song and artist name. i attached a sample output .xml file. thanks in advance!

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.