#!/usr/bin/ruby require 'mysql' MYTH_DIR = "RECORDINGS DIR eg. /mnt/mythtv-recordings" MYSQL_HOST = "localhost" MYSQL_USER = "DBUSER" MYSQL_PASS = "DBPASSWORD" MYSQL_DATABASE = "mythconverg" def connect begin $db = Mysql.real_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE) rescue Mysql::Error => e puts "Error code: #{e.errno}" puts "Error message: #{e.error}" puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate") end end def check if not File.exists? MYTH_DIR puts "Error: MYTH_DIR (#{MYTH_DIR}) does not exist" end $SYMLINK_DIR = "#{MYTH_DIR}/symlinks" if not File.exists? $SYMLINK_DIR Dir.mkdir $SYMLINK_DIR #puts "Created symlnk dir (#{$SYMLINK_DIR})" end if not Dir.chdir $SYMLINK_DIR puts "Error changing into symlink dir" exit end end def main connect() check() Dir.foreach(MYTH_DIR) do |file| next if not file =~ /\.nuv$/ query = $db.query("select *,DATE_FORMAT(starttime, '%Y-%m-%d %H:%i') as starttime, DATE_FORMAT(endtime, '%H:%i') as endtime from recorded where basename='#{file}';") info = query.fetch_hash next if info == nil symlink_name = "#{info['title'].gsub /[^A-Za-z0-9 \-]/, '_'} - #{info['starttime']} - #{info['endtime']}.nuv" if not File.symlink? symlink_name File.symlink("../#{file}", symlink_name) end end end main()