def test_copy_file_to_destination(config, test_folder): source_file = test_folder.join('output.mp3') source_file.write('') source = str(source_file) target = str(test_folder.join('mystation', 'myshow', 'myepisode.pm3')) recorder = Recorder() recorder._copy_file_to_destination(source, target) assert os.path.exists(target) assert os.path.isfile(target)
def test_write_file(test_folder, config, monkeypatch): def mockreturn(path): return open(os.path.join(os.path.dirname(__file__), 'testfile.mp3'), 'r') import capturadio monkeypatch.setattr(capturadio, 'urlopen', mockreturn) recorder = Recorder() recorder.start_time = time.time() folder = test_folder.mkdir('casts') file_name = os.path.join(str(folder), 'output.mp3') stream_url = 'http://example.org/stream.mp3' recorder._write_stream_to_file(stream_url, file_name, 2) assert os.path.exists(file_name)
def test_write_file(test_folder, config, monkeypatch): def mockreturn(path): filename = os.path.join(os.path.dirname(__file__), 'testfile.mp3') return open(filename, 'rb') import capturadio monkeypatch.setattr(capturadio, 'urlopen', mockreturn) folder = test_folder.mkdir('casts') show = config.shows['weather'] episode = capturadio.Episode(config, show) episode.filename = os.path.join(str(folder), 'output.mp3') episode.duration = 3 recorder = Recorder() recorder._write_stream_to_file(episode) assert os.path.exists(episode.filename)
def test_add_metadata(config, test_folder): import time media_file = test_folder.join('mystation', 'myshow', 'myepisode.pm3') station = config.stations['dlf'] show = Show(station, 'me', 'Me', 2) recorder = Recorder() recorder.start_time = time.time() recorder._copy_file_to_destination( os.path.join(os.path.dirname(__file__), 'testfile.mp3'), str(media_file)) recorder._add_metadata(show, str(media_file)) try: # Python 2.x from mutagen.mp3 import MP3 except ImportError: # Python 3.x from mutagenx.mp3 import MP3 audio = MP3(str(media_file)) #assert 'tit' == audio['TIT2'].text[0] assert 'Podcast' == audio['TCON'].text[0] assert 'Deutschlandfunk' == audio['TPE1'].text[0] assert 'Deutschlandfunk' == audio['TCOP'].text[0] assert 'Me' == audio['TALB'].text[0] assert 'http://example.org/dlf' == audio['TCOM'].text[0] assert u'2000' == audio['TLEN'].text[0]
def show_capture(*args): """Usage: recorder show capture [--duration=<duration>] [options] Capture a show. Options: --duration,-d=<duration> Set the duration, overrides show setting Examples: 1. Capture an episode of the show 'nighttalk' recorder show capture nighttalk 2. Capture an episode of the show 'nighttalk', but only 35 minutes recorder show capture nighttalk -d 35m """ config = Configuration() if len(config.stations) == 0: print('No stations defined, add stations at first!') sys.exit(0) if len(config.shows) == 0: print('No shows defined, add shows at first!') sys.exit(0) args = args[0] if args['<show>'] in config.shows: show = config.shows[args['<show>']] try: recorder = Recorder() episode = recorder.capture(config, show) db = database.open('episodes_db') db[episode.slug] = episode db.close() except Exception as e: logging.error('Unable to capture recording: {}'.format(e)) else: print('Unknown show %r' % args['<show>'])
def test_add_metadata(config, test_folder): import shutil from mutagenx.mp3 import MP3 media_file = test_folder.join('mystation', 'myshow', 'myepisode.pm3') os.makedirs(os.path.dirname(str(media_file))) shutil.copy(os.path.join(os.path.dirname(__file__), 'testfile.mp3'), str(media_file)) station = config.stations['dlf'] show = Show(config, station, 'me', 'Me', 2) episode = Episode(config, show) episode.filename = str(media_file) recorder = Recorder() recorder._add_metadata(episode) audio = MP3(str(media_file)) #assert 'tit' == audio['TIT2'].text[0] assert 'Podcast' == audio['TCON'].text[0] assert 'Deutschlandfunk' == audio['TPE1'].text[0] assert 'Deutschlandfunk' == audio['TCOP'].text[0] assert 'Me' == audio['TALB'].text[0] assert 'http://example.org/dlf' == audio['TCOM'].text[0] assert u'2000' == audio['TLEN'].text[0]
def show_capture(*args): """Usage: recorder show capture [--duration=<duration>] [options] Capture a show. Options: --duration,-d=<duration> Set the duration, overrides show setting Examples: 1. Capture an episode of the show 'nighttalk' recorder show capture nighttalk 2. Capture an episode of the show 'nighttalk', but only 35 minutes recorder show capture nighttalk -d 35m """ config = Configuration() if len(config.stations) == 0: print("No stations defined, add stations at first!") sys.exit(0) if len(config.shows) == 0: print("No shows defined, add shows at first!") sys.exit(0) args = args[0] if args["<show>"] in config.shows: show = config.shows[args["<show>"]] try: recorder = Recorder() episode = recorder.capture(config, show) with shelve.open(os.path.join(app_folder, "episodes_db")) as db: db[episode.slug] = episode except Exception as e: logging.error("Unable to capture recording: {}".format(e)) else: print("Unknown show %r" % args["<show>"])
def show_capture(*args): """Usage: recorder show capture [--duration=<duration>] [options] Capture a show. Options: --duration,-d=<duration> Set the duration, overrides show setting Examples: 1. Capture an episode of the show 'nighttalk' recorder show capture nighttalk 2. Capture an episode of the show 'nighttalk', but only 35 minutes recorder show capture nighttalk -d 35m """ config = Configuration() if len(config.stations) == 0: print('No stations defined, add stations at first!') sys.exit(0) if len(config.shows) == 0: print('No shows defined, add shows at first!') sys.exit(0) args = args[0] if args['<show>'] in config.shows: show = config.shows[args['<show>']] try: recorder = Recorder() recorder.capture(show) except Exception as e: print('Unable to capture recording: %s' % e) else: print('Unknown show %r' % args['<show>'])
def test_add_metadata(config, test_folder): import time media_file = test_folder.join('mystation', 'myshow', 'myepisode.pm3') station = config.stations['dlf'] show = Show(station, 'me', 'Me', 2) recorder = Recorder() recorder.start_time = time.time() recorder._copy_file_to_destination(os.path.join(os.path.dirname(__file__), 'testfile.mp3'), str(media_file)) recorder._add_metadata(show, str(media_file)) try: # Python 2.x from mutagen.mp3 import MP3 except ImportError: # Python 3.x from mutagenx.mp3 import MP3 audio = MP3(str(media_file)) #assert 'tit' == audio['TIT2'].text[0] assert 'Podcast' == audio['TCON'].text[0] assert 'Deutschlandfunk' == audio['TPE1'].text[0] assert 'Deutschlandfunk' == audio['TCOP'].text[0] assert 'Me' == audio['TALB'].text[0] assert 'http://example.org/dlf' == audio['TCOM'].text[0] assert u'2000' == audio['TLEN'].text[0]