def main():
parser = ArgumentParser(description="Transcode text from an imgur image to an mp3")
parser.add_argument("-l", "--link", dest="link_input", help="The text or image file to transcode", metavar="STRING")
parser.add_argument("-o", "--output", dest="file_output", help="The file name to output the result into (whether it be an image, or other file type)", metavar="FILE")
if len(sys.argv) == 1:
parser.print_help()
sys.exit()
args = vars(parser.parse_args())
if args['link_input'] != None:
output_filename = args['file_output']
url = args['link_input']
if output_filename == None: #if a filename isn't specified, make it the imgur image code
output_fileWithExtension = strip_link(url)
output_file = output_fileWithExtension.split(".", 1)[0]
urllib.urlretrieve(url, "temp_"+output_fileWithExtension)
os.system("python pngify.py -i temp_"+output_fileWithExtension+" -o "+output_file+".mp3; rm temp_"+output_filename) #run pngify.py then delete temp file
else: #image name is specified
o = output_filename.split(".", 1)
output_file = output_filename.split(".", 1)[0]
if o[len(o)-1] != "png": #if the user didn't input the file extension, add it in automatically
output_filename = output_filename+".png"
urllib.urlretrieve(url, "temp_"+output_filename) #download file
os.system("python pngify.py -i temp_"+output_filename+" -o "+output_file+".mp3; rm temp_"+output_filename) #run pngify.py then delete temp file
评论列表
文章目录