[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kubeplayer] lib/provider/youtube: adding automatic iterating of
From:       Robert Riemann <robert.riemann () physik ! hu-berlin ! de>
Date:       2011-09-01 21:10:44
Message-ID: 20110901211044.A63F4A6078 () git ! kde ! org
[Download RAW message or body]

Git commit 131543e5ede308fc5d4e0c51fea934e3ac845773 by Robert Riemann.
Committed on 01/09/2011 at 23:07.
Pushed by rriemann into branch 'master'.

adding automatic iterating of youtube el param

For some videos Youtube allow only the playback
when using a special el parameter while video
requesting. The following patch iterates
automatically over different parameters before
stopping with an error message shown to the user.

M  +19   -5    lib/provider/youtube/Youtube.rb

http://commits.kde.org/kubeplayer/131543e5ede308fc5d4e0c51fea934e3ac845773

diff --git a/lib/provider/youtube/Youtube.rb b/lib/provider/youtube/Youtube.rb
index e04b518..e7fcb09 100644
--- a/lib/provider/youtube/Youtube.rb
+++ b/lib/provider/youtube/Youtube.rb
@@ -48,14 +48,17 @@ class Video < KubePlayer::Video
 
   def initialize kurl
     super(kurl)
+
+    @el_mode_index = 0
   end
 
-  REQUEST_URL  = 'http://www.youtube.com/get_video_info?&video_id=%s&el=embedded&ps=default&eurl=&gl=US&hl=en'
 +  REQUEST_URL  = 'http://www.youtube.com/get_video_info?&video_id=%s&el=%s&ps=default&eurl=&gl=US&hl=en'
 +  EL_MODE = %w{embedded vevo detailpage}
   def request_video_url
     if @video_url == nil
       @video_url = false
       @id = @url.url.match(/\bv=([^&]+)/)[1]
-      infoRequestUrl = KDE::Url.new(REQUEST_URL % @id)
+      infoRequestUrl = KDE::Url.new(REQUEST_URL % [@id, EL_MODE[@el_mode_index]])
       # infoRequestUrl.add_query_item 'video_id', @id
       infoRequestJob = KIO::storedGet infoRequestUrl , KIO::NoReload, \
KIO::HideProgressInfo  infoRequestJob.add_meta_data 'cookies', 'none'
@@ -75,12 +78,23 @@ class Video < KubePlayer::Video
         end
         # http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
         @fmtUrlMap.delete_if {|fmt,url| fmt > 40} # FIXME to bypass problems with \
                webm (phonon?)
-        if video = @fmtUrlMap.max
+        if metaInfo[:status] == "ok" and video = @fmtUrlMap.max
           @video_url = KDE::Url.new video[1]
           emit got_video_url(Qt::Variant.from_value(self))
         else
-          STDERR.puts "no accessible video found"
-          KDE::MessageBox.messageBox(nil, KDE::MessageBox::Sorry, "It was not \
possible to grap an accessible video.", "Youtube Video Plugin") +          if \
@el_mode_index < EL_MODE.size - 1 +            @el_mode_index += 1
+            @video_url = nil
+            request_video_url # try same request with another el parameter see \
video.cpp from minitube +          else
+            if metaInfo[:reason]
+              msg = "<strong>Youtube reports:</strong><br/><br/>" + \
metaInfo[:reason].gsub('+',' ') +            else
+              msg = "It was not possible to grap an accessible video."
+            end
+            STDERR.puts msg
+            KDE::MessageBox.messageBox(nil, KDE::MessageBox::Sorry, msg, "Youtube \
Video Plugin") +          end
         end
       end
     elsif @video_url != false


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic