- for s in streams: #find 300 - dsl1000mbit
- if s['quality'] == '300' and s['media_type'] == 'wstreaming':
- stream_=s
- break
- for s in streams: #find veryhigh - dsl2000mbit
- if s['quality'] == 'veryhigh' and s['media_type'] == 'wstreaming': # 'hstreaming' - rtsp is not working
- stream_=s
- break
- if stream_ is None:
+ def stream_pref(s):
+ TYPE_ORDER = ['ostreaming', 'hstreaming', 'wstreaming']
+ try:
+ type_pref = TYPE_ORDER.index(s['media_type'])
+ except ValueError:
+ type_pref = 999
+
+ QUALITY_ORDER = ['veryhigh', '300']
+ try:
+ quality_pref = QUALITY_ORDER.index(s['quality'])
+ except ValueError:
+ quality_pref = 999
+
+ return (type_pref, quality_pref)
+
+ sorted_streams = sorted(streams, key=stream_pref)
+ if not sorted_streams: