def _urijoin(base_uri, path): if parser.is_url(path): return path elif parser.is_url(base_uri): if path.startswith('/'): return urlparse.urljoin(base_uri, path) parsed_url = urlparse.urlparse(base_uri) prefix = parsed_url.scheme + '://' + parsed_url.netloc new_path = os.path.normpath(parsed_url.path + '/' + path) full_uri = urlparse.urljoin(prefix, new_path.strip('/')) if not parser.is_url(full_uri): full_uri = urlparse.urljoin(prefix, '/' + new_path.strip('/')) return full_uri else: return os.path.normpath(os.path.join(base_uri, path.strip('/')))
def absolute_uri(self): if parser.is_url(self.uri): return self.uri else: if self.base_uri is None: raise ValueError('There can not be `absolute_uri` with no `base_uri` set') return _urijoin(self.base_uri, self.uri)
def _urijoin(base_uri, path): if parser.is_url(base_uri): parsed_url = urlparse.urlparse(base_uri) prefix = parsed_url.scheme + '://' + parsed_url.netloc new_path = os.path.normpath(parsed_url.path + '/' + path) return urlparse.urljoin(prefix, new_path.strip('/')) else: return os.path.normpath(os.path.join(base_uri, path.strip('/')))
def absolute_uri(self): if parser.is_url(self.uri): return self.uri else: if self.base_uri is None: raise ValueError( 'There can not be `absolute_uri` with no `base_uri` set') return _urijoin(self.base_uri, self.uri)
def load(uri): ''' Retrieves the content from a given URI and returns a M3U8 object. Raises ValueError if invalid content or IOError if request fails. ''' if is_url(uri): return _load_from_uri(uri) else: return _load_from_file(uri)
def load(uri, timeout=None, headers={}, cookies=None): ''' Retrieves the content from a given URI and returns a M3U8 object. Raises ValueError if invalid content or IOError if request fails. Raises socket.timeout(python 2.7+) or urllib2.URLError(python 2.6) if timeout happens when loading from uri ''' if is_url(uri): return _load_from_uri(uri, timeout, headers, cookies) else: return _load_from_file(uri)
def absolute_uri(self): if parser.is_url(self.uri): uri = self.uri else: if self.base_uri is None: raise ValueError('There can not be `absolute_uri` with no `base_uri` set') uri = _urijoin(self.base_uri, self.uri) # ugly workaround to be fixed proxyUri = 'englandproxy.co.uk' if proxyUri in self.base_uri and proxyUri not in uri: try: uri = 'http://www.englandproxy.co.uk/' + uri[uri.find('://')+3:] except Exception: pass return uri
def _urijoin(base_uri, path): if is_url(base_uri): return url_parser.urljoin(base_uri, path) else: return os.path.normpath(os.path.join(base_uri, path.strip('/')))
def _urijoin(base_uri, path): if parser.is_url(base_uri): return url_parser.urljoin(base_uri, path) else: return os.path.normpath(os.path.join(base_uri, path.strip('/')))