def main(directory, debug): basicConfig(level=INFO if debug else ERROR, stream=stderr) getLogger(__name__).info("started") channel_dict = load_channel_file(Path(directory)) stdout.buffer.write( generate_feed(channel_dict, find_files(channel_dict["url"], Path(directory))))
def test_feed_with_some_files(): channel_dict = load_channel_file(Path(HERE) / "test_data" / "0") files = find_files("http://example.com", Path(HERE) / "test_data" / "0") feed = generate_feed(channel_dict, files) tree = etree.fromstring(feed) items = tree.findall("channel")[0].findall("item") expected_titles = ["Some silence", "More silence", "Even more silence"] assert expected_titles == [i.findall("title")[0].text for i in items]
def test_feed_with_some_files(): channel_dict = load_channel_file(Path(HERE) / "test_data" / "0") files = find_files("http://example.com", Path(HERE) / "test_data" / "0") feed = generate_feed(channel_dict, files) tree = etree.fromstring(feed) items = tree.findall("channel")[0].findall("item") expected_titles = ['Some silence', 'More silence', 'Even more silence'] assert expected_titles == [i.findall("title")[0].text for i in items]
def main(directory, debug): basicConfig(level=INFO if debug else ERROR, stream=stderr) getLogger(__name__).info("started") channel_dict = load_channel_file(Path(directory)) stdout.buffer.write( generate_feed( channel_dict, find_files(channel_dict["url"], Path(directory))) )
def test_handle_untagged_files(): files = find_files("http://example.com/", Path(HERE) / "test_data" / "2") expected = FileMetadata( id="e103edb25b9a73e4ad53266e37f9174338cc87ae", title="1-some-silence.m4a", link="http://example.com/1-some-silence.m4a", mimetype="audio/mp4", ) expected.length = 1193 expected.duration = timedelta(seconds=1) assert files[0] == expected
def test_find_m4a_files(): files = find_files("http://example.com/", Path(HERE) / "test_data" / "1") expected = FileMetadata( id="7a37534b4994869e96552561449b2f5b9ddd985e", title="Some silence", link="http://example.com/1-some-silence.m4a", mimetype="audio/mp4", ) expected.length = 1193 expected.duration = timedelta(seconds=1) assert files[0] == expected
def main(directory: str, debug: bool, output_file: str) -> None: basicConfig(level=INFO if debug else ERROR, stream=stderr) getLogger(__name__).info("started") channel_dict = load_channel_file(Path(directory)) if not channel_dict["base_url"].endswith("/"): getLogger(__name__).error("base_url should end with a /") exit(1) feed = generate_feed( channel_dict, output_file, find_files(channel_dict["base_url"], Path(directory)) ) with open(output_file, "wb") as output_f: output_f.write(feed)