bin/xmltv2html.rb in xmltv2html-0.5.5 vs bin/xmltv2html.rb in xmltv2html-0.6.0

- old
+ new

@@ -1,10 +1,11 @@ -#!/usr/bin/ruby -w +#!/usr/bin/env ruby +#!/usr/bin/ruby -w # With Ruby 1.8.3, yaml gives a lot of warnings... :-(( # -# xmltv2html.rb - A Ruby script to tranform the XMLTV output into HTML. +# xmltv2html.rb - A Ruby script to transform the XMLTV output into HTML. # -# Version : 0.5.5 +# Version : 0.6.0 # Author : Kurt V. Hindenburg <public@kurt.hindenburg.name> # # Copyright (C) 2003, 2004, 2005 Kurt V. Hindenburg # # This program is free software; you can redistribute it and/or modify @@ -66,269 +67,223 @@ = BUGS * Please process the xmltv.xml file through tv_sort ((*before*)) using xmltv2html.rb =end -require "optparse" -require "rexml/document" +require 'optparse' +require 'yaml' +require 'rexml/document' require 'singleton' require 'time' +require 'set' -XMLTV2HTML_VERSION="0.5.5" -XMLTV2HTML_DATE="Sep 17, 2005" -module Xmltv2Html +XMLTV2HTML_VERSION="0.6.0" +XMLTV2HTML_DATE="Dec 18, 2005" - def die(*args) - $stderr.print args - exit(1) - end +class Time + class << self + ### Time.<method> - def info(*args) - $stderr.print args + # time string in format 'yyyymmddhhmmss (+/-xxxx)' + def parse_xmltv_time(str) + begin + Time::parse(str.split(' ')[0]) + rescue ArgumentError + die "Unable to parse #{str}\n\n" + end + end end + ### object.<method> + def round_to_interval + self - (self.min % @@options['time_divisor']) * 60 + end + end +module XMLTV2HTML + @@options = nil - -def die(*args) - $stderr.print args - exit(1) -end def info(*args) $stderr.print args, "\n" end + def die(*args) + info args + exit(1) + end - -class Config - attr_reader(:times_interval, :channels_interval, :time_format_12) - attr_reader(:use_config_file, :verbose, :output_links) - attr_reader(:date_format, :categories) - attr_reader(:use_favorites, :favorites) - attr_reader(:output_date_in_time, :css_filename) - attr_reader(:use_programme_popup, :programme_popup_method) - attr_reader(:popup_title_format, :popup_body_format) - attr_reader(:popup_title_background_color, :popup_title_color) - attr_reader(:popup_title_font_size, :popup_body_font_size) - attr_reader(:popup_body_background_color, :popup_body_color) - attr_reader(:popup_body_width) - attr_reader(:popup_title_font, :popup_body_font) - attr_reader(:time_divisor) - attr_accessor(:start_date, :stop_date) - attr_accessor(:days, :total_hours, :total_span) - attr_accessor(:url_next, :url_prev) - attr_accessor(:start_time, :stop_time) - attr_accessor(:output_favorites) - - def initialize - @opts = {} - @keys = %w{ times_interval chanels_interval time_format_12 } - @favorites = Hash.new - @use_config_file = true - @config_file="xmltv2htmlrc" - @total_hours = 0 - @total_span = 0 - @time_divisor = 10; # Divide programmes' times in X minute slots - @url_prev = nil - @url_next = nil - - setDefaults - handleOpts - readConfigFile if @config_file and @use_config_file - - # Convert favorite_list to Hash for fast lookup. - @favorite_list.each { |f| - f.gsub!(/&/,'&amp;') - @favorites[f] = true - } - @days = 1 + def test +# info "The West Wing=", @@options['favorites'].include?('The West Wing') +# info "EXTRA=", @@options['favorites'].include?('EXTRA') +# info "Lay & Order=", @@options['favorites'].include?("Law & Order") +# info "Categories=", @@options['categories'].class +# info "Categories=", @@options['categories'] +# info "start_time=",@@options['start_time'] +# info "stop_time=",@@options['stop_time'] end - def setDefaults - ### BEGIN CONFIGURATION - # + class ConfReader + def initialize + @@options = self # set Module variable + @cmd_line_options = nil + clear + set_defaults +# info "default config_file=",@@options['config_file'] + parse_command_line_options_for_config_file +# info "cmd_line config_file=",@@options['config_file'] +# info "cmd_line start_time=",@@options['start_time'] +# info "cmd_line stop_time=",@@options['stop_time'] - # Will output info to STDERR - @verbose = true - # Number of channels to repeat times horizontally; 0 to disable - @times_interval = 4 + read_conf if @@options['use_config_file'] +# info "start_time=",@@options['start_time'] +# info "stop_time=",@@options['stop_time'] + parse_command_line_options +# info "start_time=",@@options['start_time'] +# info "stop_time=",@@options['stop_time'] +# info "config_file=",@@options['config_file'] - # Number of hours to repeat channels vertically; 0 to disable - @channels_interval = 4 + # convert favorites_list to Set for faster lookup + @@options['favorites'] = Set.new @@options['favorites_list' ] - # true = 12 hour format; false = 24 hour format - @time_format_12 = true + test + end - # Use channel favorites? - @use_favorites = true + # Don't edit these, use an external xmltv2htmlrc file. + def set_defaults + @tree = { + 'verbose' => false, + 'times_interval' => 4, + 'channels_interval' => 4, + 'time_format_12' => true, + 'use_favorites' => false, + 'output_favorites' => false, + 'favorites_list' => [], + 'css_filename' => 'xmltv2html.css', + 'categories' => {}, + 'output_date_in_time' => false, + 'date_format' => '%a %d', + 'use_programme_popup' => true, + 'programme_popup_method' => "DHTML", + 'popup_title_format' => "%T", + 'popup_body_format' => "%S %P<br />%D<br />Rating: %R", + 'popup_title_color' => "#FFFFFF", + 'popup_title_font' => "", + 'popup_title_font_size' => "2", + 'popup_title_background_color' => "#000099", + 'popup_body_color' => "#000000", + 'popup_body_font' => "", + 'popup_body_font_size' => "1", + 'popup_body_background_color' => "#E8E8FF", + 'popup_body_width' => "200", + 'output_links' => false, + 'start_time' => "", + 'stop_time' => "", + 'start_date' => "", + 'stop_date' => "", + 'time_divisor' => 10, # Divide programmes' times in X minute slots + 'total_hours' => 0, + 'config_file' => "", + 'use_config_file' => true, + } + end - # List favorite channels below (seperate by a ',') - # The titles must be exact, not regular expressions. - @favorite_list = [ - "CSI: Crime Scene Investigation", - "Law & Order: Special Victims Unit", "Angel", "Law & Order", - "The Shield", "Law & Order: Criminal Intent", - "Charmed", "The West Wing" - ] - # Print out list of favorites beneath the listings? - @output_favorites = false + def [](key) + @tree[key] + end - # Name of CSS file - @css_filename = 'xmltv2html.css' + def []=(key, value) + @tree[key] = value + end - # Categories - use specified CSS class for given category. - # You must give the exact category for this to match. Look - # at the xml data file for a list of categories. - # Put the corresponding CSS class in your .css file - # .sports-event - # { - # color: red; - # background-color: white; - # } - @categories = { - "Sports event" => "sports-event", - "News" => "news" - } + def clear + @tree = Hash.new + end - # If true, will display date on the hour cell - # (helpful for multiple days). - # Color, etc in CSS file - @output_date_in_time = true + def read_conf + return if @@options['config_file'].empty? + f=File.expand_path(@@options['config_file']) + if not File.exists?(f) or not File.stat(f).readable_real? + info "* Unable to read #{f}\n" + return + end + new_xmltv2htmlrc_format = false + File.open(f, "r") do |aFile| + first_line = aFile.gets + new_xmltv2htmlrc_format = true if first_line =~ /^#config_version: 1/ + end + if new_xmltv2htmlrc_format == false + info "\nWhoa! You are using an old xmltv2htmlrc format file (v0.5.x)." + info "Please update your xmltv2htmlrc using the sample file provided" + info "with xmltv2html-0.6.0+." + die "\n" + end + info "^ Reading #{f}\n" + @tree.merge!(YAML::load(File.open(f))) + end - # The format to display the date - # %m = month (01..12); %d = day (01..31); %b = Abbr month (Jan) - # %a = Abbr weekday (Sun) - # @date_format = '%m-%d' - # @date_format = '%b %m-%d' - @date_format = '%a %d' - - # Should the programme's description 'popup' on mouseover? - # This will enlarge the output by the size of all the programme's - # descriptions. - @use_programme_popup = true - - # What method to use for popup? DHTML or STATUSBAR - # Some browsers disable pages from changing the statusbar. - @programme_popup_method = "DHTML" # "STATUSBAR" - - # Title is the top line of popup; body is the below part. - # Define the popup: %T = title, %S = sub-title - # %D = description, %R = rating - # %P = previously-shown; will display (R) - # Example: @popup_title_format = "%T" - # Example: @popup_body_format = "%D<br />%R" - # DHTML: You can put *some* CSS/HTML stuff here as well... - # STATUSBAR: NO HTML - @popup_title_format = "%T" - @popup_body_format = "%S %P<br />%D<br />Rating: %R" - - # Attributes for the DHTML popup - @popup_title_color = "#FFFFFF" - @popup_title_font = "" # "Utopia" - @popup_title_font_size = "2" # FONT SIZE= - @popup_title_background_color = "#000099" - @popup_body_color = "#000000" - @popup_body_font = "" # "Utopia" - @popup_body_font_size = "1" # FONT SIZE= - @popup_body_background_color = "#E8E8FF" - @popup_body_width = "200" # pixels - - # xmltv and xmltv2html home page links - @output_links = true - - @start_time = "" - @stop_time = "" - - ### END CONFIGURATION - end - - def readConfigFile - f=File.expand_path(@config_file) - return if not File.exists?(f) - return if not File.stat(f).readable_real? - begin - eval File.new(f).read - $stderr.print "^ Reading configuration file #{f}\n" if @verbose - rescue - warn("\nAn error occurred while reading #{f}; please fix!\n") - exit + # Check to see if --configfile= is present. + # TODO: Should be a way to do with with OptionParser + def parse_command_line_options_for_config_file + ARGV.each do + |opts| + if opts =~ /--configfile=/ + @@options['config_file'] = opts.split(/=/)[1] + end + end end - end - def handleOpts + # TODO: This has to be a better way to do this... + def parse_command_line_options + ARGV.options do + |opts| + opts.banner = "Usage: #{File.basename($0)} < xmltv.xml > tv.html\n" - ARGV.options do - |opts| - opts.banner = "Usage: #{File.basename($0)} < xmltv.xml > tv.html\n" + # separater + opts.on_tail + opts.on_tail("common options:") - # separater - opts.on_tail - opts.on_tail("common options:") + opts.on("--configfile=FILE", String, "config file to use") { + |@@options['config_file']|} - opts.on("-c", "--configfile=FILE", String, "config file to use") { - |@config_file|} - opts.on("--noconfigfile","do NOT use any config file") { - @use_config_file = false} + opts.on("--starttime=YYYYMMDDHHMM", String, "Start time") { + |@@options['start_time']|} + opts.on("--stoptime=YYYYMMDDHHMM", String, "Stop time") { + |@@options['stop_time']|} - opts.on("--starttime=YYYYMMDDHHMM", String, "Start time") { |@start_time|} - opts.on("--stoptime=YYYYMMDDHHMM", String, "Stop time") { |@stop_time|} + opts.on("--urlprev=URL", String, "URL for previous link") { + |@@options['url_prev']|} + opts.on("--urlnext=URL", String, "URL for next link") { + |@@options['url_next']|} - opts.on("--urlprev=URL", String, "URL for previous link") { |@url_prev|} - opts.on("--urlnext=URL", String, "URL for next link") { |@url_next|} + # no argument, shows at tail + opts.on_tail("-h", "--help", "show this message") {puts opts; exit} - # no argument, shows at tail - opts.on_tail("-h", "--help", "show this message") {puts opts; exit} + opts.on_head("specific options:") - opts.on_head("specific options:") - - # no argument - opts.on_tail("-v", "--version", "show version") do - print "xmltv2html.rb v#{XMLTV2HTML_VERSION} (#{XMLTV2HTML_DATE})\n\n" - print "Copyright (C) 2003, 2004, 2005 Kurt V. Hindenburg\n" - print "This is free software; see the source for copying conditions. There is NO\n" - print " warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" - print "\npublic@kurt.hindenburg.name\n" - + # no argument + opts.on_tail("-v", "--version", "show version") do + print <<EOF +xmltv2html.rb v#{XMLTV2HTML_VERSION} (#{XMLTV2HTML_DATE})\n +Copyright (C) 2003, 2004, 2005 Kurt V. Hindenburg (public@kurt.hindenburg.name) +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +EOF exit end begin opts.parse! rescue die "\n * Invalid parameters given!\n\n" end end end -end - -class Time - - class << self - ### Time.<method> - - # time string in format 'yyyymmddhhmmss (+/-xxxx)' - def parse_xmltv_time(str) - begin - Time.parse(str.split(' ')[0]) - rescue ArgumentError - die "Unable to parse #{str}\n\n" - end - end end - ### object.<method> - - # TODO: cache $params.time_divisor - def round_to_interval - self - (self.min % $params.time_divisor) * 60 - end - -end - class ProgrammeTime attr_reader(:fullStartTime, :fullStopTime) def initialize(start, stop) @fullStartTime = Time.parse_xmltv_time(start) @@ -351,25 +306,25 @@ end pt end def calculateStartSlot - return if $params.start_date == nil # 1st pass - @start_date = returnParsedTime($params.start_date) if not @start_date + return if @@options['start_date'] == nil # 1st pass + @start_date = returnParsedTime(@@options['start_date']) if not @start_date start_diff_min = ((@fullStartTime - @start_date) / 60).to_i # $stderr.print ", diff #{start_diff_min}" - start_slot = start_diff_min / $params.time_divisor + start_slot = start_diff_min / @@options['time_divisor'] # $stderr.print "starting slot #{start_slot}\n" start_slot end def calculateStopSlot - return if $params.stop_date == nil # 1st pass + return if @@options['stop_date'] == nil # 1st pass - @start_date = returnParsedTime($params.start_date) if not @start_date + @start_date = returnParsedTime(@@options['start_date']) if not @start_date stop_diff_min = ((@fullStopTime - @start_date) / 60).to_i - stop_slot = stop_diff_min / $params.time_divisor + stop_slot = stop_diff_min / @@options['time_divisor'] # $stderr.print " stoping slot #{stop_slot}\n" # (@fullStopTime.hour * 60 / $timeDivisor) + (@fullStopTime.min / $timeDivisor) stop_slot end @@ -378,15 +333,13 @@ class Programme attr_reader :title, :subtitle, :span, :times, :desc, :rating, :category attr_reader :previouslyShown, :spanSlots, :startSlot attr_accessor :popupIndex -# attr_accessor :popupIndex def initialize(title, subtitle, channel, start, stop, desc, rating, cats, rerun) @title = title - @title.gsub!(/&/,'&amp;') @subtitle = subtitle @channelid = channel @desc = desc @rating = rating @category = cats @@ -405,18 +358,10 @@ return if not @stopSlot @spanSlots = @stopSlot - @startSlot end -# def start_time -# @times.start_time -# end - -# def stop_time -# @times.stop_time -# end - def to_s @title end end @@ -502,11 +447,11 @@ p.calculateSlots } end def calculateSlots(slist) - tinterval = $params.channels_interval * 60 / $params.time_divisor + tinterval = @@options['channels_interval'] * 60 / @@options['time_divisor'] left = [] right = slist.dup index = 0 total = 0 slist.each { |e| @@ -548,20 +493,20 @@ # left.each { |i| $stderr.print "#{i}*" }; $stderr.print "\n" left end # Create a slot list to account for displaying channel info - # $params.channel_interval = # of hours to display channel info + # channel_interval = # of hours to display channel info # Handle empty programmes at start/end of channel. def createSlotList l = Array.new span_counter = 0 times_counter = 1 sindex = 0 total = 0 - if $params.channels_interval > 0 - tinterval = $params.channels_interval * 60 / $params.time_divisor + if @@options['channels_interval'] > 0 + tinterval = @@options['channels_interval'] * 60 / @@options['time_divisor'] else tinterval = 9999 end ci = tinterval @@ -577,11 +522,11 @@ @programmes[@id].each { |s| slist.push "P"+s.spanSlots.to_s } - if $params.channels_interval > 0 + if @@options['channels_interval'] > 0 sl = calculateSlots(slist) while sl != slist slist = sl.dup sl = calculateSlots(sl) end @@ -589,22 +534,22 @@ slist.each { |entry| span = entry.slice(1..-1).to_i l.push entry total += span - l.push("C0") if (total % tinterval) == 0 and $params.channels_interval > 0 + l.push("C0") if (total % tinterval) == 0 and @@options['channels_interval'] > 0 } slist = l.unshift("C0") # Add left-most channel # Add left-most channel if not already there # slist = l # slist = l.unshift("C0") if l[0] != "C0" # slist = l.unshift("C0") if l[0, 1] != "C0" # $stderr.print slist[0, 3],"\n" # $stderr.print l[0, 3],"\n" - dinterval = $params.total_hours * 60 / $params.time_divisor + dinterval = @@options['total_hours'] * 60 / @@options['time_divisor'] if total < dinterval # Not enough programmes' data at end slist.push("D"+(dinterval - total).to_s) slist.push("C0") if dinterval % tinterval == 0 end @@ -699,11 +644,10 @@ } end def parseProgrammes channels = Channels.instance - @doc.elements.each("tv/programme") { |element| title="" subtitle="" desc="" rating="" @@ -718,46 +662,51 @@ dstart = start[0..13] dstop = stop[0..13] ext = start[14..-1] - if not $params.start_time.empty? -# $stderr.print "Desired start : #{$params.start_time}\n" - nstart = $params.start_time.clone - nstart[10..11] = $params.time_divisor.to_s +# info "start_time=",@@options['start_time'] +# info "stop_time=",@@options['stop_time'] +# info "empty?" ,@@options['start_time'].empty? + if not @@options['start_time'].empty? + nstart = @@options['start_time'].clone + nstart[10..11] = @@options['time_divisor'].to_s # If programme ends before the desired start time... # Adjust for the time_divisor (round_to_interval) if dstop < nstart +# info "Delete programme - Desired start : #{@@options['start_time']}, " # $stderr.print "Delete programme - Desired start : #{$params.start_time}, " # $stderr.print "programme stop : #{dstop}\n" # $stderr.print "Old start time = #{$params.start_time}, new=#{nstart}\n" next end end - # If programme starts after the desired stop time... - if (not $params.stop_time.empty?) and (dstart >= $params.stop_time) + if (not @@options['stop_time'].empty?) and (dstart >= @@options['stop_time']) # $stderr.print "Delete programme - Desired stop : #{$params.stop_time}, " # $stderr.print "programme start : #{dstart}\n" +# info "programme start : #{dstart}\n" next end # If programme starts before the desired start time, change start - if (not $params.start_time.empty?) and (dstart < $params.start_time) + if (not @@options['start_time'].empty?) and (dstart < @@options['start_time']) +# info "Change Start - new start : " # $stderr.print "Change Start - new start : #{$params.start_time}, " # $stderr.print "old start: #{dstart}\n" # ndesc = "(" + start[8..9] + ":" + start[10..11] + ") " - start = $params.start_time + ext + start = @@options['start_time'] + ext dstart = start[0..13] end # If programme ends after the desired stop time, change stop - if (not $params.stop_time.empty?) and (dstop > $params.stop_time) - stop = $params.stop_time + ext + if (not @@options['stop_time'].empty?) and (dstop > @@options['stop_time']) + stop = @@options['stop_time'] + ext +# info "Change Stop - new stopt : " dstop = stop[0..13] end @firstShowStartDate = dstart if @firstShowStartDate > dstart @lastShowStartDate = dstart if @lastShowStartDate < dstart @@ -775,13 +724,12 @@ end # Check to see if user want to use special CSS class for category # FIXME: What happens when more than 1 category is triggered? if e.name == "category" - if $params.categories.has_key?(e.text()) -# $stderr.print "found #{e.text()}, using #{$params.categories[e.text()]}\n" - cats = $params.categories[e.text()]; + if @@options['categories'].has_key?(e.text()) + cats = @@options['categories'][e.text()]; end end } title.gsub!(/[\"\'\`]/,'') # Remove "'` @@ -807,11 +755,11 @@ end end -class XMLTV2HTML +class XMLTV2HTML2 attr_accessor(:dates) def initialize @xml = XmlTV.new @out = Html.new @@ -823,38 +771,36 @@ @xml.parseChannels @xml.parseProgrammes - $params.start_date = @xml.firstShowStartDate - $params.stop_date = @xml.lastShowStopDate -# $stderr.print "Starting listings at #{$params.start_date}\n" -# $stderr.print "Stopping listings at #{$params.stop_date}\n" + @@options['start_date'] = @xml.firstShowStartDate + @@options['stop_date'] = @xml.lastShowStopDate # Force start/stop time on hour - $params.start_date[10,4] = "0000" + @@options['start_date'][10,4] = "0000" - if $params.stop_date[10,2] != "00" - hour = ($params.stop_date[8,2]).to_i + 1 +# info "start_date=",@@options['start_date'] +# info "stop_date= ",@@options['stop_date'] + if @@options['stop_date'][10,2] != "00" + hour = (@@options['stop_date'][8,2]).to_i + 1 if hour > 23 $stderr.print "yuck #{hour}\n" end - $params.stop_date[8,2] = hour.to_s.rjust(2).sub(/\s/,'0') + @@options['stop_date'][8,2] = hour.to_s.rjust(2).sub(/\s/,'0') end - $params.stop_date[10,4] = "0000" -# $stderr.print "Starting listings at #{$params.start_date}\n" -# $stderr.print "Stopping listings at #{$params.stop_date}\n" + @@options['stop_date'][10,4] = "0000" - pstart = Time.parse($params.start_date) - pstop = Time.parse($params.stop_date) - $params.total_hours = ((pstop - pstart) / 3600).to_i + pstart = Time.parse(@@options['start_date']) + pstop = Time.parse(@@options['stop_date']) + @@options['total_hours'] = ((pstop - pstart) / 3600).to_i channels = Channels.instance channels.calc_programmes_slots - fdate = $params.start_date[0,8] - ldate = $params.stop_date[0,8] + fdate = @@options['start_date'][0,8] + ldate = @@options['stop_date'][0,8] @xml.setTitle(@dates) end @@ -876,11 +822,11 @@ @out.dates = @dates @out.doctype @out.header(@xml.HTML_title) - generatePopups if $params.use_programme_popup + generatePopups if @@options['use_programme_popup'] @out.text_before_table(@xml.top_title) @out.table_start @out.table_times channels = Channels.instance @@ -902,11 +848,11 @@ sindex += 1 pi += 1 prog = c.programme_at(pi) @out.outputProgramme(prog, sindex, span) # @out.outputProgramme(c.programme_at(pi), sindex, span) - if $params.use_favorites and $params.output_favorites and $params.favorites.has_key?(prog.title) + if @@options['use_favorites'] and @@options['output_favorites'] and @@options['favorites'].include?(prog.title) #$stderr.print "found a fav #{prog.title}\n" favorites_list << prog end when "Q" # Use previous Programme's info @out.outputProgramme(c.programme_at(pi), sindex, span) @@ -916,11 +862,11 @@ $stderr.print "Unknown slot entry #{entry}\n" ; exit end i += 1 } @out.outputChannelEnd - @out.table_times if times_counter % $params.times_interval == 0 + @out.table_times if times_counter % @@options['times_interval'] == 0 times_counter += 1 } @out.table_end @@ -956,15 +902,15 @@ print '<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1">'; nl print '<meta http-equiv="Content-language" content="en">'; nl print '<title>' print title if title print '</title>'; nl - print '<link rel="stylesheet" href="', $params.css_filename + print '<link rel="stylesheet" href="', @@options['css_filename'] print '" type="text/css">'; nl - if $params.use_programme_popup - if $params.programme_popup_method == "DHTML" + if @@options['use_programme_popup'] + if @@options['programme_popup_method'] == "DHTML" print '<script language="JavaScript1.2" src="popup.js" type="text/javascript"></script>'; nl else print '<script language="JavaScript1.2" type="text/javascript">' # April 02, 2004 : This doesn't work with Konqueor3.2.1 # nor firefox0.8 @@ -985,39 +931,38 @@ print 'var FiltersEnabled = 0 // if your not going to use transitions or filters in any of the tips set this to 0'; nl # Styles print 'Style[1]=[' - print '"', $params.popup_title_color, '",' - print '"', $params.popup_body_color, '",' - print '"', $params.popup_title_background_color, '",' - print '"', $params.popup_body_background_color, '",' + print '"', @@options['popup_title_color'], '",' + print '"', @@options['popup_body_color'], '",' + print '"', @@options['popup_title_background_color'], '",' + print '"', @@options['popup_body_background_color'], '",' print '"","","","",' - print '"', $params.popup_title_font, '",' - print '"', $params.popup_body_font, '",' + print '"', @@options['popup_title_font'], '",' + print '"', @@options['popup_body_font'], '",' print '"center","",' - print '"', $params.popup_title_font_size, '",' - print '"', $params.popup_body_font_size, '",' - print $params.popup_body_width, ',' + print '"', @@options['popup_title_font_size'], '",' + print '"', @@options['popup_body_font_size'], '",' + print @@options['popup_body_width'], ',' print '"",' print '3,' # Border width print '10,' # Padding around body text print '20, 20, "", "", "", "", ""]' - print nl - + nl print 'applyCssFilter()'; nl print '</script>'; nl nl end def outputPopupDescs(c, cindex) # The descriptions go here...Text[#]=["title","text"] c.programmes[c.id()].each { |s| - title = $params.popup_title_format.sub(/\%T/, s.title) + title = @@options['popup_title_format'].sub(/\%T/, s.title) title.sub!(/\%R/, s.rating) - desc = $params.popup_body_format.gsub(/%T/, s.title) + desc = @@options['popup_body_format'].gsub(/%T/, s.title) desc.sub!(/\%S/, s.subtitle) if (s.previouslyShown) # rerun desc.sub!(/\%P/, "(R)") else desc.sub!(/\%P/, "") @@ -1043,36 +988,36 @@ if text print '<center><h3>' print text print '</h3></center>'; nl end - if $params.url_prev + if @@options['url_prev'] print '<a class="links" href="' - print $params.url_prev + print @@options['url_prev'] print '"><<< Previous</a> | ' end - if $params.url_next + if @@options['url_next'] print '<a class="links" href="' - print $params.url_next + print @@options['url_next'] print '">Next >>></a>' end end def text_after_table - if $params.url_prev + if @@options['url_prev'] print '<a class="links" href="' - print $params.url_prev + print @@options['url_prev'] print '"><<< Previous</a> | ' end - if $params.url_next + if @@options['url_next'] print '<a class="links" href="' - print $params.url_next + print @@options['url_next'] print '">Next >>></a>' end print '<br />' outputInfo - outputLinks if $params.output_links + outputLinks if @@options['output_links'] end def table_start print '<table width="100%" border="3" cellpadding="3">'; nl end @@ -1086,81 +1031,79 @@ end def outputDate days = @hours/24 colspan = 96 - colspan += 96 / $params.channels_interval if $params.channels_interval > 0 + colspan += 96 / @@options['channels_interval'] if @@options['channels_interval'] > 0 print '<tr class="date">'; nl (0 .. days-1).each { |d| print '<td colspan="',colspan,'" align="center">','date here','</td>'; nl } print '</tr>'; nl end def table_times - intervals = 60 / $params.time_divisor + intervals = 60 / @@options['time_divisor'] -# $stderr.print "Starting time #{$params.start_date}\n" -# $stderr.print "Stoping time #{$params.stop_date}\n" # Need hour to start.... we'll force it to be on an hour later - starting_day = $params.start_date[6,2].to_i - starting_hour = $params.start_date[8,2].to_i + starting_day = @@options['start_date'][6,2].to_i + starting_hour = @@options['start_date'][8,2].to_i # $stderr.print "Day to start: #{starting_day}\n" # $stderr.print "Hour to start: #{starting_hour}\n" # $stderr.print "Total hours: #{$params.total_hours}\n" print '<tr class="time">'; nl output_channel_space cs = 0 - (starting_hour .. starting_hour + $params.total_hours - 1).each { |h| + (starting_hour .. starting_hour + @@options['total_hours'] - 1).each { |h| (0 .. intervals-1).each { |hh| print '<td>'; - printf "%02d", hh * $params.time_divisor; print '</td>'; + printf "%02d", hh * @@options['time_divisor']; print '</td>'; } cs += 1 - output_channel_space if $params.channels_interval > 0 and cs % $params.channels_interval == 0 + output_channel_space if @@options['channels_interval'] > 0 and cs % @@options['channels_interval'] == 0 } print '</tr>'; nl print '<tr class="time">'; nl output_channel_space days = @hours/24 cs = 0 - cdate = Time.parse($params.start_date) + cdate = Time.parse(@@options['start_date']) - (starting_hour .. starting_hour + $params.total_hours - 1).each { |hi| + (starting_hour .. starting_hour + @@options['total_hours'] - 1).each { |hi| h = hi % 24 print '<td colspan="',intervals,'" class="time">'; - if $params.output_date_in_time + if @@options['output_date_in_time'] nl; print '<table width="100%" border="0" cellpadding="0">'; nl print '<tr><td align="left" class="time">'; end - if $params.time_format_12 + if @@options['time_format_12'] if h < 12 out = "#{h} am" else out = (h - 12).to_s + " pm" end out.gsub!(/^0/, '12') else out = sprintf "%02d", h end print out - if $params.output_date_in_time + if @@options['output_date_in_time'] print '<td align="right" class="date_in_time">'; - print cdate.strftime($params.date_format) + print cdate.strftime(@@options['date_format']) print '</td></tr>'; nl; print '</table></td>'; nl else print '</td>'; end cs += 1 cdate += 3600 # Add 1 hour - output_channel_space if $params.channels_interval > 0 and cs % $params.channels_interval == 0 + output_channel_space if @@options['channels_interval'] > 0 and cs % @@options['channels_interval'] == 0 } print '</tr>'; nl end def outputChannelBegin @@ -1177,28 +1120,29 @@ def outputDummyProgramme(span) print '<td colspan="',span,'" class="dummy">No Data</td>' end def outputProgramme(s, index, slots) + return if s.spanSlots == 0 # Invalid programme - too short if slots > 0 print '<td colspan="', slots, '" class="' else print '<td colspan="',s.spanSlots,'" class="' end # Favorites override category. - if $params.use_favorites and $params.favorites.has_key?(s.title) + if @@options['use_favorites'] and @@options['favorites'].include?(s.title) print 'favorite">' elsif s.category print s.category,'">' else print 'programme">' end # Styles : 12=right; 1=center; 2=left; 3=float - if $params.use_programme_popup + if @@options['use_programme_popup'] if s.popupIndex >= 0 - if $params.programme_popup_method == "DHTML" + if @@options['programme_popup_method'] == "DHTML" print '<a onmouseover="stm(Text[', s.popupIndex print '],Style[1])" onmouseout="htm()">'; nl else print '<a language="Javascript" ' print 'onmouseover="window.status=Text[', s.popupIndex @@ -1268,21 +1212,31 @@ nl end end -$params = Config.new -xmltv2html = XMLTV2HTML.new +end +include XMLTV2HTML + +trap("INT") do + info "\n Received user interrupt...exiting.\n" + exit +end + +confreader = ConfReader.new + +xmltv2html = XMLTV2HTML2.new + time1 = Time.new xmltv2html.parseXML time2 = Time.new -$stderr.print "^ Parsing XML took #{time2-time1} seconds.\n" if $params.verbose +$stderr.print "^ Parsing XML took #{time2-time1} seconds.\n" time3 = Time.new xmltv2html.generateHTML time4 = Time.new -$stderr.print "^ Generating HTML took #{time4-time3} seconds.\n" if $params.verbose +$stderr.print "^ Generating HTML took #{time4-time3} seconds.\n" exit # vim:set ts=3 sw=3 expandtab: