#!/usr/bin/env ruby # encoding: utf-8 require "gst" if ARGV.length < 1 puts "usage: #{$0} " exit(false) end Gst.init playbin = Gst::ElementFactory.make("playbin", "playbin") if playbin.nil? puts "'playbin' gstreamer plugin missing" exit(false) end # take the commandline argument and ensure that it is a uri if Gst.valid_uri?(ARGV.first) uri = ARGV.first else uri = Gst.filename_to_uri(ARGV.first) end playbin.uri = uri playbin.pause sleep 1 p "slept" bus = playbin.bus tags=Gst::TagList.new while message=bus.pop if message.type==Gst::MessageType::TAG tags=tags.merge(message.parse_tag, Gst::TagMergeMode::KEEP) end end if tags.empty? puts "No metadata found for #{}" else tags.each do |taglist, tag| if taglist.get_tag_size(tag)==1 puts "%-15s: %s" % [Gst.tag_get_nick(tag), taglist.get_value_index(tag, 0).value] else puts "#{tag}" end end end puts tags class Gst::TagList def to_hash hash={}#Use symbol for hash keys? n_tags.times do |i| name=nth_tag_name(i) n=get_tag_size(name) if n==1 hash[name]=get_value_index(name, 0).value else hash[name]=[] n.times do |i| hash[name].push(get_value_index(name, i).value) end end end hash end alias_method :gi_each, :each def each(&block) to_hash.each(&block) end end tags.each{|name, value| puts "%-15s: %s" % [Gst.tag_get_nick(name), value]} p tags.to_hash p tags.each