def _get_streams(self): if not RTMPStream.is_usable(self.session): self.logger.warning("rtmpdump is not usable, only HDS streams will be available") self.logger.debug("Fetching stream info") match = re.search("/\w*/(live|video)*/(\d+)", self.url) if not match: return stream_id = match.group(2) res = http.get(API_URL, params=dict(ak="web", id=stream_id)) root = parse_xml(res.text.encode("utf8")) streams = {} for formitaet in root.iter('formitaet'): url = formitaet.find('url').text quality = formitaet.find('quality').text if formitaet.get('basetype') == "h264_aac_f4f_http_f4m_http": hds_streams = HDSStream.parse_manifest(self.session, url) streams.update(hds_streams) elif formitaet.get('basetype') == 'h264_aac_mp4_rtmp_zdfmeta_http': streams[quality] = RTMPStream(self.session, { "rtmp": self._get_stream(url), "pageUrl": self.url, }) return streams
def _get_rtmp_streams(self): def clean_tag(tag): if tag[0] == "_": return tag[1:] else: return tag chansub = self._authenticate() url = self.StreamInfoURL.format(self.channelname) params = dict(b_id="true", group="", private_code="null", p=int(random.random() * 999999), channel_subscription=chansub, type="any") self.logger.debug("Fetching stream info") res = urlget(url, params=params) data = res.text # fix invalid xml data = re.sub("<(\d+)", "<_\g<1>", data) data = re.sub("</(\d+)", "</_\g<1>", data) streams = {} dom = parse_xml(data, "config XML") nodes = dom.getElementsByTagName("nodes")[0] if len(nodes.childNodes) == 0: return streams swfurl = urlresolve(self.SWFURL) if "?" in swfurl: swfurl = swfurl[:swfurl.find("?")] for node in nodes.childNodes: info = {} for child in node.childNodes: info[child.tagName] = get_node_text(child) if not ("connect" in info and "play" in info): continue stream = RTMPStream(self.session, { "rtmp": ("{0}/{1}").format(info["connect"], info["play"]), "swfVfy": swfurl, "live": True }) sname = clean_tag(node.tagName) if "token" in info: stream.params["jtv"] = info["token"] else: self.logger.warning("No token found for stream {0}, this stream may fail to play", sname) streams[sname] = stream return streams
def _parse(self, data): entries = [] errcode = re.search("^(\d+)$", data) haserror = errcode or "error.mp4" in data if not haserror and len(data) > 0: # Fix invalid XML data = data.replace("&", "&") dom = parse_xml(data, "GOX XML") for entry in dom.findall("ENTRY"): entry = GOXFileEntry(entry) entries.append(entry) return entries
def _get_streams(self): cubeid = self._get_live_cubeid() if not cubeid: return res = http.get(API_URL_LIVE, params=dict(cubeid=cubeid)) root = parse_xml(res.text.encode("utf8")) streams = {} for entry in root.findall("./ENTRY/*/[@reftype='live'][@href]"): url = entry.get("href") try: hls_streams = HLSStream.parse_variant_playlist(self.session, url) streams.update(hls_streams) except IOError as err: self.logger.error("Failed to open playlist: {0}", err) return streams
def _get_streams(self): cubeid = self._get_live_cubeid() if not cubeid: return res = http.get(API_URL_LIVE, params=dict(cubeid=cubeid)) root = parse_xml(res.text.encode("utf8")) streams = {} for entry in root.findall("./ENTRY/*/[@reftype='live'][@href]"): url = entry.get("href") try: hls_streams = HLSStream.parse_variant_playlist( self.session, url) streams.update(hls_streams) except IOError as err: self.logger.error("Failed to open playlist: {0}", err) return streams
def _parse_gox_file(self, data): dom = parse_xml(data, "GOX XML") entries = [] for xentry in dom.getElementsByTagName("ENTRY"): entry = {} for child in xentry.childNodes: if isinstance(child, xml.dom.minidom.Element): if child.tagName == "REF": href = child.getAttribute("href") # SQ and SQTest streams can be gomp2p links, with actual stream address passed as a parameter. if href.startswith("gomp2p://"): href, n = re.subn("^.*LiveAddr=", "", href) href = unquote(href) entry[child.tagName] = href else: entry[child.tagName] = get_node_text(child) entries.append(entry) return entries
def _get_live_cubeid(self): res = http.get(API_URL_APP, params=dict(mode="get_live")) root = parse_xml(res.text.encode("utf8")) return root.findtext("./cube/cubeid")
def _get_stream(self, meta_url): res = http.get(meta_url) root = parse_xml(res.text.encode("utf8")) stream_url = root.find("default-stream-url").text return stream_url