X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fyoutube.rb;h=40922b7d39f5ddb3ec3d83cefd5bbadff6e33cf7;hb=7a128ab6457c9b79ed31a5562be98e1718bfaf80;hp=947156bc4f40472b8447624a508094ba4e27bda6;hpb=78ccfb89403dc2fd2c06d4bbaca2129e2ba4c968;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/youtube.rb b/data/rbot/plugins/youtube.rb index 947156bc..40922b7d 100644 --- a/data/rbot/plugins/youtube.rb +++ b/data/rbot/plugins/youtube.rb @@ -27,7 +27,7 @@ class YouTubePlugin < Plugin def youtube_filter(s) loc = Utils.check_location(s, /youtube\.com/) return nil unless loc - if s[:text].include? '
' + if s[:text].include? '
' 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 @@ -40,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 @@ -71,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 @@ -109,15 +102,7 @@ class YouTubePlugin < Plugin :format => fmt }.delete_if { |k, v| v.nil? } if seconds - mins, secs = seconds.divmod 60 - hours, mins = mins.divmod 60 - if hours > 0 - vid[:formats].last[:duration] = "%s:%s:%s" % [hours, mins, secs] - elsif mins > 0 - vid[:formats].last[:duration] = "%s'%s\"" % [mins, secs] - else - vid[:formats].last[:duration] = "%ss" % [secs] - end + vid[:formats].last[:duration] = Utils.secs_to_short(seconds) else vid[:formats].last[:duration] = _("unknown duration") end