Created
April 4, 2017 19:47
-
-
Save brighid/bac471ef412f0b7112c1f432a5c2a567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import subprocess | |
import tempfile | |
import click | |
DOWNLOAD_DIR = "{}/Downloads".format(os.environ['HOME']) | |
VEEKUN_CRY_URL = "https://veekun.com/dex/media/pokemon/cries/{}.ogg" | |
@click.command() | |
@click.argument('mon_number') | |
@click.argument('mon_name') | |
def download_cry(mon_number, mon_name): | |
download_to = tempfile.NamedTemporaryFile(suffix=".m4a") | |
download = subprocess.check_output(["wget", | |
"--verbose", | |
"--output-document=-", | |
VEEKUN_CRY_URL.format(mon_number)]) | |
subprocess.run(["ffmpeg", | |
"-loglevel", "verbose", | |
"-i", "-", | |
"-c:a", "libfaac", | |
"-vn", | |
"-y", | |
"-t", "8", | |
download_to.name], | |
input=download, | |
check=True) | |
# If we try to name it .m4r to start with, FFMPEG gets over-eager and tries | |
# to figure out how to output an M4R file, then gets sad when it doesn't | |
# know how to do that. So we have to rename it by hand. | |
subprocess.run(["cp", | |
download_to.name, | |
"{}/{}-cry.m4r".format(DOWNLOAD_DIR, mon_name)]) | |
if __name__ == '__main__': | |
download_cry() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment