def test_bin_working_output(self): cls = lib_mux.MP4Box() cls.set_path(mp4boxbin) cls._test_bin() self.assertEqual(cls._bin_test_output, mp4box_output)
def test_bin_working(self): cls = lib_mux.MP4Box() cls.set_path(mp4boxbin) cls._test_bin() self.assertTrue(cls._tested)
def test_bin_error(self): cls = lib_mux.MP4Box() with self.assertRaises(subprocess.SubprocessError): cls._cmd = [sys.executable, "-c", "raise SystemExit(1)"] cls._test_bin_works()
def test_bin_timeout(self): cls = lib_mux.MP4Box() with self.assertRaises(subprocess.SubprocessError): cls._cmd = [sys.executable, "-c", "import time; time.sleep(3)"] cls._test_bin_works()
def test_bin_found2(self): cls = lib_mux.MP4Box() with self.assertRaises(FileNotFoundError): cls.set_path("none") cls._test_bin_exists()
def main(argv): ld("argv", argv) program_version = "v{}".format(__version__) program_build_date = str(__updated__) program_version_message = "{}, built {}".format(program_version, program_build_date) args = lib_argparse.parser(program_version_message) ld(args) #initialize class to hold configuration: conf = config.Config() #parse arguments: #check verbose/debug mode: if args.verbose or DEBUG: conf.debug = True set_log_level('debug') #get folder contents: conf.input_folder = args.input_folder try: folder_contents = lib_tree.Parse(conf.input_folder) ld("folder_contents", folder_contents) except lib_exceptions.FolderNotFound as err: lc(err.msg) conf.audio_files = folder_contents.audio_files ld("conf.audio_files", conf.audio_files) # TODO: check if audio files present conf.cover = folder_contents.cover ld("conf.cover", conf.cover) if not conf.cover: lw("No cover files specified or found. No artwork will be used.") get_metadata(args, conf) #simple text editor to display and edit metadata: lib_editor.Editor(conf) #set metadata for each audio file: track_no = 0 files_with_tags = list() for file in conf.audio_files: track_no += 1 file_tags = { "file": file, "cover": conf.cover, "title": conf.title_full(track=track_no), "sort_title": conf.title_sort, "artist": "{} (read by {})".format(conf.authors_string, conf.narrators_string), "album_artist": conf.authors_string, "album": conf.series_title or conf.title, "track_no": track_no, "total_no": len(conf.audio_files), "disk_no": conf.series_position, "year": conf.date, "description": conf.description, "copyright": conf.copyright } files_with_tags.append(file_tags) #replace previous audio files with the full dict: conf.audio_files = files_with_tags ld(conf.audio_files) #setup paths for binary tools: main_path = os.path.split(os.path.realpath(__file__))[0] if platform.system() == "Windows": tools_path = os.path.join(main_path, "tools\win") mp4box_path = os.path.join(tools_path, "MP4Box.exe") ap_path = os.path.join(tools_path, "AtomicParsley.exe") else: tools_path = os.path.join(main_path, "tools/mac") mp4box_path = os.path.join(tools_path, "MP4Box") ap_path = os.path.join(tools_path, "AtomicParsley") ld("main_path", main_path) ld("tools_path", tools_path) ld("mp4box_path", mp4box_path) ld("ap_path", ap_path) #for each file in the list of files to process #first prepare the blank file to tag (remux), #then tag with given metadata: for file_data in conf.audio_files: #create a separate instance of each class for each file #this way all command line arguments and subprocess instances are separated: mux = lib_mux.MP4Box(mp4box_path) tag = lib_tag.APTagger(ap_path) try: if mux.remux(file_data["file"], file_data["track_no"]): if tag.tag(file_data): print("Finished tagging file: {}".format( file_data["file"])) #remove class instances: del mux del tag except FileNotFoundError as err: lc(err) except lib_exceptions.MP4BoxError as err: lc(err) print("Done!")