Created
October 19, 2015 01:18
-
-
Save holman/745e61a2dbb25b993b1a to your computer and use it in GitHub Desktop.
Revisions
-
holman created this gist
Oct 19, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ # jekyll_media_length / by @holman # # Drop the length of a particular audio file and junk into your Jekyll page. # (See https://twitter.com/Una/status/655856628198014976 for more context). # # INSTALL: # # brew install taglib # gem install taglib-ruby # # Toss this file into your _plugins directory. # # USAGE: # # In your HTML page webzone device, do a liquid tag with the path to the audio # file, like: # # {% media_length media/song.mp3 %} # # => 4:12 # # YAY NEATO # # Have a cupcake, you've earned it. # require 'taglib' module Jekyll class MediaLength < Liquid::Tag def initialize(tag_name, filename, tokens) super @filename = filename.strip end def render(context) length = nil TagLib::FileRef.open(@filename) do |file| properties = file.audio_properties if file length = properties.length if properties end if length minutes = length / 60 seconds = length % 60 "#{minutes}:#{"%.2d" % seconds}" end end end end Liquid::Template.register_tag('media_length', Jekyll::MediaLength)