chrippa / python-librtmp

python-librtmp is a RTMP client library. It uses the implementation provided by librtmp via cffi.
BSD 2-Clause "Simplified" License
154 stars 33 forks source link

Does remote_method() work correctly? #2

Closed brachna closed 11 years ago

brachna commented 11 years ago

It's more than likely that I'm doing something terribly wrong, but is remote_method() working fine?

channel = "yourchannel"
ip = socket.gethostbyname( "x" + channel + "x.e.channel.livestream.com" )
conn = librtmp.RTMP( "rtmp://" + ip + ":80" )
conn.connect()
# conn.connected returns True
func = conn.remote_method( "getCluster3", block=True )
response = func()

I get: librtmp.exceptions.RTMPError: Failed to read packet

I must be making wrong connection, but there are no problems with it, judging by conn.connected property.

chrippa commented 11 years ago

If you grab the result from the connect packet:

r = conn.connect().result()
print(r)

You'll notice that there was a connection related error. Currently there is no attempt to read a packet after connect and this should probably be changed to raise a error in .connect() instead.

brachna commented 11 years ago

I made successful connection judging by resulting AMF I got. Response contains trackid that should be used for getCluster3 method. The only thing I skipped is viewerId parameter in obj dictionary (might be a problem?).

channel = "yourchannel"

obj = dict()
obj.update( { "browser" : "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",  "referrerUrl" : "", "devKey" : "GO2kKNTS471iv-G6HNWVS0LmuTRQfhkeRkW6v7vb9i4YDXmFk_8_2SH15O-gWk9T-gOnI17jx1hmGfrOI_OlTNMle-U1FTclV5B4bqXn3yM", "os" : "Windows 7", "embedUrl" : "http://www.livestream.com/" + channel, "version" : "WIN 11,9,900,117" } )

data = [ "player", None, "instance390", "", None, obj, "password", 197377, True ]
url = "rtmp://x" + channel + "x.e.channel.livestream.com/mogulus-edge/" + channel
page = "http://www.livestream.com/embed/" + channel

conn = librtmp.RTMP( url, connect_data=data, app="mogulus-edge/"+channel, flashver="WIN 11,9,900,117", swfurl="http://cdn.livestream.com/chromelessPlayer/v21/playerapi.swf", pageurl=page )

amf = conn.connect().result()
trackid = amf.get( "application" )[1][0].get( "trackId" )  
func = conn.remote_method( "getCluster3", block=True, transaction_id=3 )
response = func( trackid )
print( str( response ) )

I get "{}" as a response... getServerTimestamp() results in empty amf also. No clear errors, just nothing.

chrippa commented 11 years ago

Hmm, that's odd. I tried your code and it works for me.

Even if I modify it to remove some of the parameters it works. Output from this script is:

1.38410958749e+12
[{u'uri': u'rtmp://212-47.livestream.com', u'zone': u'origin-zone', u'streamId': u'tv_zenica_live_b67e5ad4-dfb4-4e5a-a664-4fe3f43e77c7'}, {u'probability': 1.0, u'uri': u'rtmp://212-68.livestream.com', u'zone': u'dvlabs'}]
brachna commented 11 years ago

Got it. The problem was that I used mine librtmp.dll (compiled with KSV patch). librtmp.dll provided by KSV also didn't work. After I used librtmp.dll compiled by you it did worked. I wonder what can be the reason for this. Do you compile librtmp with or without KSV patch?

Anyway thank you. I'm gonna continue testing tomorrow.

chrippa commented 11 years ago

My build is built from the official Git repo. It seems the KSV patch breaks something, but it's a large patch and I don't plan on tracking down what could be the cause. I updated the README to mention that only the official version is supported.

brachna commented 11 years ago

I recall KSV fixed some crucial stuff regarding rtmpdump though. In particular seeking, I have a lot of videos with problems downloaded with build from svnpenn. Some are fixed with LWLibavVideoSource(), some can't be handled even by it.

On another note I managed to get RTMP stream, but more with guessing. I can't get affiliateURI through RTMP calls alone, which is necessary for playpath. I posted link to script as example how to do it in livestreamer issue.

Gonna close this.