Skip to main content
Search
Search This Blog
Javier Isassi
Development tid-bits. Memos to self. Code. Cool and interesting stuff.
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
March 26, 2011
Play Podcast using mplayer Ruby and zenity
The following updated to previous post uses the program ffprobe to get the name of the podcast. Also uses clases. Just because.
#!/usr/bin/ruby require 'find' #this ruby script lets you access and play your podcasts or any mp4 file from your usb device mounted #in the directory: media in a Linux system (maybe Ubuntu). Notice i have my Ipod directory hard-code. #You can hard code yours or modify this script to pass the directory as a paramter. #Provecho. Javier Isassi MYDIR ='/media/Javier\'s Ipod/iPod_Control/Music/*/*.mp4' #first extend the String class with a method to strip quotation marks or any character for that matter. class String def strip_str(str) gsub(/^#{str}|#{str}$/, '') end end class PodcastPlayer def initialize(dirname) @pcasts = Dir[dirname].sort_by{ |f| File.ctime(f) } @pcastStr = "" @_pcast = "" @titles = [] @idx = 99 end def getPodcastTitle(p) album = "" podcastInfo = `ffprobe -v 0 -show_tags \"#{p}\"` podcastInfo.each do |l| l.chomp! tokens = l.split(/=/) if tokens[0] == "album" album << tokens[1] end end album end def play if @idx != 99 cmd = `mplayer \"#{@pcasts[@idx]}\"` end end def displayPanel @pcasts.each_with_index do |p, index| album = getPodcastTitle(p) if album == "" tokens = p.split(/\//) @pcastStr << "\"#{index}.- #{tokens.last}\"" << " " else @pcastStr << "\"" << "#{index}.- #{album}" << "\" " end end #puts "da string is #{@pcastStr}" @_pcast=`ans=$(zenity --width=120 --height=500 --list --column \"Podcast\" #{@pcastStr} --separator=\":\"); echo $ans` if @_pcast.chomp! == "" puts "goodbye!" else @idx = @_pcast.scan(/\d+/)[0].to_i puts "idx is now #{@idx}" end end def start displayPanel play end end myPcast = PodcastPlayer.new( MYDIR ) myPcast.start
Comments
Popular Posts
November 10, 2007
Fedora 8 Review on DELL D620.
June 30, 2009
Pesky c++ interview questions.
Comments