def test_consume_from_balancer_should_transcode_to_audio(tmpdir): server = Server(M3U8_HOST, M3U8_PORT) playlist = 'real' uri = '/real_content.m3u8' playlists = {'streams': {playlist: {'input-path': uri, 'servers': [server]}}, 'actions': [{'type': 'transcode', 'input': playlist, 'output': {'audio': { "transcode": { "path": "transcode.m3u8", "audio-bitrate": "64000", "bandwidth": "65000" } }}}]} b = Balancer() b.update(get_servers(playlists)) hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir)) expected_created = ['real_content.m3u8', 'sample.ts', 'transcode.m3u8', 'sample.aac'] resources_created = os.listdir(str(tmpdir)) assert sorted(expected_created) == sorted(resources_created) original_m3u8 = tmpdir.join('real_content.m3u8').read() expected_audio_m3u8 = original_m3u8.replace('.ts', '.aac') assert expected_audio_m3u8 == tmpdir.join('transcode.m3u8').read()
def run(self): playlists = discover_playlists(self.config) worker_playlists = self.filter_playlists_for_worker(playlists) if not worker_playlists['streams']: logging.warning("Playlist is not available anymore") self.stop() paths = get_servers(worker_playlists) self.balancer.update(paths) consume_from_balancer(self.balancer, worker_playlists, self.destination, self.encrypt)
def test_consume_from_balancer_should_timeout(tmpdir, monkeypatch): server = Server(M3U8_HOST, M3U8_PORT) playlist = 'slow' uri = '/slow.m3u8' playlists = {'streams': {playlist: {'input-path': uri, 'servers': [server]}}} errors = [] b = Balancer() b.update(get_servers(playlists)) b.notify_error = lambda: errors.append("ERROR") monkeypatch.setattr(logging, 'warning', lambda warn: 0) # just to hide hlsclient warning hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir)) assert errors == ["ERROR"]
def test_consume_from_balancer_should_not_report_content_modified_if_there_are_no_changes(tmpdir): server = Server(M3U8_HOST, M3U8_PORT) playlist = 'low' uri = '/low.m3u8' playlists = {'streams': {playlist: {'input-path': uri, 'servers': [server]}}} b = Balancer() b.update(get_servers(playlists)) hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir)) modified = [] b.notify_modified = lambda: modified.append("MODIFIED") hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir)) assert modified == []
def test_consume_from_balancer_should_report_content_modified(tmpdir): server = Server(M3U8_HOST, M3U8_PORT) playlist = 'low' uri = '/low.m3u8' playlists = {'streams': {playlist: {'input-path': uri, 'servers': [server]}}} modified = [] b = Balancer() b.update(get_servers(playlists)) b.notify_modified = lambda: modified.append("MODIFIED") hlsclient.consumer.consume_from_balancer(b, playlists, str(tmpdir)) assert modified == ["MODIFIED"] expected_created = ['low.m3u8', 'low1.ts', 'low2.ts'] resources_created = os.listdir(str(tmpdir)) assert sorted(expected_created) == sorted(resources_created) for filename in resources_created: assert stat.S_IMODE(os.stat(str(tmpdir.join(filename))).st_mode) == 0644