Author: max
Date: 2008-02-19 12:43:39 -0800 (Tue, 19 Feb 2008)
New Revision: 8063

Modified:
   openlaszlo/branches/pagan-deities/
   openlaszlo/branches/pagan-deities/demos/youtube/youtube.jsp
   openlaszlo/branches/pagan-deities/demos/youtube/youtube.lzx
Log:
Merged revisions 8021 via svnmerge from 
http://svn.openlaszlo.org/openlaszlo/trunk

.......
  r8021 | max | 2008-02-13 17:33:32 -0800 (Wed, 13 Feb 2008) | 26 lines
  
  Change 20080213-maxcarlson-o by [EMAIL PROTECTED] on 2008-02-13 15:13:18 PST
      in /Users/maxcarlson/openlaszlo/trunk
      for http://svn.openlaszlo.org/openlaszlo/trunk
  
  Summary: Fix youtube video loading, for real this time!
  
  New Features:
  
  Bugs Fixed: LPP-5424 - YouTube demo is broken, clicking on picture does not 
load video
  
  Technical Reviewer: promanik
  QA Reviewer: mkratt
  Doc Reviewer: (pending)
  
  Documentation:
  
  Release Notes:
  
  Details: youtube.jsp - Parse out Location header from different URL - totally 
bulletproof now.
  
  youtube.lzx - Proxied loads are no longer supported/required!
      
  
  Tests: Any video will play in youtube.lzx now.
.......



Property changes on: openlaszlo/branches/pagan-deities
___________________________________________________________________
Name: svnmerge-integrated
   - /openlaszlo/branches/paperpie:1-6504,6506-6574,6576-7135,7137-7235 
/openlaszlo/branches/wafflecone:1-5746,5818-6068,6070-6205,6207-6213,6216-6265,6267-6368,6370-6431,6433-6450,6497,6509,6661,7097,7872
 /openlaszlo/trunk:1-7950,7983
   + /openlaszlo/branches/paperpie:1-6504,6506-6574,6576-7135,7137-7235 
/openlaszlo/branches/wafflecone:1-5746,5818-6068,6070-6205,6207-6213,6216-6265,6267-6368,6370-6431,6433-6450,6497,6509,6661,7097,7872
 /openlaszlo/trunk:1-7950,7983,8021

Modified: openlaszlo/branches/pagan-deities/demos/youtube/youtube.jsp
===================================================================
--- openlaszlo/branches/pagan-deities/demos/youtube/youtube.jsp 2008-02-19 
20:40:46 UTC (rev 8062)
+++ openlaszlo/branches/pagan-deities/demos/youtube/youtube.jsp 2008-02-19 
20:43:39 UTC (rev 8063)
@@ -11,7 +11,7 @@
 <%!
 
 /* X_LZ_COPYRIGHT_BEGIN ****************************************************
- * Copyright 2007 Laszlo Systems, Inc.  All Rights Reserved.               *
+ * Copyright 2007, 2008 Laszlo Systems, Inc.  All Rights Reserved.         *
  * Use is subject to license terms.                                        *
  * X_LZ_COPYRIGHT_END ******************************************************/
 
@@ -199,18 +199,22 @@
         Document result)
     {
         String pageUrl =
-            "http://www.YouTube.com/watch?v=";;
-        pageUrl += id;
+            "http://www.youtube.com/v/"; + id;
 
-        BufferedReader inputFile = null;
+        // Based on http://www.jeroenwijering.com/?thread=5484#msg50818
+        // Get Location header and parse strings from that...
+        String redirURL = null;
         try {
             URL u = new URL(pageUrl);
-            inputFile =
-                new BufferedReader(
-                    new InputStreamReader(
-                        u.openStream()));
+            HttpURLConnection redir = 
(java.net.HttpURLConnection)u.openConnection();
+            redir.setFollowRedirects(false);
+            redir.connect();
+            redirURL = redir.getHeaderField("Location");
+            if (redirURL == null) {
+                throw new Exception("No Location header found");
+            }
         } catch (Exception e) {
-            reportError("Could not load url.", result);
+            reportError("Could not load url " + redirURL + ": " + 
e.toString(), result);
             return;
         } // try
 
@@ -219,57 +223,34 @@
 
         String videoId = "";
         String tId = "";
-        while (true) {
-            String line = null;
 
-            try {
-                line = inputFile.readLine();
-            } catch (IOException e) {
-                line = null;
-            }
-
-            if (line == null) {
-                break;
-            }
-
-            int start =
-                line.indexOf("swfArgs");
-            if (start == -1) {
-                continue;
-            } else {
-                // Extract the video_id from the args line
-                Pattern vidpat = Pattern.compile("video_id:'[\\w\\d]+'?");
-                Pattern tpat = Pattern.compile("t:'[\\w\\d]+'?");
-                Matcher vidmatcher = vidpat.matcher(line);
-                Matcher tmatcher = tpat.matcher(line);
-                if ( vidmatcher.find() ) {
-                    videoId = (line.substring(vidmatcher.start(), 
vidmatcher.end()));
-                    videoId = videoId.substring(10, videoId.length()-1);
-                } else {
-                    reportError("video_id argument not found in HTML page", 
result);
-                    return;
-                }
-                if ( tmatcher.find() ) {
-                    tId = (line.substring(tmatcher.start(), tmatcher.end()));
-                    tId = tId.substring(3, tId.length()-1);
-                } else {
-                    reportError("t argument not found in HTML page", result);
-                    return;
-                }
-            }
-
-            String url =
-                "http://www.youtube.com/get_video?video_id="; + videoId + "&t=" 
+ tId;
-            
-            resultEl.setAttribute("id", videoId);
-            resultEl.setAttribute("t", tId);
-            resultEl.setAttribute("url", url);
-            result.setRootElement(resultEl);
-
+        // Extract the video_id and t fields from 
+        Pattern vidpat = Pattern.compile("video_id=[\\w\\d]+'?");
+        Pattern tpat = Pattern.compile("t=[\\w\\d\\-]+'?");
+        Matcher vidmatcher = vidpat.matcher(redirURL);
+        Matcher tmatcher = tpat.matcher(redirURL);
+        if ( vidmatcher.find() ) {
+            videoId = (redirURL.substring(vidmatcher.start(), 
vidmatcher.end()));
+            videoId = videoId.substring(9, videoId.length());
+        } else {
+            reportError("video_id argument not found in HTML page", result);
             return;
         }
+        if ( tmatcher.find() ) {
+            tId = (redirURL.substring(tmatcher.start(), tmatcher.end()));
+            tId = tId.substring(2, tId.length());
+        } else {
+            reportError("t argument not found in URL", result);
+            return;
+        }
 
-        reportError("Could not find SWFObject at url " + pageUrl, result);
+        String url =
+            "http://www.youtube.com/get_video?video_id="; + videoId + "&t=" + 
tId;
+
+        resultEl.setAttribute("id", videoId);
+        resultEl.setAttribute("t", tId);
+        resultEl.setAttribute("url", url);
+        result.setRootElement(resultEl);
     }
 
 

Modified: openlaszlo/branches/pagan-deities/demos/youtube/youtube.lzx
===================================================================
--- openlaszlo/branches/pagan-deities/demos/youtube/youtube.lzx 2008-02-19 
20:40:46 UTC (rev 8062)
+++ openlaszlo/branches/pagan-deities/demos/youtube/youtube.lzx 2008-02-19 
20:43:39 UTC (rev 8063)
@@ -1,5 +1,5 @@
 <!-- X_LZ_COPYRIGHT_BEGIN ************************************************
-* Copyright 2007 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2007, 2008 Laszlo Systems, Inc.  All Rights Reserved.        *
 * Use is subject to license terms.                                       *
 * X_LZ_COPYRIGHT_END ************************************************** -->
 
@@ -7,7 +7,6 @@
 <canvas
   width="100%"
   height="100%"
-  proxied="true"
 >
     
     <include href="av/videoutils.lzx"/>


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to