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
e2da13b0
Commit
e2da13b0
authored
5 years ago
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/file: add command "readpicture"
Closes
https://github.com/MusicPlayerDaemon/MPD/issues/42
parent
54daa85a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
0 deletions
+89
-0
NEWS
NEWS
+1
-0
protocol.rst
doc/protocol.rst
+24
-0
AllCommands.cxx
src/command/AllCommands.cxx
+1
-0
FileCommands.cxx
src/command/FileCommands.cxx
+60
-0
FileCommands.hxx
src/command/FileCommands.hxx
+3
-0
No files found.
NEWS
View file @
e2da13b0
...
...
@@ -2,6 +2,7 @@ ver 0.22 (not yet released)
* protocol
- "findadd"/"searchadd"/"searchaddpl" support the "sort" and
"window" parameters
- add command "readpicture" to download embedded pictures
* tags
- new tags "Grouping" (for ID3 "TIT1") and "Work"
* input
...
...
This diff is collapsed.
Click to expand it.
doc/protocol.rst
View file @
e2da13b0
...
...
@@ -1005,6 +1005,30 @@ The music database
decoder plugins support it. For example, on Ogg files,
this lists the Vorbis comments.
:command:`readpicture {URI} {OFFSET}`
Locate a picture for the given song and return a chunk of the
image file at offset ``OFFSET``. This is usually implemented by
reading embedded pictures from binary tags (e.g. ID3v2's ``APIC``
tag).
Returns the following values:
- ``size``: the total file size
- ``type``: the file's MIME type (optional)
- ``binary``: see :ref:`binary`
If the song file was recognized, but there is no picture, the
response is successful, but is otherwise empty.
Example::
readpicture foo/bar.ogg 0
size: 1024768
type: image/jpeg
binary: 8192
<8192 bytes>
OK
.. _command_search:
:command:`search {FILTER} [sort {TYPE}] [window {START:END}]`
...
...
This diff is collapsed.
Click to expand it.
src/command/AllCommands.cxx
View file @
e2da13b0
...
...
@@ -168,6 +168,7 @@ static constexpr struct command commands[] = {
{
"rangeid"
,
PERMISSION_ADD
,
2
,
2
,
handle_rangeid
},
{
"readcomments"
,
PERMISSION_READ
,
1
,
1
,
handle_read_comments
},
{
"readmessages"
,
PERMISSION_READ
,
0
,
0
,
handle_read_messages
},
{
"readpicture"
,
PERMISSION_READ
,
2
,
2
,
handle_read_picture
},
{
"rename"
,
PERMISSION_CONTROL
,
2
,
2
,
handle_rename
},
{
"repeat"
,
PERMISSION_CONTROL
,
1
,
1
,
handle_repeat
},
{
"replay_gain_mode"
,
PERMISSION_CONTROL
,
1
,
1
,
...
...
This diff is collapsed.
Click to expand it.
src/command/FileCommands.cxx
View file @
e2da13b0
...
...
@@ -26,6 +26,7 @@
#include "client/Client.hxx"
#include "client/Response.hxx"
#include "util/CharUtil.hxx"
#include "util/OffsetPointer.hxx"
#include "util/StringView.hxx"
#include "util/UriExtract.hxx"
#include "tag/Handler.hxx"
...
...
@@ -270,3 +271,62 @@ handle_album_art(Client &client, Request args, Response &r)
return
CommandResult
::
ERROR
;
}
class
PrintPictureHandler
final
:
public
NullTagHandler
{
Response
&
response
;
const
size_t
offset
;
bool
found
=
false
;
bool
bad_offset
=
false
;
public
:
PrintPictureHandler
(
Response
&
_response
,
size_t
_offset
)
noexcept
:
NullTagHandler
(
WANT_PICTURE
),
response
(
_response
),
offset
(
_offset
)
{}
void
RethrowError
()
const
{
if
(
bad_offset
)
throw
ProtocolError
(
ACK_ERROR_ARG
,
"Bad file offset"
);
}
void
OnPicture
(
const
char
*
mime_type
,
ConstBuffer
<
void
>
buffer
)
noexcept
override
{
if
(
found
)
/* only use the first picture */
return
;
found
=
true
;
if
(
offset
>
buffer
.
size
)
{
bad_offset
=
true
;
return
;
}
response
.
Format
(
"size: %"
PRIoffset
"
\n
"
,
buffer
.
size
);
if
(
mime_type
!=
nullptr
)
response
.
Format
(
"type: %s
\n
"
,
mime_type
);
buffer
.
size
-=
offset
;
if
(
buffer
.
size
>
Response
::
MAX_BINARY_SIZE
)
buffer
.
size
=
Response
::
MAX_BINARY_SIZE
;
buffer
.
data
=
OffsetPointer
(
buffer
.
data
,
offset
);
response
.
WriteBinary
(
buffer
);
}
};
CommandResult
handle_read_picture
(
Client
&
client
,
Request
args
,
Response
&
r
)
{
assert
(
args
.
size
==
2
);
const
char
*
const
uri
=
args
.
front
();
const
size_t
offset
=
args
.
ParseUnsigned
(
1
);
PrintPictureHandler
handler
(
r
,
offset
);
TagScanAny
(
client
,
uri
,
handler
);
handler
.
RethrowError
();
return
CommandResult
::
OK
;
}
This diff is collapsed.
Click to expand it.
src/command/FileCommands.hxx
View file @
e2da13b0
...
...
@@ -36,4 +36,7 @@ handle_read_comments(Client &client, Request request, Response &response);
CommandResult
handle_album_art
(
Client
&
client
,
Request
request
,
Response
&
response
);
CommandResult
handle_read_picture
(
Client
&
client
,
Request
request
,
Response
&
response
);
#endif
This diff is collapsed.
Click to expand it.
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