Sha256: 2383990b9fab088da6ce477f567cecbb77f38311e7886c80235165991c604ca2

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

require "yaml"
require "hearken/range_expander"

module Hearken
  module Command
    class Enqueue
      attr_reader :usage, :help

      def initialize(library)
        @usage = "*<id>"
        @help = "enqueues the list of songs with the specified ids"
        @expander = Hearken::RangeExpander.new
        @library = library
      end

      def execute(text)
        `mkdir -p /tmp/queue`
        count = (Time.now.to_f * 1000).to_i
        @expander.expand(text).each do |id|
          @library.with_track id do |track|
            meta = {
              title: track.title,
              artist: track.artist,
              album: track.album,
              length: track.time.to_i,
              path: track.path
            }
            File.open("/tmp/queue/#{count}.yml", "w") { |f| f.puts meta.to_yaml }
            count += 1
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hearken-0.1.3 lib/hearken/command/enqueue.rb