Sha256: ca21a923e49feb7e0b658a2a625da65d692d5d5f23f97aaaa0e02c386a685988

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

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
      return unless @current_path

      result = YAML.load_file(@current_path)
      File.exist?(result[:path]) ? result : self.next
    end

    def self.length
      Dir["/tmp/queue/*.yml"].length
    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.3.0 lib/vlcraptor/queue.rb