https://blog.csdn.net/fireroll/article/details/18899285
http://nkwavelet.blog.163.com/blog/static/227756038201412022720924/
https://blog.csdn.net/leixiaohua1020/article/details/12953833
http://www.voidcn.com/article/p-sgtepgaz-hh.html
https://github.com/ossrs/srs/issues/741
https://github.com/ossrs/srs/wiki/v1_cn_rtmpurlvhost
http://www.ttstream.com/wowza/flash/urlFormateForRtmpInFlashPlayer
https://github.com/ossrs/librtmp/blob/feature/srs/librtmp/rtmp.c
def rtmp_url_validation(url): log_info = 'parse success' p = url.find('://') if p == -1: log_info = 'RTMP URL: No :// in url!' print log_info return False print "scheme: ", url[:p] #parse host p += 3 if not url[p:]: log_info = 'No hostname in url!' print log_info return False hostlen = 0 end = len(url) col = url.find(':', p) ques = url.find('?', p) slash = url.find('/', p) if slash != -1: hostlen = slash - p else: hostlen = end - p if col != -1 and col - p < hostlen: hostlen = col - p print "host: ", url[p:p+hostlen] p += hostlen #get port if url[p:].startswith(':'): p += 1 portlen = slash - p port = url[p:p+portlen] print "port: ", port if slash == -1: log_info = 'No application or playpath in url!' print log_info return False #get application name p = slash + 1 slash2 = slash3 = -1 applen = appnamelen = 0 slash2 = url.find('/', p) if slash2 != -1: slash3 = url.find('/', p + 1) #ondemand, pass all parameters as app applen = end - p #ondemand length appnamelen = applen if ques != -1 and url.find('slist=', p) != -1: #whatever it is, the '?' and slist= means we need to use everything as app and parse plapath from slist= appnamelen = ques - p elif url[p:].startswith('ondemand/'): #app = ondemand/foobar, only pass app=ondemand applen = 8 appnamelen = 8 else: #app != ondemand, so app is app[/appinstance] if slash3 != -1: appnamelen = slash3 - p elif slash2 != -1: appnamelen = slash2 - p applen = appnamelen print "app name", url[p : p + applen] p += appnamelen if url[p:].startswith('/'): p += 1 #get playpath if end - p: print "stream name: ", url[p:] return True else: print "No stream name found" return False url = 'rtmp://source.hairui.tv:123/stream?token=7wYZbYWh16H1/IdentityV' url2 = 'rtmp://220.181.184.89:1935/liveugc/' url3 = 'rtmp://flashserver:1935/ondemand/thefile swfUrl=http://flashserver/player.swf swfVfy=1' url4 = 'rtmp://mycompany.com/vod/mp4:mycoolvideo.mov?param1=value1¶m2=value2' url5 = 'rtmp://192.168.1.10/live?vhost=ossrs.net/livestream'
url6 = 'rtmp://pub1.guoshi.com:1935/pushstation/ 291?wsSecret=2b8 &wsTime=5302' print (rtmp_url_validation(url)) print print (rtmp_url_validation(url2)) print print (rtmp_url_validation(url3)) print print (rtmp_url_validation(url4)) print print (rtmp_url_validation(url5)) print
print (rtmp_url_validation(url6))