'
vid = @bot.filter(:"youtube.video", s)
return nil unless vid
content = _("Category: %{cat}. Rating: %{rating}. Author: %{author}. Duration: %{duration}. %{views} views, faved %{faves} times. %{desc}") % vid
@@ -37,10 +40,11 @@ class YouTubePlugin < Plugin
end
# otherwise, just grab the proper div
if defined? Hpricot
- content = (Hpricot(s[:text])/"#mainContent").to_html.ircify_html
+ content = (Hpricot(s[:text])/".watch-video-desc").to_html.ircify_html
end
# suboptimal, but still better than the default HTML info extractor
- content ||= /
]*>/.match(s[:text]).post_match.ircify_html
+ dm = /
]*>/.match(s[:text])
+ content ||= dm ? dm.post_match.ircify_html : '(no description found)'
return {:title => s[:text].ircify_html_title, :content => content}
end
@@ -68,15 +72,7 @@ class YouTubePlugin < Plugin
vid[:desc].gsub!(/\s+/m, " ")
end
if secs = vid[:seconds]
- mins, secs = secs.divmod 60
- hours, mins = mins.divmod 60
- if hours > 0
- vid[:duration] = "%s:%s:%s" % [hours, mins, secs]
- elsif mins > 0
- vid[:duration] = "%s'%s\"" % [mins, secs]
- else
- vid[:duration] = "%ss" % [secs]
- end
+ vid[:duration] = Utils.secs_to_short(secs)
else
vid[:duration] = _("unknown duration")
end
@@ -85,7 +81,7 @@ class YouTubePlugin < Plugin
type = c.elements["@type"].value rescue nil
medium = c.elements["@medium"].value rescue nil
expression = c.elements["@expression"].value rescue nil
- duration = c.elements["@duration"].value rescue nil
+ seconds = c.elements["@duration"].value.to_i rescue nil
fmt = case num_fmt = (c.elements["@yt:format"].value rescue nil)
when "1"
"h263+amr"
@@ -101,10 +97,15 @@ class YouTubePlugin < Plugin
vid[:formats] << {
:url => url, :type => type,
:medium => medium, :expression => expression,
- :duration => duration,
+ :seconds => seconds,
:numeric_format => num_fmt,
:format => fmt
}.delete_if { |k, v| v.nil? }
+ if seconds
+ vid[:formats].last[:duration] = Utils.secs_to_short(seconds)
+ else
+ vid[:formats].last[:duration] = _("unknown duration")
+ end
end
}
debug vid
@@ -179,8 +180,15 @@ class YouTubePlugin < Plugin
vid = @bot.filter(:"youtube.video", :url => movie, :youtube_video_id => id)
if vid
- m.reply(_("%{bold}%{title}%{bold} [%{cat}] %{rating} @ %{url} by %{author} (%{duration}). %{views} views, faved %{faves} times. %{desc}") %
- {:bold => Bold}.merge(vid))
+ str = _("%{bold}%{title}%{bold} [%{cat}] %{rating} @ %{url} by %{author} (%{duration}). %{views} views, faved %{faves} times. %{desc}") %
+ {:bold => Bold}.merge(vid)
+ if @bot.config['youtube.formats'] and not vid[:formats].empty?
+ str << _("\n -- also available at: ")
+ str << vid[:formats].inject([]) { |list, fmt|
+ list << ("%{url} %{type} %{format} (%{duration} %{expression} %{medium})" % fmt)
+ }.join(', ')
+ end
+ m.reply str
else
m.reply(_("couldn't retrieve video info") % {:id => id})
end