thewood68 Posted January 25, 2008 Share Posted January 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/ Share on other sites More sharing options...
PHP Monkeh Posted January 25, 2008 Share Posted January 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-448724 Share on other sites More sharing options...
thewood68 Posted January 25, 2008 Author Share Posted January 25, 2008 See that was my thought as well, however on a whim I opened the text file in MS excel and it was divided up perfectly into cells. So if ms excel can figure it out I just assume that there is something that is a give. Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449000 Share on other sites More sharing options...
cooldude832 Posted January 25, 2008 Share Posted January 25, 2008 can u attach a sample of the .txt file odds are its simple enough to do. Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449005 Share on other sites More sharing options...
thewood68 Posted January 25, 2008 Author Share Posted January 25, 2008 sure thing, this is the sample output text. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449029 Share on other sites More sharing options...
GingerRobot Posted January 25, 2008 Share Posted January 25, 2008 Looks tab-delimited to me. Should just be a case of exploding by the tab and extracting the relevant information from the generated array. See: www.php.net/explode The separator will be "\t" Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449064 Share on other sites More sharing options...
cooldude832 Posted January 25, 2008 Share Posted January 25, 2008 try <?php $itunes_file = "textfile.xt"; $data = file_get_contents($itunes_file); $data = explode("\t",$data); print_r($data); ?> See what it does (view the source code to the page not the in browser presentation Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449087 Share on other sites More sharing options...
thewood68 Posted January 25, 2008 Author Share Posted January 25, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449227 Share on other sites More sharing options...
thewood68 Posted January 25, 2008 Author Share Posted January 25, 2008 Ok sorry that last question was dumb because it took me .3 seconds to figure it out. but the question i do have is what would be the best way to grab the song title which if you look above was between [26] and [27] but not actually in its own bracket? Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449230 Share on other sites More sharing options...
cooldude832 Posted January 25, 2008 Share Posted January 25, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449234 Share on other sites More sharing options...
cooldude832 Posted January 25, 2008 Share Posted January 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449235 Share on other sites More sharing options...
thewood68 Posted January 25, 2008 Author Share Posted January 25, 2008 Thank you thnak you thank you. That did it. Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449283 Share on other sites More sharing options...
thewood68 Posted January 26, 2008 Author Share Posted January 26, 2008 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] Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449568 Share on other sites More sharing options...
cooldude832 Posted January 26, 2008 Share Posted January 26, 2008 its an encoding problem based on which computer did it. but I don't see an error other than the name label having a funky character in it. what is wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449570 Share on other sites More sharing options...
thewood68 Posted January 26, 2008 Author Share Posted January 26, 2008 is there a way of addressing this encoding problem? the problem is when i try to print $song_data[$i][Artist], in the different encoding that variable is empty. Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449572 Share on other sites More sharing options...
thewood68 Posted January 26, 2008 Author Share Posted January 26, 2008 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] Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449672 Share on other sites More sharing options...
laffin Posted January 26, 2008 Share Posted January 26, 2008 Most of this info is in the id3 tags of the mp3 already. Which u can retrieve directly. that is if u work exclusively with mp3's. and if u are attached to using the export function Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449714 Share on other sites More sharing options...
thewood68 Posted January 26, 2008 Author Share Posted January 26, 2008 nope not exclusive Quote Link to comment https://forums.phpfreaks.com/topic/87725-trimming-itunes-song-export-list/#findComment-449848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.