def runTest(self, uri): hostHeader, uri = uri.split(' ') uri = uri.replace('@time@', str(int(time.time()))) urlBase1 = random.choice(URL1_BASE) urlBase2 = random.choice(URL2_BASE) url1 = urlBase1 + uri url2 = urlBase2 + uri self.writeOutput('Info: testing %s %s' % (url1, url2)) compareResult = self.compareUrls(hostHeader, url1, url2) if compareResult == False: return False code, headers, body = compareResult if str(code) != '200': return True mimeType = headers['content-type'][0] urls = manifest_utils.getManifestUrls(url1.rsplit('/', 1)[0], body, mimeType, {'Host':hostHeader}) urls = map(lambda x: urlBase1 + urlparse(x).path, urls) # the urls may contain the host header result = True for url in urls: if not self.compareUrls(hostHeader, url, url.replace(urlBase1, urlBase2)): result = False return result
def runTest(self, uri): hostHeader, uri = uri.split(' ') uri = uri.replace('@time@', str(int(time.time()))) urlBase1 = random.choice(URL1_BASE) urlBase2 = random.choice(URL2_BASE) url1 = urlBase1 + uri url2 = urlBase2 + uri self.writeOutput('Info: testing %s %s' % (url1, url2)) compareResult = self.compareUrls(hostHeader, url1, url2) if compareResult == False: return False code, headers, body = compareResult if str(code) != '200': return True mimeType = headers['content-type'][0] urls = manifest_utils.getManifestUrls(url1.rsplit('/', 1)[0], body, mimeType, {}) result = True for url in urls: if not self.compareUrls(hostHeader, url, url.replace(urlBase1, urlBase2)): result = False return result
import manifest_utils import http_utils import sys import os if len(sys.argv) < 3: print 'Usage:\n\tpython %s <manifest url> <output path>' % os.path.basename( __file__) sys.exit(1) _, manifestUrl, outputPath = sys.argv code, headers, body = http_utils.getUrl(manifestUrl, {}) mimeType = headers['content-type'][0] urls = manifest_utils.getManifestUrls(manifestUrl, body, mimeType, {}) for curUrl in [manifestUrl] + urls: fileName = os.path.join(outputPath, os.path.split(curUrl)[1].split('?')[0]) if os.path.exists(fileName): print 'Error: %s already exists' % fileName break http_utils.downloadUrl(curUrl, fileName)
PARSER_BY_MIME_TYPE = { 'application/dash+xml': getDashFragmentsInfo, 'video/f4m': getHdsFragmentsInfo, 'application/vnd.apple.mpegurl': getHlsFragmentsInfo, 'text/xml': getMssFragmentsInfo, } TIMESCALE = { 'application/dash+xml': 90000, 'video/f4m': 1000, 'application/vnd.apple.mpegurl': 90000, 'text/xml': 10000000, } baseUrl = URL.rsplit('/', 1)[0] + '/' urls = manifest_utils.getManifestUrls(baseUrl, d, mimeType, {}) print 'processing %s urls' % len(urls) fragmentInfos = PARSER_BY_MIME_TYPE[mimeType](urls) timescale = TIMESCALE[mimeType] print '' # group the results byStream = {} bySegIndex = {} for (url, segIndex, streamId, fileIndex, timingInfo) in fragmentInfos: key = '%s-%s' % (fileIndex, streamId) byStream.setdefault(key, {}) byStream[key][segIndex] = (url, timingInfo)
'video/f4m': getHdsFragmentsInfo, 'application/vnd.apple.mpegurl': getHlsFragmentsInfo, 'application/x-mpegurl': getHlsFragmentsInfo, 'text/xml': getMssFragmentsInfo, } TIMESCALE = { 'application/dash+xml': 90000, 'video/f4m': 1000, 'application/vnd.apple.mpegurl': 90000, 'application/x-mpegurl': 90000, 'text/xml': 10000000, } baseUrl = URL.rsplit('/', 1)[0] + '/' urls = manifest_utils.getManifestUrls(baseUrl, d, mimeType, headers) print 'processing %s urls' % len(urls) fragmentInfos = PARSER_BY_MIME_TYPE[mimeType](urls) timescale = TIMESCALE[mimeType] print '' # group the results byStream = {} bySegIndex = {} for (url, segIndex, streamId, fileIndex, timingInfo) in fragmentInfos: key = '%s-%s' % (fileIndex, streamId) byStream.setdefault(key, {}) byStream[key][segIndex] = (url, timingInfo)
import manifest_utils import http_utils import sys import os if len(sys.argv) < 3: print 'Usage:\n\tpython %s <manifest url> <output path>' % os.path.basename(__file__) sys.exit(1) _, manifestUrl, outputPath = sys.argv code, headers, body = http_utils.getUrl(manifestUrl, {}) mimeType = headers['content-type'][0] urls = manifest_utils.getManifestUrls(manifestUrl, body, mimeType, {}) for curUrl in [manifestUrl] + urls: fileName = os.path.join(outputPath, os.path.split(curUrl)[1]) if os.path.exists(fileName): print 'Error: %s already exists' % fileName break http_utils.downloadUrl(curUrl, fileName)