Hey

I have a problem that annoys me a lot....

i want to extract all titles and songnames within a file, a *.pls file to be exact.

ive read the entire file from beginning to end and ive splitted the text like so..

string[] titles = readpls.Split(new string[] { @"\n", "\\"}, StringSplitOptions.None);

where readpls is the file being read...

now it looks like this for example:

"al twisted and dj jfx feat vicky fee - turn it up.mp3\r\n#extinf:328,al twisted and jfx - raise the roof\r\n"

i want the result to only be the title or song.....namely "ai twisted" on titles and "turn it up" on songs....

would make another string array for songs also. Question is: how do i search for all titles and song names? Do i use regex to match a string/text or do i use indexOf/LastIndexOf to search for a char and the iterate until i get to another char?

Best regards
xorl

Recommended Answers

All 21 Replies

Oh yea sorry, my mistake this not a *.pls

this is an *.m3u

How about splitting like this:
string[] s1 = s.Split(new string[]{".mp3"} ,StringSplitOptions.RemoveEmptyEntries);
and then Split('-') ?

hmm yea altho it cannot split correctly on that.

file looks like this unsplitted and unfiltered....

"#extm3u\r\n#extinf:4779,addictive djs - crush on hardcore 3\r\n\\streamripper\\d i g i t a l l y - i m p o r t e d & happyhardcorecom - hardcore - dj mixes, hard dance and nunrg!\\addictive djs - crush on hardcore 3.mp3\r\n#extinf:312,al storm and the acolyte ft lisa abbott - falling through (alistair storm remix)\r\n\\streamripper\\d i g i t a l l y - i m p o r t e d & happyhardcorecom - hardcore - dj mixes, hard dance and nunrg!\\al storm and the acolyte ft lisa abbott - falling through (alistair storm remix).mp3\r\n#extinf:363,al twisted and dj jfx feat vicky fee - turn it up\r\n\\streamripper\\d i g i t a l l y - i m p o r t e d & happyhardcorecom - hardcore - dj mixes, hard dance and nunrg!\\al twisted and dj jfx feat vicky fee - turn it up.mp3\r\n#extinf:328,al twisted and jfx - raise the roof\r

etc etc.

I think i need to split on the given name, not sure and then create certain properties for example titles[].

best regards

Well if you did an initial split on \\ and \r\n, you would have a bunch of stuff and then parts of which would be

#extinf:nnnnn,

so you could find the , and remove upto it, and its your title, or, if it ends in .mp3 its your filename..

Hmmmm i did a split like this

string []titles = readpls.split(new string[]{@"\", @"\r\n"}, StringSplitOptions.RemoveEmptyEntries);

first output:

#extm3u is the header

#extinf looks to be the section for the next name and file

[0] "#extm3u\r\n#extinf:4779,addictive djs - crush on hardcore 3\r\n" //remove with indexof?
[1] "Streamripper"
[2] "addictive djs - crush on hardcore 3.mp3\r\n#extinf:312,al storm and the acolyte ft lisa abbott - falling through (alistair storm remix)\r\n"

ill have to use the remove perhaps to remove everything up on till ',' as u stated. Although im not sure how to remove the second "\r\n" for every title. maybe use lastindexof?

Best regards
xorl

I can offer you this:
String.Concat(s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));

where s - is title. Not the best, but it is variant.

Allright.

Thank you both of you.....uve been a great help.

Greatly appreciated from my side.

/Xorl

:) good luck

Note:

I tried another solution that i had in mind.....although im not sure this works

while (!streamread.EndOfStream)
{
    readpls = srpls.ReadToEnd();
    readpls = readpls.ToLower().Trim();

    int index1 = readpls.LastIndexOf(@"\");
    int index2 = readpls.LastIndexOf(".");

    string output = readpls.Substring(index1 + 1, index2 - index1 - 1);
}

this did return the name of the last element on the m3u list. Not sure this is optimal though.
Need to declare a string array to hold the title elements on every line. Does ReadToEnd() really work with that?

/xorl

If the files that youll working with will be not to large, I think, you can use It. But in case bigger files, I prefer to use, for example, ReadLine() function to reach the end of file.

Hey

Performance wise, is ReadLine() faster and less memory consuming when reading files?
m3u and pls can get quite large so ill have to use that then.

Thanks
/xorl

ReadLine() is not the only one, there are a few not less interesting functions in StreamReader class ... pay attention to it.
And there's a few functions in Stream class (for example to move the cursor).

Hmmmm i did a split like this

string []titles = readpls.split(new string[]{@"\", @"\r\n"},

[snip]

Hmmmm i did a split like this
[0] "#extm3u\r\n#extinf:4779,addictive djs - crush on hardcore 3\r\n" //remove with indexof?
[1] "Streamripper"
[2] "addictive djs - crush on hardcore 3.mp3\r\n#extinf:312,al storm and the acolyte ft lisa abbott - falling through (alistair storm remix)\r\n"

Well I guess thats what happens when you tell it to take as litteral the escape characters you were trying to split at..

sigh

Hey

Yea well.....i was actually trying different variants my friend. nothing worked.....
just gotta find the right split......

how would you split it then?

/xorl

Can you attach whole file m3u, that you are working with?

how would you split it then?/xorl

I already said how Id split it - I just wouldnt have made it so it was a physical string of \r\n, but the escape characters.

I already said how Id split it - I just wouldnt have made it so it was a physical string of \r\n, but the escape characters.

Ok. I know what u mean now. Ill try to split the actual chars then. Thanks.

/xorl

Can you attach whole file m3u, that you are working with?

Hey

ehm, you can always make ur own m3u in winamp. i could however do that if you specifically want the m3u im working on.

/xorl

No, there is no necessity. I just forgot, that I can create my own :)

Hey

It worked well with that split

string []titles = lines.split(new char[]{'\\', '\n', '\r'});

now i should be able todo a remove

/xorl

hey

it works well now....didnt even need to split the file. just do a search for a certain char '#' and skip the line if char is on the line.....that simple =).

another problem with my m3u file is that it wasnt generated correctly in winamp. No searchpaths was added like it should. dont know why, but i think my version of winamp is buggy. both m3u and pls saving in winamp generate the same incorrect result.

Anyway the problem is solved...thanks for the help

/xorl

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.