Posted: Mon Apr 17, 2006 8:28 pm Post subject: Unicode Encoding and Byte Removal
Well, this is definately something I won't be able to figure out on myself.
So I made a program. It converts Windows Media Player 10 Playlist files ( *.wpl files) into a playlist file that will play on my MP3 Player (A samsung YH-925, and the playlist file is *.plp).
Here's an example of a .wpl playlist file:
code:
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.4019"/>
<author/>
<title>Easy Listening</title>
</head>
<body>
<seq>
<media src="D:\Limewire\Music\Stained - So Far Away.mp3" tid="{63BCF8C9-6593-4352-8D14-6B169136D475}"/>
<media src="D:\My Documents\My Music\Simple Plan - Still Not Gettin' Any\06 - Crazy.mp3" tid="{1920B4CA-6927-4719-9CB7-BB713CEC0910}"/>
<media src="D:\Limewire\Music\Asher Lane - New days.mp3" tid="{33EA83D7-8022-46DF-AD15-956DA3490FEB}"/>
<media src="D:\Limewire\Music\Disney-Phil Collins - Tarzan - You'll Be In My Heart.mp3" tid="{F368BBBA-F6F4-4A38-B933-C15ECB1DE5CF}"/>
</seq>
</body>
</smil>
(The indentation won't be shown because of the forum, but whatever)
and here's an example of this file converted into a .plp playlist file:
code:
PLP PLAYLIST
VERSION 1.20
HDD, System\MUSIC\Stained - So Far Away.mp3
HDD, System\MUSIC\06 - Crazy.mp3
HDD, System\MUSIC\Asher Lane - New days.mp3
HDD, System\MUSIC\Disney-Phil Collins - Tarzan - You'll Be In My Heart.mp3
So what the program has to do is seek out the file names, then put a "HDD, System\MUSIC\" infront of them. It also has to change all occurences of "'" into apostrophes, as they should be.
So, after this conversion, it won't play in my mp3 player. To make it work properly, I have to open it into notepad, and then re-save it, but change the encoding from ANSI to unicode. And then, I have to open the file in a hex editor, and remove the first two bytes, which have the hex values FF and FE, respectively. Then it will work on my mp3 player.
So I'm wondering, is there a way in turing for me to be able to encode the file using unicode, and then remove the first two bytes?
Thanks
Oh, and here is a copy of my program. I know it may be a little inefficient in spots, but it's been half a year since I've had comp. sci., so it's all going off of memory.
code:
var fn, fn2 : int
var textfile, character, playlist, yplay : string := ""
put "Please enter the name of the Windows Media Player playlist"
put "(including the extension).", skip
put "NOTE: It must be in the same directory as this executable. ", skip
get playlist :*
put skip, "Please enter the name of the YH-925 Playlist (without the extension)", skip
get yplay :*
yplay += ".plp"
open : fn, playlist, get, seek
open : fn2, yplay, put, seek
put skip, "------------- A copy of the output file: -------------", skip
put "PLP PLAYLIST" % Prints a copy of the playlist header to the screen
put "VERSION 1.20"
put ""
put : fn2, "PLP PLAYLIST" % Prints a copy of the playlist header to the playlist file
put : fn2, "VERSION 1.20"
put : fn2, ""
loop
location := 0
exit when eof (fn)
if character = chr (92) then
tell : fn, location
loop % ----------- START "\" removal loop -----------
get : fn, character : 1
if character = chr (92) then % Description: The file is searched for any occurences of the "\" character. When it
tell : fn, location % is detected, a reference point is made, and the search continues for others. When there
end if % are no more on the line, the reference point is seeked, and then moves on to the next loop.
exit when character = chr (34)
end loop % ----------- END "\" removal loop -----------
seek : fn, location
loop % ----------- START ' removal and replacement loop -----------
get : fn, character : 1
if character = "&" then
tell : fn, location
get : fn, character : 1
if character = "a" then
get : fn, character : 1
if character = "p" then
get : fn, character : 1
if character = "o" then
get : fn, character : 1
if character = "s" then
get : fn, character : 1
if character = ";" then
get : fn, character : 1
textfile += "'"
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
end if
exit when character = chr (34) % Exit when a quotation mark is detected
textfile += character
end loop % ----------- END ' removal and replacement loop -----------
put "HDD, System", chr (92), "MUSIC", chr (92) ..
put : fn2, "HDD, System", chr (92), "MUSIC", chr (92) ..
put textfile ..
put : fn2, textfile ..
put ""
put : fn2, ""
textfile := ""
end if
get : fn, character : 1
end loop
close : fn
close : fn2
Sponsor Sponsor
Delos
Posted: Tue Apr 18, 2006 1:35 pm Post subject: (No subject)
Use read and write instead of put and get. That's the first big step to take, since it will then write the file in binary format (i.e., free of ASCII).
This should work...if not, well try this first and then post up again.
skootles
Posted: Tue Apr 18, 2006 2:38 pm Post subject: (No subject)
When I replaced put with write, for example:
code:
out : fn2, "PLP PLAYLIST"
put : fn2, "VERSION 1.20"
put : fn2, ""
put "Please enter the name of the Windows Media Player playlist"
put "(including the extension).", skip
put "NOTE: It must be in the same directory as this executable. ", skip
get playlist :*
put skip, "Please enter the name of the YH-925 Playlist", skip
get yplay :*
yplay += ".plp"
open : fn, playlist, read, seek % The Windows Media Player playlist file
open : fn2, yplay, write, seek % The MP3 Player playlist file
put skip, "------------- A copy of the outwrite file: -------------", skip
var v1 : string := "PLP PLAYLIST"
var v2 : string := "VERSION 1.20"
var v3 : string := ""
put v1
put v2
put v3
write : fn2, v1 % Prints a copy of the playlist header to the playlist file
write : fn2, v2
write : fn2, v3
loop
location := 0
exit when eof (fn)
if character = chr (92) then
tell : fn, location
loop % ----------- START "\" removal loop -----------
read : fn, character : 1
if character = chr (92) then % Description: The file is searched for any occurences of the "\" character. When it
tell : fn, location % is detected, a reference point is made, and the search continues for others. When there
end if % are no more on the line, the reference point is seeked, and then moves on to the next loop.
exit when character = chr (34)
end loop % ----------- END "\" removal loop -----------
seek : fn, location
loop % ----------- START ' removal and replacement loop -----------
read : fn, character : 1
if character = "&" then
tell : fn, location
read : fn, character : 1
if character = "a" then
read : fn, character : 1
if character = "p" then
read : fn, character : 1
if character = "o" then
read : fn, character : 1
if character = "s" then
read : fn, character : 1
if character = ";" then
read : fn, character : 1
textfile += "'"
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
else
seek : fn, location - 1
end if
end if
exit when character = chr (34) % Exit when a quotation mark is detected. (Quotes signal the end of the filename)
textfile += character
end loop % ----------- END ' removal and replacement loop -----------
var test : string := "HDD, System"
test += chr(92)
test += "MUSIC"
test += chr(92)
test += textfile
put test
write : fn2, test
%put textfile
%write : fn2, textfile
write : fn2, v3
textfile := ""
test := ""
end if
read : fn, character : 1
end loop
close : fn
close : fn2
and everything comes out horribly spaced:
Plus I don't know what those weird 3 characters are
Delos
Posted: Tue Apr 18, 2006 11:13 pm Post subject: (No subject)
Using write outputs it in binary format - this is not something that Notepad can recognize very well. However, your file headers should be less of a pain to work with.
Have you tested the new playlists with your MP3 player? If they still don't work, we can work on some actual Hex editting stuff. It's really quite a bit of fun, playing with obscure values that make no sense to the average eye. Of course, we'll have made code efficient enough that we'll never have to deal with said values...
skootles
Posted: Wed Apr 19, 2006 2:14 pm Post subject: (No subject)
No, the playlist files still don't work. So, I guess let's get into Hex Editing
I showed the problem to my old comp sci teacher, and he said he'd take a look at it, so I may get some help from him.
Delos
Posted: Wed Apr 19, 2006 3:39 pm Post subject: (No subject)
Right right, no problem. Just post a copy of the same playlist in both formats, and we'll move on from there. Also, what Hex editor are you using?
Sponsor Sponsor
skootles
Posted: Wed Apr 19, 2006 4:26 pm Post subject: (No subject)
Alrighty. Here's the windows media player file (*.wpl):
code:
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.4019"/>
<author/>
<title>Easy Listening</title>
</head>
<body>
<seq>
<media src="D:\Limewire\Music\Stained - So Far Away.mp3" tid="{63BCF8C9-6593-4352-8D14-6B169136D475}"/>
<media src="D:\My Documents\My Music\Simple Plan - Still Not Gettin' Any\06 - Crazy.mp3" tid="{1920B4CA-6927-4719-9CB7-BB713CEC0910}"/>
<media src="D:\Limewire\Music\Asher Lane - New days.mp3" tid="{33EA83D7-8022-46DF-AD15-956DA3490FEB}"/>
<media src="D:\Limewire\Music\Disney-Phil Collins - Tarzan - You'll Be In My Heart.mp3" tid="{F368BBBA-F6F4-4A38-B933-C15ECB1DE5CF}"/>
</seq>
</body>
</smil>
and Here's the MP3 Player playlist file (*.plp):
code:
PLP PLAYLIST
VERSION 1.20
HDD, System\MUSIC\Stained - So Far Away.mp3
HDD, System\MUSIC\06 - Crazy.mp3
HDD, System\MUSIC\Asher Lane - New days.mp3
HDD, System\MUSIC\Disney-Phil Collins - Tarzan - You'll Be In My Heart.mp3
Now if you copy the .plp file from above into notepad, you still have to save it with unicode encoding, then open it up in a hex editor (I'm using one that I found on my computer, translhextion) and remove the first two bytes.
Delos
Posted: Wed Apr 19, 2006 8:10 pm Post subject: (No subject)
Delos wrote:
Right right, no problem. Just post a copy of the same playlist in both formats, and we'll move on from there. Also, what Hex editor are you using?
Mayhaps I ought have spake that a little differently. No damage:
Please attach a copy of the same playlist in both formats...
I'm not sure if you have the capability to save in .plp - considering your dilemma. But if you can, awsome. If not, then just post one of your editted files.
skootles
Posted: Wed Apr 19, 2006 9:17 pm Post subject: (No subject)
Haha, okay.
So I've included 4 files in the zip. 1 is the original Windows Media Player Playlist file (Easy Listening.wpl), and then there are 3 MP3 Player Playlist files:
The first, which has "NOT WORKING" is the raw conversion. It's the output from the program, so it doesn't work in the MP3 Player.
The second which has "ALMOST WORKING" is the first one, except I've opened it up in notepad, and re-saved it with Unicode encoding.
The third which has "WORKING FULLY" is the second one, but I've opened it in Translhextion and removed the first two bytes. Now it works perfectly in the MP3 Player.
Now just note that when you open up the second one in notepad, you can't see the first two bytes that need to be removed. My teacher got confused with this, so just clarifing
Posted: Thu Apr 20, 2006 12:40 pm Post subject: (No subject)
Right, this is better now. I'll probably be able to work on this a little tonight - not right now since studying is taking complete precedence...well, mostly at least .
For the time being, make sure you know how to convert between decimal and hexadecimal (and vice versa); and simple ASCII manipulations between decimal and their character equivalents.
For instance, if I were to throw the number 2E at you, I'd expect you to be able to tell me what the character equivalent was (it's ".", FYI).
Work on that for the time being, and we'll get to the rest soon enough. (Don't worry if some of your conversion output as blank spaces - a lot of characters simply have no renderable equivalent.
Delos
Posted: Fri Apr 21, 2006 7:48 am Post subject: (No subject)
I'm going to guess that by this time you have figured out what I set out above. On to the next step.
Now that conversions between decimal and hex are no problem, you're going to have to do a bit of logical analysis of the hex dumps. The usefulness here is that you'll be able to create a specific type of file that goes beyond the mere suffix that is attached to it.
For instance, Turing is sneaky when it comes to saving pictures. They claim that it can save in .jpg; when in fact the resultant pictures have none of the compression of JPEGs and are indeed bitmaps with different suffixes. The hex headers remain the same.
That being said, your task to to do the following:
- determine the header for .plp files, according to what you have. Post up the hex dump of it. Don't worry about the text version, that is mostly meaningless.
- determine the format that will allow the MP3 player to recognise the following file:
"Hello - World.mp3"
Again, post up the hex for it. You should find that the entire path for this inclues a little more than the name of the song...something about a system folder...
I'd be a little more instructive - just I don't have the time right now! I'm sure you can handle this much though. If you get stuck, say so and I'll give you a few more hints.
skootles
Posted: Fri Apr 21, 2006 3:02 pm Post subject: (No subject)
I understand, exams are inportant.
But I'm not quite sure what the header is, or where I'd find it. Methinks at the top, but there's nothing really there. To save some time, I just got a screenie of the hex editor when I've got the file open. Note the first two bytes - these are the ones that need to be removed before the playlist will play in the player.
And here is the same file when opened in notepad:
code:
PLP PLAYLIST
VERSION 1.20
HDD, System\MUSIC\Hello - World.mp3
The "System\MUSIC" part is obviously the path to the file, where all music that is synced to the device is put.
Delos
Posted: Fri Apr 21, 2006 6:55 pm Post subject: (No subject)
You're off to a good start. Essentially, a header is a little bit of hex at the top of the file that gives some details about its contents. These can be quite complex (hell, even bitmap headers are pretty long) to barely nonexistent (the .wpl don't really have headers).
When you're creating your playlists, you'll need to have a default header to be added to the beginning of each file. You'll then fill the body with the data for each song, and finally...well...where there's a header...
You haven't quite completed the assigned tasks just yet, but keep plugging away at them. Once you're past those - it's really quite a simple transition to create the playlist itself.