Switch to unified view

a/rdpl2stream/StreamDecoder.py b/rdpl2stream/StreamDecoder.py
...
...
18
#
18
#
19
##########################################################################
19
##########################################################################
20
from __future__ import print_function
20
from __future__ import print_function
21
21
22
import sys
22
import sys
23
import ssl
23
24
24
PY3 = sys.version > '3'
25
PY3 = sys.version > '3'
25
if PY3:
26
if PY3:
26
    from urllib.request import Request as UrlRequest
27
    from urllib.request import Request as UrlRequest
27
    import urllib.request, urllib.error, urllib.parse
28
    import urllib.request, urllib.error, urllib.parse
28
    from urllib.error import HTTPError as HTTPError
29
    from urllib.error import HTTPError as HTTPError
29
    from urllib.error import URLError as URLError
30
    from urllib.error import URLError as URLError
30
    from http.client import BadStatusLine as BadStatusLine
31
    from http.client import BadStatusLine as BadStatusLine
31
    from urllib.request import build_opener as urlBuild_opener
32
    from urllib.request import build_opener as urlBuild_opener
32
    from urllib.request import HTTPSHandler    
33
    from urllib.request import HTTPSHandler
34
    if sys.version_info < (3,5):
35
        def my_ssl_create_unverified_context():
36
            ssl_ctx = ssl.create_default_context()
37
            ssl_ctx.check_hostname = False
38
            ssl_ctx.verify_mode = ssl.CERT_NONE
39
            return ssl_ctx
40
    else:
41
        my_ssl_create_unverified_context = ssl._create_unverified_context
33
else:
42
else:
34
    from urllib2 import Request as UrlRequest
43
    from urllib2 import Request as UrlRequest
35
    from urllib2 import HTTPError as HTTPError
44
    from urllib2 import HTTPError as HTTPError
36
    from urllib2 import URLError as URLError
45
    from urllib2 import URLError as URLError
37
    from urllib2 import build_opener as urlBuild_opener
46
    from urllib2 import build_opener as urlBuild_opener
38
    from urllib2 import HTTPSHandler
47
    from urllib2 import HTTPSHandler
39
    class BadStatusLine:
48
    class BadStatusLine:
40
        pass
49
        pass
41
import ssl
42
50
43
from lib.common import USER_AGENT, Logger
51
from lib.common import USER_AGENT, Logger
44
from lib.DummyMMSHandler import DummyMMSHandler
52
from lib.DummyMMSHandler import DummyMMSHandler
45
from PlsPlaylistDecoder import PlsPlaylistDecoder
53
from PlsPlaylistDecoder import PlsPlaylistDecoder
46
from M3uPlaylistDecoder import M3uPlaylistDecoder
54
from M3uPlaylistDecoder import M3uPlaylistDecoder
...
...
93
        req.add_header('User-Agent', USER_AGENT)
101
        req.add_header('User-Agent', USER_AGENT)
94
102
95
        try:
103
        try:
96
            opener = urlBuild_opener(
104
            opener = urlBuild_opener(
97
                DummyMMSHandler(),
105
                DummyMMSHandler(),
98
                HTTPSHandler(context = ssl._create_unverified_context()))
106
                HTTPSHandler(context = my_ssl_create_unverified_context()))
99
            f = opener.open(req, timeout=float(self.url_timeout))
107
            f = opener.open(req, timeout=float(self.url_timeout))
100
        except HTTPError as e:
108
        except HTTPError as e:
101
            self.log.warn('HTTP Error for %s: %s' % (url, e))
109
            self.log.warn('HTTP Error for %s: %s' % (url, e))
102
            return None
110
            return None
103
        except URLError as e:
111
        except URLError as e:
...
...
113
                self.log.info('Found ICY stream')
121
                self.log.info('Found ICY stream')
114
                return UrlInfo(url, False, None)
122
                return UrlInfo(url, False, None)
115
            else:
123
            else:
116
                return None
124
                return None
117
        except Exception as e:
125
        except Exception as e:
126
            print('%s: for %s: %s' % (type(e), url, e),file=sys.stderr)
118
            self.log.warn('%s: for %s: Error %s: %s' % (type(e), url, e))
127
            self.log.warn('%s: for %s: %s' % (type(e), url, e))
119
            return None
128
            return None
120
129
121
        metadata = f.info()
130
        metadata = f.info()
122
        firstbytes = f.read(500)
131
        firstbytes = f.read(500)
123
        f.close()
132
        f.close()