File loading music
#1

Well i have been making my own radio/random stream system for a wile now where players can suggest streams and then admins add the streams if it is apporpriate and such (have all that working well) but i have been having a hard time loading the streams from a file. It loads the songs correctly but it adds a new line to the stream name parameter.
Here is my print i did to the server log...
Код:
[21:40:05] Country


[21:40:05] Sky. FM


[21:40:05] Big_R_Radio


[21:40:05] Slow Music


[21:40:05] Aaron FM (Rock)


[21:40:05] Techno


[21:40:05] Dance Floor Rmx


[21:40:05] Get Low


[21:40:05] Comedy


[21:40:05] .977 The Hits Channel


[21:40:05] 181.FM The Buzz


[21:40:05] Beatles Radio


[21:40:05] 181.FM Rock


[21:40:05] Rocky FM


[21:40:05] Sky.FM Country


[21:40:05] ChroniX GRIT Radio


[21:40:05] Spellbound Harbor Radio


[21:40:05] Mond-Radio


[21:40:05] One-Eleven Radio


[21:40:05] Flight Level Radio


[21:40:05] Lite Favorites


[21:40:05] 420 FM


[21:40:05] Malabloos Blues


[21:40:05] Talk Radio
[21:40:08] NStreamer created 3354 objects
[21:40:08] Loaded 24 music streams
As you can see its making a line after the name wich is bad for the rest of my system. Here is my loading function

pawn Код:
forward LoadMusic();
public LoadMusic()
{
    new path[64], line[128];
    format(path, sizeof(path), "/AdminFolder/musiclist.txt");
    if(!fexist(path))
    {

        print("Counld not locate song file");
    }
    else
    {
        new name[128], url[400],pname[24],File:song = fopen(path, io_read);
        while(fread(song, line))
        {
            if (!sscanf(line, "s[400]s[24]s[128]",url, pname, name))
            {
                randomMusic[MusicCount][Url] = url;
                randomMusic[MusicCount][pAdded] = pname;
                randomMusic[MusicCount][MusicName] = name;
                printf("%s",randomMusic[MusicCount][MusicName]);
                MusicCount++;
            }
            else
            {
                printf("cound not load line %i",1+MusicCount);
            }
        }
    }
}
Here is a video of the dialog issue too(used xfire video cause screen shots wont take screens of dialogs)

Video

The Stream name and added by line should all be on the same line but this problem caused that to happen.

Any one know what would cause this to make a new line?

Here is the file it loads from..
Код:
http://yp.shoutcast.com/sbin/tunein-stat...id=1283687 Admin Country
http://yp.shoutcast.com/sbin/tunein-station.pls?id=728272 Admin Sky. FM
http://74.86.186.35:8018/listen.pls Admin Big_R_Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=1658657 Admin Slow Music
http://yp.shoutcast.com/sbin/tunein-station.pls?id=204262 Admin Aaron FM (Rock)
http://yp.shoutcast.com/sbin/tunein-station.pls?id=1377200 Admin Techno
http://k003.kiwi6.com/hotlink/47pfej18n4/dance_floor_rmx.mp3 Admin Dance Floor Rmx
http://k005.kiwi6.com/hotlink/7xy395s711/lil_jon_the_eastside_boyz_get_low.mp3 Admin Get Low
http://yp.shoutcast.com/sbin/tunein-station.pls?id=52807 Admin Comedy
http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356 Admin .977 The Hits Channel
http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586 Admin 181.FM The Buzz
http://yp.shoutcast.com/sbin/tunein-station.pls?id=1273220 Admin Beatles Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=302754 Admin 181.FM Rock
http://yp.shoutcast.com/sbin/tunein-station.pls?id=684390 Admin Rocky FM
http://yp.shoutcast.com/sbin/tunein-station.pls?id=780577 Admin Sky.FM Country
http://yp.shoutcast.com/sbin/tunein-station.pls?id=2187022 Admin ChroniX GRIT Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=8850 Admin Spellbound Harbor Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=161583 Admin Mond-Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=2052 Admin One-Eleven Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=105926 Admin Flight Level Radio
http://yp.shoutcast.com/sbin/tunein-station.pls?id=2100794 Admin Lite Favorites
http://yp.shoutcast.com/sbin/tunein-station.pls?id=33610 Admin 420 FM
http://yp.shoutcast.com/sbin/tunein-station.pls?id=222696 Admin Malabloos Blues
http://yp.shoutcast.com/sbin/tunein-station.pls?id=1026951 [T1S]nickdodd25 Talk Radio
Now i did have it loading perfect by having the song name first then i had to add _ in place of spaces make it one string or sscanf would just load the first word as the name then the second word as the url, it worked fine for single named streams then i switched to this and everything works great but it makes a new line out of no where.
I know the strings are a bit high but i want to get this working first lol

Anyone have a idea on why this is happening or does anyone know a way to load with sscanf or just load without sscanf? Need anymore info let me know.
Reply
#2

this is weird but one thing is you should get a handle on the string size now
you have

line[128];

but then you have
new name[128], url[400],pname[24]
128 + 400 + 24 = 552 that is reading from a line size of 128.
you cannot fill 552 cells with only 128 cells of data.

i would setup a MAX_STATION_NAME
and figure out how much you really need for a url
and if need be then increase the line size to 256 or higher if you NEED to,
figure a limit and stick to it.

put i don't think that's the problem here
im still not sure on why its creating a new line
how is the file created?
Reply
#3

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
this is weird but one thing is you should get a handle on the string size now
you have

line[128];

but then you have
new name[128], url[400],pname[24]
128 + 400 + 24 = 552 that is reading from a line size of 128.
you cannot fill 552 cells with only 128 cells of data.

i would setup a MAX_STATION_NAME
and figure out how much you really need for a url
and if need be then increase the line size to 256 or higher if you NEED to,
figure a limit and stick to it.

put i don't think that's the problem here
im still not sure on why its creating a new line
how is the file created?
Well i have the string sizes figured out, made the urls 128, cause my longest url i found was only 70 somthing, and the stream name is 30 now. I also made line[128] to line[182], so now all the string sizes arent wrong/too big. And it still loads with an extra line.

As for createing the file i just have a function for when admins ok the file it appends it to the file but i have only tested it with the last two streams and the rest i put in the folder myself.

pawn Код:
new string1[188], path[30];
                format(path, sizeof(path), "/AdminFolder/musiclist.txt");
               

                format(string1, sizeof(string1), "\r\n%s %s %s",PlayerInfo[playerid][smusicname], PlayerInfo[playerid][smusicurl], PlayerInfo[playerid][spadded]);
                printf("%s",string1);
                new File:song = fopen(path, io_append);
                fwrite(song,string1);
                fclose(song);
                PlayerInfo[playerid][smusicurl] ='\0';
                PlayerInfo[playerid][smusicname] ='\0';
                PlayerInfo[playerid][spadded] ='\0';
                MusicCount++;
But would it be possible for sscanf to load strings between " "? like example
Код:
"http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283687" "Admin" "Country"
If thats the case i never had a problem when the song name was first exept i had to use _ inplace of spaces so sscanf would load it as one word then had a function that removed the _. But if there was a way to load like above then i wouldnt need _ at all
Reply
#4

i use the "|" for a delimiter in sscanf most of the time.

and maybe dont add a carriage return to the line when saving. eg "\r"
Im thinking the saving code is what is doing this,

I use todo the same sort of thing i will go back threw some old code and see how i did it and edit this post wityh the info.
Reply
#5

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
i use the "|" for a delimiter in sscanf most of the time.

and maybe dont add a carriage return to the line when saving. eg "\r"
Im thinking the saving code is what is doing this,

I use todo the same sort of thing i will go back threw some old code and see how i did it and edit this post wityh the info.
Well i tryed the delimiter thing and it still makes the extra line for no reason. And as for you thinking that its the saving it really shoulnt make a diffrence, the file i made myself and then the only ones that the writing function did are the last two. And for the \r i needed that cause it wouldnt make a new line for some reason and it would add on to the bottom line.

Edit: you think mabey changing the file type would help? like something other than .txt? I am all out of ideas here lol

Edit again:

Well i chaged the code around to how it used to be where it would load the stream name first then url then the person who added it and it still loads the last param(the person who added it) with a new line from out of no where.
Reply
#6

Welll i got it to load properly with out it making a new line, but now sscanf gives me warnings
Код:
[14:51:09] sscanf warning: Format specifier does not match parameter count.
That happens before loading each line, here is the full serverlog of that part

Код:
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Big-R-Radio
[15:51:39] http://74.86.186.35:8018/listen.plsnl673...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Country
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Sky.FM
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Slow-Music
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Aaron-FM(ROCK)
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Techno
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Dance-Floor-Rmx
[15:51:39] http://k003.kiwi6.com/hotlink/47pfej18n4...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Get-Low
[15:51:39] http://k005.kiwi6.com/hotlink/7xy395s711...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Comedy
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] .977-The-Hits
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] 181.FM-The-Buzz
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Beatles-Radio
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] 181.Fm-(ROCK)
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Rocky-FM
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Sky.FM-Country
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] ChroniX-GRIT-Radio
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Spellbound-Harbor-Radio
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] One-Eleven-Radio
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Flight-Level-Radio
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Lite-Favorites
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] 420-FM
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Malabloos-Blues
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
[15:51:39] sscanf warning: Format specifier does not match parameter count.
[15:51:39] Talk-Radio
[15:51:39] http://yp.shoutcast.com/sbin/tunein-stat...4.33021654[15:51:39] [T1S]nickdodd25
I have debug prints in the loading function here is the loading function slightly modifyed now
pawn Код:
forward LoadMusic();
public LoadMusic()
{
    new path[64], line[182];
    format(path, sizeof(path), "/AdminFolder/musiclist.ini");
    if(!fexist(path))
    {

        print("Counld not locate song file");
    }
    else
    {
        new name[30], url[128],pname[24],File:song = fopen(path, io_read);
        while(fread(song, line))
        {
            if (!sscanf(line, "s[30]s[128]s[24]p<|>", name, url, pname))
            {
                printf("%s",name);
                printf("%s",url);
                printf("%s",pname);
                randomMusic[MusicCount][Url] = url;
                randomMusic[MusicCount][pAdded] = pname;
                randomMusic[MusicCount][MusicName] = name;
                MusicCount++;
            }
            else
            {
                printf("cound not load line %i",1+MusicCount);
            }
        }
    }
}
I added a delimiter and it kida fixed the problem, here is how i have the file,
Код:
Big-R-Radio http://74.86.186.35:8018/listen.pls [T1S]nickdodd25 |
Country http://yp.shoutcast.com/sbin/tunein-stat...id=1283687 [T1S]nickdodd25 |
Sky.FM http://yp.shoutcast.com/sbin/tunein-stat...?id=728272 [T1S]nickdodd25 |
Slow-Music http://yp.shoutcast.com/sbin/tunein-stat...id=1658657 [T1S]nickdodd25 |
Aaron-FM(ROCK) http://yp.shoutcast.com/sbin/tunein-stat...?id=204262 [T1S]nickdodd25 |
Techno http://yp.shoutcast.com/sbin/tunein-stat...id=1377200 [T1S]nickdodd25 |
Dance-Floor-Rmx http://k003.kiwi6.com/hotlink/47pfej18n4...or_rmx.mp3 [T1S]nickdodd25 |
Get-Low http://k005.kiwi6.com/hotlink/7xy395s711...et_low.mp3 [T1S]nickdodd25 |
Comedy http://yp.shoutcast.com/sbin/tunein-stat...s?id=52807 [T1S]nickdodd25 |
.977-The-Hits http://yp.shoutcast.com/sbin/tunein-stat...id=1280356 [T1S]nickdodd25 |
181.FM-The-Buzz http://yp.shoutcast.com/sbin/tunein-stat...s?id=37586 [T1S]nickdodd25 |
Beatles-Radio http://yp.shoutcast.com/sbin/tunein-stat...id=1273220 [T1S]nickdodd25 |
181.Fm-(ROCK) http://yp.shoutcast.com/sbin/tunein-stat...?id=302754 [T1S]nickdodd25 |
Rocky-FM http://yp.shoutcast.com/sbin/tunein-stat...?id=684390 [T1S]nickdodd25 |
Sky.FM-Country http://yp.shoutcast.com/sbin/tunein-stat...?id=780577 [T1S]nickdodd25 |
ChroniX-GRIT-Radio http://yp.shoutcast.com/sbin/tunein-stat...id=2187022 [T1S]nickdodd25 |
Spellbound-Harbor-Radio http://yp.shoutcast.com/sbin/tunein-station.pls?id=8850 [T1S]nickdodd25 |
One-Eleven-Radio http://yp.shoutcast.com/sbin/tunein-station.pls?id=2052 [T1S]nickdodd25 |
Flight-Level-Radio http://yp.shoutcast.com/sbin/tunein-stat...?id=105926 [T1S]nickdodd25 |
Lite-Favorites http://yp.shoutcast.com/sbin/tunein-stat...id=2100794 [T1S]nickdodd25 |
420-FM http://yp.shoutcast.com/sbin/tunein-stat...s?id=33610 [T1S]nickdodd25 |
Malabloos-Blues http://yp.shoutcast.com/sbin/tunein-stat...?id=222696 [T1S]nickdodd25 |
Talk-Radio http://yp.shoutcast.com/sbin/tunein-stat...id=1026951 [T1S]nickdodd25 |
I think i am doing this right but i am not totaly sure, but on the bright side the rest of my music system now works bug free aside from the server log warnings, Anyone know how i should go about fixing this?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)