Open neoice opened 9 years ago
Yeah, seems like the parser just strips the directory declarations out, leaving the last-modified timestamps in place. The implementation will need modification to remove those out as well.
for this category of problem, I always feel like my solution is brutish and inelegant. here's a fix that seems to resolve my test case issue: https://github.com/neoice/ruby-mpd/commit/577d810ea57922c4a58445e70f9b9eb5ff6467df
given that MPD::Parser#filter_lines
is dropping both :directory
and :playlist
, I'm not 100% sure what will happen to the Playlist objects. I'm attempting to test against that now.
root@3815993ad0f1:/# mpc lsplaylists
foobar
[1] pry(main)> @mpd = MPD.new ENV['MPD_HOST'], ENV['MPD_PORT']
=> #<MPD:0x00000003e0fdc8
@callbacks={},
@hostname="127.0.0.1",
@mutex=#<Mutex:0x00000003e0fcb0>,
@options={:callbacks=>false},
@password=nil,
@port="6600",
@socket=nil,
@tags=nil,
@version=nil>
[2] pry(main)> @mpd.connect
=> true
[3] pry(main)> @mpd.songs.count
=> 5
[4] pry(main)> @mpd.send('socket').puts 'listallinfo'
=> nil
[5] pry(main)> response = @mpd.send('handle_server_response')
=> "directory: test_library\nLast-Modified: 2015-08-07T14:50:41Z\nfile: test_library/Nova-139889831.mp3\nLast-Modified: 2014-03-16T18:46:30Z\nTime: 238\nfile: test_library/Indian_Summer-212174.mp3\nLast-Modified: 2009-04-04T13:04:47Z\nTime: 286\nArtist: canton\nTitle: Indian Summer\nAlbum: http://www.cantonbecker.com\nfile: test_library/Invisible_Space_Journeys-212173.mp3\nLast-Modified: 2009-04-04T13:01:05Z\nTime: 410\nArtist: canton\nTitle: Invisible Space Journeys\nAlbum: http://www.cantonbecker.com\nfile: test_library/Map_of_the_Cosmos-184608.mp3\nLast-Modified: 2009-03-16T01:37:52Z\nTime: 395\nArtist: canton\nTitle: Map of the Cosmos\nAlbum: http://www.cantonbecker.com\nfile: test_library/Sunflower-184607.mp3\nLast-Modified: 2009-03-16T01:37:39Z\nTime: 289\nArtist: canton\nTitle: Sunflower\nAlbum: http://www.cantonbecker.com\n"
looks like Playlist info doesn't actually come down with listallinfo
.
I looked into this and noticed that the MPD protocol documentation frowns on using listallinfo
and keeping a client-side copy of the database:
http://www.musicpd.org/doc/protocol/database.html
listallinfo [URI]
Same as listall, except it also returns metadata info in the same format as lsinfo.
Do not use this command. Do not manage a client-side copy of MPD's database. That is fragile and adds huge overhead. It will break with large databases. Instead, query MPD whenever you need something.
You can get an accurate song count from the stats
command:
mpd.send_command(:stats).fetch(:songs)
I'm working on Dockerizing an application that uses
ruby-mpd
. I include a small set of Creative Commons mp3s as a kind of "database seed". I noticed that@mpd.songs.count
was always 1 greater than the actual count of my library.using some Dirty Ruby Tricks(tm), I've traced it as follows:
note statements 11 and 12.
MPD::Parser#filter_lines
removes the "directory" line, but leaves behind the "Last-Modified" line associated with the directory. this later on manifests as a bizarre, inconsistent song list:3 songs where there should be 2, one with a
nil
@file
variable, another with anil
@time
variable.I have no idea what a fix would/should look like. I think I've spent all of today's brain juices tracing the issue this far.
as an additional exhibit, here's a data structure that has obviously weird behavior in
:"last-modified"
and:time
. I didn't trace it fully, but I assume this data structure will eventually become an array ofMPD::Song
objects. the mis-matched columns likely causes malformed objects to be created.