Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
aa4c7055
Commit
aa4c7055
authored
Dec 04, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playlist/pls: custom INI parser
Don't use GLib.
parent
4b70f9d2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
93 deletions
+107
-93
Makefile.am
Makefile.am
+2
-6
PlaylistRegistry.cxx
src/playlist/PlaylistRegistry.cxx
+0
-3
PlsPlaylistPlugin.cxx
src/playlist/plugins/PlsPlaylistPlugin.cxx
+105
-84
No files found.
Makefile.am
View file @
aa4c7055
...
@@ -1397,6 +1397,8 @@ libplaylist_plugins_a_SOURCES = \
...
@@ -1397,6 +1397,8 @@ libplaylist_plugins_a_SOURCES = \
src/playlist/plugins/CuePlaylistPlugin.hxx
\
src/playlist/plugins/CuePlaylistPlugin.hxx
\
src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx
\
src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx
\
src/playlist/plugins/EmbeddedCuePlaylistPlugin.hxx
\
src/playlist/plugins/EmbeddedCuePlaylistPlugin.hxx
\
src/playlist/plugins/PlsPlaylistPlugin.cxx
\
src/playlist/plugins/PlsPlaylistPlugin.hxx
\
src/playlist/PlaylistRegistry.cxx src/playlist/PlaylistRegistry.hxx
src/playlist/PlaylistRegistry.cxx src/playlist/PlaylistRegistry.hxx
libplaylist_plugins_a_CPPFLAGS
=
$(AM_CPPFLAGS)
\
libplaylist_plugins_a_CPPFLAGS
=
$(AM_CPPFLAGS)
\
$(EXPAT_CFLAGS)
\
$(EXPAT_CFLAGS)
\
...
@@ -1434,12 +1436,6 @@ libplaylist_plugins_a_SOURCES += \
...
@@ -1434,12 +1436,6 @@ libplaylist_plugins_a_SOURCES += \
src/playlist/plugins/RssPlaylistPlugin.hxx
src/playlist/plugins/RssPlaylistPlugin.hxx
endif
endif
if
HAVE_GLIB
libplaylist_plugins_a_SOURCES
+=
\
src/playlist/plugins/PlsPlaylistPlugin.cxx
\
src/playlist/plugins/PlsPlaylistPlugin.hxx
endif
#
#
# Filter plugins
# Filter plugins
#
#
...
...
src/playlist/PlaylistRegistry.cxx
View file @
aa4c7055
...
@@ -45,10 +45,7 @@
...
@@ -45,10 +45,7 @@
const
struct
playlist_plugin
*
const
playlist_plugins
[]
=
{
const
struct
playlist_plugin
*
const
playlist_plugins
[]
=
{
&
extm3u_playlist_plugin
,
&
extm3u_playlist_plugin
,
&
m3u_playlist_plugin
,
&
m3u_playlist_plugin
,
#ifdef HAVE_GLIB
// TODO: enable without GLib
&
pls_playlist_plugin
,
&
pls_playlist_plugin
,
#endif
#ifdef ENABLE_EXPAT
#ifdef ENABLE_EXPAT
&
xspf_playlist_plugin
,
&
xspf_playlist_plugin
,
&
asx_playlist_plugin
,
&
asx_playlist_plugin
,
...
...
src/playlist/plugins/PlsPlaylistPlugin.cxx
View file @
aa4c7055
...
@@ -21,121 +21,142 @@
...
@@ -21,121 +21,142 @@
#include "PlsPlaylistPlugin.hxx"
#include "PlsPlaylistPlugin.hxx"
#include "../PlaylistPlugin.hxx"
#include "../PlaylistPlugin.hxx"
#include "../MemorySongEnumerator.hxx"
#include "../MemorySongEnumerator.hxx"
#include "input/InputStream.hxx"
#include "input/
Text
InputStream.hxx"
#include "DetachedSong.hxx"
#include "DetachedSong.hxx"
#include "tag/TagBuilder.hxx"
#include "tag/TagBuilder.hxx"
#include "util/ASCII.hxx"
#include "util/StringUtil.hxx"
#include "util/DivideString.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <string>
#include <string>
#include <stdio.h>
#include <std
io
.h>
#include <std
lib
.h>
static
constexpr
Domain
pls_domain
(
"pls"
);
static
constexpr
Domain
pls_domain
(
"pls"
);
static
void
static
bool
pls_parser
(
GKeyFile
*
keyfile
,
std
::
forward_list
<
DetachedSong
>
&
song
s
)
FindPlaylistSection
(
TextInputStream
&
i
s
)
{
{
gchar
*
value
;
char
*
line
;
GError
*
error
=
nullptr
;
while
((
line
=
is
.
ReadLine
())
!=
nullptr
)
{
int
num_entries
=
g_key_file_get_integer
(
keyfile
,
"playlist"
,
line
=
Strip
(
line
);
"NumberOfEntries"
,
&
error
);
if
(
StringEqualsCaseASCII
(
line
,
"[playlist]"
))
if
(
error
)
{
return
true
;
FormatError
(
pls_domain
,
"Invalid PLS file: '%s'"
,
error
->
message
);
g_error_free
(
error
);
error
=
nullptr
;
/* Hack to work around shoutcast failure to comform to spec */
num_entries
=
g_key_file_get_integer
(
keyfile
,
"playlist"
,
"numberofentries"
,
&
error
);
if
(
error
)
{
g_error_free
(
error
);
error
=
nullptr
;
}
}
}
for
(;
num_entries
>
0
;
--
num_entries
)
{
return
false
;
char
key
[
64
];
}
sprintf
(
key
,
"File%u"
,
num_entries
);
char
*
uri
=
g_key_file_get_string
(
keyfile
,
"playlist"
,
key
,
&
error
);
if
(
error
)
{
FormatError
(
pls_domain
,
"Invalid PLS entry %s: '%s'"
,
key
,
error
->
message
);
g_error_free
(
error
);
return
;
}
TagBuilder
tag
;
static
bool
ParsePls
(
TextInputStream
&
is
,
std
::
forward_list
<
DetachedSong
>
&
songs
)
{
assert
(
songs
.
empty
());
sprintf
(
key
,
"Title%u"
,
num_entries
);
if
(
!
FindPlaylistSection
(
is
))
value
=
g_key_file_get_string
(
keyfile
,
"playlist"
,
key
,
return
false
;
nullptr
);
if
(
value
!=
nullptr
)
tag
.
AddItem
(
TAG_TITLE
,
value
);
g_free
(
value
)
;
unsigned
n_entries
=
0
;
sprintf
(
key
,
"Length%u"
,
num_entries
);
struct
Entry
{
int
length
=
g_key_file_get_integer
(
keyfile
,
"playlist"
,
key
,
std
::
string
file
,
title
;
nullptr
);
int
length
;
if
(
length
>
0
)
tag
.
SetDuration
(
SignedSongTime
::
FromS
(
length
));
songs
.
emplace_front
(
uri
,
tag
.
Commit
());
Entry
()
:
length
(
-
1
)
{}
g_free
(
uri
);
};
}
}
static
constexpr
unsigned
MAX_ENTRIES
=
65536
;
static
SongEnumerator
*
std
::
vector
<
Entry
>
entries
;
pls_open_stream
(
InputStream
&
is
)
{
GError
*
error
=
nullptr
;
Error
error2
;
std
::
string
kf_data
;
char
*
line
;
while
((
line
=
is
.
ReadLine
())
!=
nullptr
)
{
line
=
Strip
(
line
);
do
{
if
(
*
line
==
0
||
*
line
==
';'
)
char
buffer
[
1024
];
continue
;
size_t
nbytes
=
is
.
LockRead
(
buffer
,
sizeof
(
buffer
),
error2
);
if
(
nbytes
==
0
)
{
if
(
error2
.
IsDefined
())
{
LogError
(
error2
);
return
nullptr
;
}
if
(
*
line
==
'['
)
/* another section starts; we only want
[Playlist], so stop here */
break
;
break
;
const
DivideString
ds
(
line
,
'='
,
true
);
if
(
!
ds
.
IsDefined
())
continue
;
const
char
*
const
name
=
ds
.
GetFirst
();
const
char
*
const
value
=
ds
.
GetSecond
();
if
(
StringEqualsCaseASCII
(
name
,
"NumberOfEntries"
))
{
n_entries
=
strtoul
(
value
,
nullptr
,
10
);
if
(
n_entries
==
0
)
/* empty file - nothing remains to be
done */
return
true
;
if
(
n_entries
>
MAX_ENTRIES
)
n_entries
=
MAX_ENTRIES
;
entries
.
resize
(
n_entries
);
}
else
if
(
StringEqualsCaseASCII
(
name
,
"File"
,
4
))
{
unsigned
i
=
strtoul
(
name
+
4
,
nullptr
,
10
);
if
(
i
>=
1
&&
i
<=
(
n_entries
>
0
?
n_entries
:
MAX_ENTRIES
))
{
if
(
entries
.
size
()
<
i
)
entries
.
resize
(
i
);
entries
[
i
-
1
].
file
=
value
;
}
}
else
if
(
StringEqualsCaseASCII
(
name
,
"Title"
,
5
))
{
unsigned
i
=
strtoul
(
name
+
5
,
nullptr
,
10
);
if
(
i
>=
1
&&
i
<=
(
n_entries
>
0
?
n_entries
:
MAX_ENTRIES
))
{
if
(
entries
.
size
()
<
i
)
entries
.
resize
(
i
);
entries
[
i
-
1
].
title
=
value
;
}
}
else
if
(
StringEqualsCaseASCII
(
name
,
"Length"
,
6
))
{
unsigned
i
=
strtoul
(
name
+
6
,
nullptr
,
10
);
if
(
i
>=
1
&&
i
<=
(
n_entries
>
0
?
n_entries
:
MAX_ENTRIES
))
{
if
(
entries
.
size
()
<
i
)
entries
.
resize
(
i
);
entries
[
i
-
1
].
length
=
atoi
(
value
);
}
}
}
}
kf_data
.
append
(
buffer
,
nbytes
);
if
(
n_entries
==
0
)
/*
Limit to 64k
*/
/*
no "NumberOfEntries" found
*/
}
while
(
kf_data
.
length
()
<
65536
)
;
return
false
;
if
(
kf_data
.
empty
())
{
auto
i
=
songs
.
before_begin
();
LogWarning
(
pls_domain
,
"KeyFile parser failed: No Data"
);
for
(
const
auto
&
entry
:
entries
)
{
return
nullptr
;
const
char
*
uri
=
entry
.
file
.
c_str
();
}
GKeyFile
*
keyfile
=
g_key_file_new
();
TagBuilder
tag
;
if
(
!
g_key_file_load_from_data
(
keyfile
,
if
(
!
entry
.
title
.
empty
())
kf_data
.
data
(),
kf_data
.
length
(),
tag
.
AddItem
(
TAG_TITLE
,
entry
.
title
.
c_str
());
G_KEY_FILE_NONE
,
&
error
))
{
FormatError
(
pls_domain
,
if
(
entry
.
length
>
0
)
"KeyFile parser failed: %s"
,
error
->
message
);
tag
.
SetDuration
(
SignedSongTime
::
FromS
(
entry
.
length
));
g_error_free
(
error
);
g_key_file_free
(
keyfile
);
i
=
songs
.
emplace_after
(
i
,
uri
,
tag
.
Commit
());
return
nullptr
;
}
}
return
true
;
}
static
bool
ParsePls
(
InputStream
&
is
,
std
::
forward_list
<
DetachedSong
>
&
songs
)
{
TextInputStream
tis
(
is
);
return
ParsePls
(
tis
,
songs
);
}
static
SongEnumerator
*
pls_open_stream
(
InputStream
&
is
)
{
std
::
forward_list
<
DetachedSong
>
songs
;
std
::
forward_list
<
DetachedSong
>
songs
;
pls_parser
(
keyfile
,
songs
);
if
(
!
ParsePls
(
is
,
songs
))
g_key_file_free
(
keyfile
)
;
return
nullptr
;
return
new
MemorySongEnumerator
(
std
::
move
(
songs
));
return
new
MemorySongEnumerator
(
std
::
move
(
songs
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment