Sha256: a635313c155bcaba97efeb04a079ba5dc1cff5464620938ce30da6048e42eb31

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

require "yaml"
require_relative "ffmpeg"

module Vlcraptor
  class Queue
    def initialize
      @current_path = nil
    end

    def next
      `rm -f #{@current_path}` if @current_path
      @current_path = Dir["/tmp/queue/*.yml"].min
      YAML.load_file(@current_path) if @current_path
    end

    def self.each
      Dir["/tmp/queue/*.yml"].sort.each do |path|
        yield YAML.load_file path
      end
    end

    def self.add(path)
      unless %w[.mp3 .m4a].include?(File.extname(path))
        puts "skipping #{path}"
        return
      end

      puts "adding #{path}"
      tags = Vlcraptor::Ffmpeg.new(path)
      meta = {
        title: tags.title,
        artist: tags.artist,
        album: tags.album,
        length: tags.time,
        path: File.expand_path(path),
      }
      `mkdir -p /tmp/queue`
      File.open("/tmp/queue/#{(Time.now.to_f * 1000).to_i}.yml", "w") { |f| f.puts meta.to_yaml }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vlcraptor-0.2.0 lib/vlcraptor/queue.rb