Akamai SecureHD Streaming Proxy
#1
I modified Unbehagen's XBMC Local Proxy from http://forum.xbmc.org/showthread.php?tid=95369 to support Akamai SecureHD streaming.

Thanks to KSV for the help with tokens.

This streaming method is over http but they embedded information in the FLV file. This information is needed to make command requests to the server. The swf player url is needed to calculate an MD5 of the uncompressed player. This value is used in calculating tokens.

Base64 encode the video url and swf url. You can use those to build the proxy url. an example is below.

example code to generate the proxy url.
Code:
import base64

    VIDb64 = base64.encodestring(VIDEO_URL).replace('\n','')
    SWFb64 = base64.encodestring(SWF_URL).replace('\n','')
    proxyUrl = 'http://127.0.0.1:64653/secureconne/%s/%s' % (VIDb64,SWFb64)

here is the proxy code.
http://pastebin.com/KGdHv5a0

This requires flvlib to be able to parse the flv meta-data. I am using version 0.1.12
http://pypi.python.org/pypi/flvlib/0.1.5

I am trying to work on a generic xbmc script module for this. I am not sure the proper way to run and shutdown the proxy within XBMC. I have been running it separately and just having plugins connect to it for testing.

I know National Geographic and Discovery sites in the US use this streaming method. There were also some EU Olympic streams using this type of streaming.

I need to put more work into it to make it a script module. Some might find it useful now.
Reply
#2
Wow, BlueCop. Impressive. Big Grin Maybe you can help me out.

I'm not sure what I'm doing wrong. I ran the proxy and then tried playing the proxyUrl but I'm still having the buffering issue. There seem to be no difference between playing the VIDEO_URL or proxyUrl. I can eventually play the video by pressing play to cancel the buffering. I also used flvlib 0.1.12.

Website link = http://video.nationalgeographic.com/vide...canaveral/
Code:
    VIDEO_URL = 'http://channelhd-f.akamaihd.net/mpx/video/Nat_Geo_Channels/28/476/UFO_Court_Cape_Canaveral_ngc_015__710340.flv'
    SWF_URL = 'http://images.nationalgeographic.com/wpf/sites/video/swf/ngplayer_v2.2.swf'
    VIDb64 = base64.encodestring(VIDEO_URL).replace('\n','')
    SWFb64 = base64.encodestring(SWF_URL).replace('\n','')
    proxyUrl = 'http://127.0.0.1:64653/secureconne/%s/%s' % (VIDb64,SWFb64)
    item = xbmcgui.ListItem( label = name )
    item.setInfo( type="Video", infoLabels={ "Title": name } )
    xbmc.Player( xbmc.PLAYER_CORE_DVDPLAYER ).play( proxyUrl, item )

Log from Python: http://pastebin.com/GW2Nk3b0


Reply
#3
stacked: Do you mean where it seems to just be paused and continues to buffer?

I am actually working on a fix for that. The server responds with a content-length 2GB and it is forwarded to XBMC. The player seems to think that it is buffering a full 2GB file.

I want fix this by using the MetaData block in the flv. It has the audio bitrate, video bitrate, and video duration to calculate a correct content length.

I need to redo the order of some things to do this. It already forwards it to the client by the time I process any meta currently.

We could not pass the content-length at all and then XBMC seems to stream it like a Live stream.
Reply
#4
(2012-07-31, 07:25)BlueCop Wrote: stacked: Do you mean where it seems to just be paused and continues to buffer?

I am actually working on a fix for that. The server responds with a content-length 2GB and it is forwarded to XBMC. The player seems to think that it is buffering a full 2GB file.

I want fix this by using the MetaData block in the flv. It has the audio bitrate, video bitrate, and video duration to calculate a correct content length.

I need to redo the order of some things to do this. It already forwards it to the client by the time I process any meta currently.

We could not pass the content-length at all and then XBMC seems to stream it like a Live stream.
No. The video starts out paused/buffering and doesn't continue until I press play. This is probably caused by the 2GB content-length.

Hopefully, you can find a way to get the proxy running in XBMC. A xbmc script module would come in handy for addon creators as more sites start using Akamai SecureHD.

Keep up the good work.
Reply
#5
I was actually patching the content-length in that version to 500MB. Sorry I misspoke. I was trying a few things and forgot I left that in there.
Code:
for key in headers:
            try:
                val=headers[key]
                if 'content-length' == key.lower():
                    s.send_header(key, str(500*1024*1024))
                else:
                    s.send_header(key, val)
if you change line 105 to "pass" then it will start immediately in XBMC. It treats it kinda like a live stream. It doesn't allow skipping back in the buffer. I hope calculating the correct size will solve any issues.
Code:
for key in headers:
            try:
                val=headers[key]
                if 'content-length' == key.lower():
                    pass
                else:
                    s.send_header(key, val)



Reply
#6
(2012-07-31, 08:21)BlueCop Wrote: if you change line 105 to "pass" then it will start immediately in XBMC. It treats it kinda like a live stream. It doesn't allow skipping back in the buffer. I hope calculating the correct size will solve any issues.

I tried this and got the same results. I also noticed with the original code, short clips (less than 5min), the video would start off paused. Full episodes (about 45min) plays immediately without buffering. Skipping also wasn't working well.
Reply
#7
Thanks again for working on this!
I tried it on the olympic streams from eurovisionsports.tv but couldnt get it working.
The full video url looks like this:
Code:
http://culture-f.akamaihd.net/[email protected]?primaryToken=1343429976_8026355950f5638d98e65b51815d22cb&v=1.1.12&fp=WIN%2011,3,300,268&r=TGFHH&g=TEDFKDRIAXAD&primaryToken=?event=d03m01

When trying without the parameters it wont work: http://pastebin.com/f3DHhmSg
With the parameters it seems to start (black screen) but hangs on "Loading..." (but not the buffering issue): http://pastebin.com/GGG2ge4M
Also tried it with only the primaryToken parameter.

Perhaps you know whats going on...
Reply
#8
You definitely need those parameters. I can play the stream with the parameters but I can't retrieve the swf to calculate its md5.

It looks like the onEdge dictionary isn't getting parsed from your log. That doesn't fail for me on this same stream though. It just fails to retrieve the swf because it is geo-restricted.

I am trying to find a working proxy to grab a copy of the swf so I can do more tests. It seems free UK based proxies are hard to find currently.

Edit: I got a copy of the swf. I actually proxied it via 'http://anonymouse.org/cgi-bin/anon-www.cgi/http://www.eurovisionsports.tv/london2012/site/Digotel.4.3.0.swf"

I have been watching the stream you posted for a few minutes now.

Edit2: I have been letting it play for for a while just to test and all seems well. It sucks I can't seem to replicate the issue you have.

I stopped it on the 15 minute mark. I would like to help more but I am a little confused why it is failed for you.

Edit3:
I am now getting 403 errors on the stream. I was actually testing in VLC. I should have used XBMC.

If you could set the MIME type of the item you return to the player. This will prevent XBMC from connecting to the server twice.

item.setProperty('mimetype', 'video/x-flv')

I think this might fix your issue. Let me know how it works. I am still trying to get everything working smoothly.

Reply
#9
I am fairly new to XMBC, and I don't know how I can use this proxy, can you explain what I have to do with this script?

Thanks in advance
Reply
#10
qurben: it is really meant for add-on developers currently. The end user will hopefully benefit in the future.

I am working on making everything run correctly in XBMC. It seems to crash XBMC when trying to close XBMC with the proxy running.
Reply
#11
(2012-07-31, 21:29)BlueCop Wrote: You definitely need those parameters. I can play the stream with the parameters but I can't retrieve the swf to calculate its md5.

It looks like the onEdge dictionary isn't getting parsed from your log. That doesn't fail for me on this same stream though. It just fails to retrieve the swf because it is geo-restricted.

I am trying to find a working proxy to grab a copy of the swf so I can do more tests. It seems free UK based proxies are hard to find currently.

Edit: I got a copy of the swf. I actually proxied it via 'http://anonymouse.org/cgi-bin/anon-www.cgi/http://www.eurovisionsports.tv/london2012/site/Digotel.4.3.0.swf"

I have been watching the stream you posted for a few minutes now.

Edit2: I have been letting it play for for a while just to test and all seems well. It sucks I can't seem to replicate the issue you have.

I stopped it on the 15 minute mark. I would like to help more but I am a little confused why it is failed for you.

Edit3:
I am now getting 403 errors on the stream. I was actually testing in VLC. I should have used XBMC.

If you could set the MIME type of the item you return to the player. This will prevent XBMC from connecting to the server twice.

item.setProperty('mimetype', 'video/x-flv')

I think this might fix your issue. Let me know how it works. I am still trying to get everything working smoothly.
Thanks for your patience Smile
I tried it under windows and linux. Also with "item.setProperty('mimetype', 'video/x-flv')" - But it hangs on starting the playback.
Reply
#12
Did you the Commander9000 post here?

He said he got it working. Sorry I am not more help. I am a little confused why it is failing.
Reply
#13
(2012-07-31, 23:10)BlueCop Wrote: Did you the Commander9000 post here?

He said he got it working. Sorry I am not more help. I am a little confused why it is failing.
I tried it the same way as Commander9000... Mysterious Huh
The problem is not related to the olympic streams: Just tried it with a national geo stream from post #2
http://pastebin.com/xS2B3KL0

Exactly the same...
Just getting "CEdl::ReadEdl" errors! (about 3000 per second)

I'm using flvlib-0.1.12 on Eden Final! I only have to start your proxy, right? Or did I missed something?

You're doing an amazing service btw - Always ready to help Smile
Reply
#14
It seems EDL is Edit Decision List. I am not sure why that is being activated. I haven't used them before. http://wiki.xbmc.org/index.php?title=Edit_decision_list

it is looking on the proxy for an EDL file by just adding ".edl" to the proxy url. This of course will not work but I don't know what is activating it.

could you try the proxy url in a browser or open it as a network stream in VLC just as a test? I believe it is something with XBMC


Edit: I was using a newer build then Eden final. XBMC is looking for various edit decision lists on the server. I can make the proxy ignore these requests to get it working right.
Reply
#15
I got it working by ignoring the additional requests with file extensions.

It feels hackish but it works. It will just 404 anything with the extensions XBMC looks up.

I made changes between line 63 and 64
Code:
request_path=s.path[1:]
            request_path=re.sub(r"\?.*","",request_path)

Code:
request_path=s.path[1:]
            extensions = ['.Vprj','.edl','.txt','.chapters.xml']
            for extension in extensions:
                if request_path.endswith(extension):
                    s.send_response(404)
                    request_path=''      
            request_path=re.sub(r"\?.*","",request_path)

I am working on getting it all running with in XBMC now.

Edit.
This isn't a good solution. I will work on something better.
Reply



Logout Mark Read Team Forum Stats Members Help
Akamai SecureHD Streaming Proxy1
This forum uses Lukasz Tkacz MyBB addons.