2016-03-13 16:52:54 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; coding: utf-8 -*-
|
|
|
|
# ex:ts=4:sw=4:sts=4:et:fenc=utf-8
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import unittest
|
2018-09-08 22:21:54 +02:00
|
|
|
from svtplay_dl.utils.stream import protocol_prio
|
2016-03-13 16:52:54 +01:00
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2018-09-08 22:21:54 +02:00
|
|
|
class VideoRetriever(object):
|
2016-03-13 16:52:54 +01:00
|
|
|
def __init__(self, proto, bitrate):
|
|
|
|
self.proto = proto
|
|
|
|
self.bitrate = bitrate
|
2018-09-08 22:21:54 +02:00
|
|
|
self.name = proto
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2016-03-13 16:52:54 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return '%s(%d)' % (self.proto.upper(), self.bitrate)
|
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2016-03-13 16:52:54 +01:00
|
|
|
class PrioStreamsTest(unittest.TestCase):
|
2016-03-29 19:39:26 +02:00
|
|
|
def _gen_proto_case(self, ordered, unordered, expected=None):
|
2018-09-08 22:21:54 +02:00
|
|
|
streams = [VideoRetriever(x, 100) for x in unordered]
|
2016-03-13 16:52:54 +01:00
|
|
|
|
|
|
|
kwargs = {}
|
|
|
|
if expected is None:
|
2018-09-08 22:21:54 +02:00
|
|
|
expected = [str(VideoRetriever(x, 100)) for x in ordered]
|
2016-03-13 16:52:54 +01:00
|
|
|
|
|
|
|
return self.assertEqual(
|
2016-03-30 23:09:13 +02:00
|
|
|
[str(x) for x in protocol_prio(streams, ordered, **kwargs)],
|
2016-03-13 16:52:54 +01:00
|
|
|
expected
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_custom_order(self):
|
|
|
|
return self._gen_proto_case(
|
|
|
|
['http', 'rtmp', 'hds', 'hls'],
|
|
|
|
['rtmp', 'hds', 'hls', 'http'],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_custom_order_1(self):
|
|
|
|
return self._gen_proto_case(
|
|
|
|
['http'],
|
|
|
|
['rtmp', 'hds', 'hls', 'http'],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_proto_unavail(self):
|
|
|
|
return self._gen_proto_case(
|
|
|
|
['http', 'rtmp'],
|
|
|
|
['hds', 'hls', 'https'],
|
|
|
|
expected=[],
|
|
|
|
)
|