Generate URLs from External Page Source? (Javascript?)

Talk about your favorite PC games, Steam and building awesome custom rigs!

Moderator:Moderators

Post Reply
User avatar
bicostp
Moderator
Posts:10491
Joined:Mon Mar 07, 2005 5:47 pm
Steam ID:bicostp
Location:Spamalot
Contact:
Generate URLs from External Page Source? (Javascript?)

Post by bicostp » Sat Sep 26, 2009 9:48 am

Okay for a project I'm working on (a Hulu TV for Garry's Mod), I need to get a variable from a page's source code and generate a new URL to use.

When you look at the page source of any Hulu player page, you see a block of code like this:

Code: Select all

<script type="text/javascript">/*<![CDATA[*/
    current_video_cid = "f5bd3dba84d3573fdb7611ee9f20addf";
    UserHistory.add_watched_history(50004271);
    function carouselOffset(carouselId) {
      if (/([a-z])(\d+)/.test(window.location.hash))
        if (RegExp.$1 == carouselId && RegExp.$2) 
          return parseInt(RegExp.$2);
      return 0;
    }
What I want to do is take that long 'current_video_cid' hex string and tack it on the end of the "pop out" player URL, making a string like this:

Code: Select all

http://www.hulu.com/stand_alone/f5bd3dba84d3573fdb7611ee9f20addf
That way, it can run the video properly on the in-game screen. (When you have it load the entire page, the game bogs down to unplayable speeds, around 7 FPS, even on a 2.8 ghz Q9550. :facepalm:)

I already have this working in the game using a hard-coded video URL. The problem is, in order to make that URL you have to dig through the source code manually in order to find that string. I want to automate this process to make it more user-friendly, so all you have to do is enter the plain URL from the address bar and the script takes care of the rest. (That would be best, especially considering the level of idiocy in the help forum on Facepunch. :facepalm:)

Yes, this is based off the YouTube in-game player. I tried using the Hulu embedded player, since their embedded player doesn't have an autoplay feature. The "pop-out" player accomplishes the same thing, but plays automatically.

This is definitely possible somehow, since (as far as I can tell) that is how Boxee handles full screen Hulu playback.

It would be great if this could be done in Javascript, because then it can be integrated into the addon without relying on an external webserver. (The addon can generate a temporary HTML page from scratch by itself; that's how it displays the YouTube embedded player.)

Thanks!

EDIT: I think this might be possible with plain old LUA, adapting this example for the job:
http://lua-users.org/wiki/GettingTheTitleFromHtmlFiles" onclick="window.open(this.href);return false;

yes/no?

User avatar
MasterPrime
Posts:88
Joined:Sun Feb 17, 2008 9:53 pm

Re: Generate URLs from External Page Source? (Javascript?)

Post by MasterPrime » Sat Sep 26, 2009 4:06 pm

I've never played with garry's mod but I suspect that you can get lua to do everything you require.
Image

Post Reply