Coder Social home page Coder Social logo

Comments (2)

Phrogz avatar Phrogz commented on June 16, 2024

I've come up with a good solution, I think. It's in the 'answer' to the link above. The hash-for-filename was a bad idea, because it does not identify the files, and makes it very hard to edit them.

Instead, I've got test files like this sitting in a directory:

initialversion.recording

--putsabove--getsbelow--
OK MPD 0.19.0

listplaylists.recording

listplaylists
--putsabove--getsbelow--
playlist: Mix Rock Alternative Electric
Last-Modified: 2015-11-23T15:58:51Z
playlist: SNBRN
Last-Modified: 2016-01-26T00:25:52Z
playlist: Enya-esque
Last-Modified: 2015-11-18T16:19:12Z
playlist: RecentNice
Last-Modified: 2015-12-01T15:52:38Z
playlist: Dancetown
Last-Modified: 2015-11-18T16:19:26Z
playlist: Piano
Last-Modified: 2015-11-18T16:17:13Z
playlist: Thump
Last-Modified: 2015-11-20T15:32:30Z
playlist: GavinLikesIt
Last-Modified: 2015-11-20T15:54:49Z
OK

clear-and-add

command_list_begin
clear
addid test1.mp3
addid "test 2.mp3"
addid test3.mp3
command_list_end
--putsabove--getsbelow--
Id: 107
Id: 108
Id: 109
OK

...(more files)...

And now I can just do:

require '../lib/ruby-mpd'
require './socket_spoof'

class PlaybackMPD < MPD
  def initialize( recordings_directory=nil )
    super()
    @socket = SocketSpoof::Player.new(directory:recordings_directory)
  end
  def last_messages
    @socket.last_messages
  end
end

require 'minitest/autorun'
class TestQueue < MiniTest::Unit::TestCase
  def setup
    @mpd = PlaybackMPD.new 'socket_recordings'
  end

  def test_songs
    songs = @mpd.queue
    assert_equal ["playlistinfo"], @mpd.last_messages
    assert_equal 5, songs.length
    assert songs.all?{ |value| value.is_a? MPD::Song }
    assert_equal [310,226,243,258,347], songs.map(&:track_length)
  end

  def test_command_lists
    ids = @mpd.command_list(:values) do
      clear
      %w[test1.mp3 test\ 2.mp3 test3.mp3].each{ |f| addid(f) }
    end
    assert_equal(
      ["command_list_begin", "clear", "addid test1.mp3", 'addid "test 2.mp3"',
       "addid test3.mp3", "command_list_end"],
      @mpd.last_messages
    )
    assert_equal [107,108,109], ids

    pls = @mpd.command_list(:playlists){ playlists }
    assert_equal(
      ["command_list_begin", "listplaylists", "command_list_end"],
      @mpd.last_messages
    )
    assert_equal(8,pls.length)
    assert pls.all?{ |value| value.is_a? MPD::Playlist }
  end
end

from ruby-mpd.

Phrogz avatar Phrogz commented on June 16, 2024

Once I get a good suite of recordings saved (which, BTW, I can create super-easily by copy-pasting from a telnet-into-MPD session), I'll be checking this in as part of a test suite for command lists.

from ruby-mpd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.