def test_pad_short(self): mp3_path = os.path.join(self.mp3_folder, 'pad_short.mp3') mp3_temp = tempfile.mkstemp()[1] shutil.copy(mp3_path, mp3_temp) audio = Audio(mp3_temp) tags = { 'title': 'test', 'artist': 'test', 'album': 'test', 'genre': 'test' } self.assertEqual(audio.get_tags(), tags) audio.write_tags(tags) self.assertEqual(audio.get_tags(), tags)
def test_pad(self): mp3_path = os.path.join(self.mp3_folder, 'pad.mp3') mp3_temp = tempfile.mkstemp()[1] shutil.copy(mp3_path, mp3_temp) audio = Audio(mp3_temp) tags = {'title': "There's a Beast and We All Feed It", 'genre': 'Rock', 'tracknumber': '1', 'date': '2013', 'artist': 'Jake Bugg', 'album': 'Shangri La', } self.assertEqual(audio.get_tags(), tags) audio.write_tags(tags) self.assertEqual(audio.get_tags(), tags)
def test_write(self): path = os.path.join(os.path.dirname(__file__), 'files', 'oggvorbis', 'sample.ogg') temp = tempfile.mkstemp(suffix='.ogg')[1] shutil.copy(path, temp) audio = Audio(temp) self.assertEqual(self.tags, audio.get_tags()) audio.write_tags({'foo': 'foo', 'bar': 'bar'}) self.assertEqual({}, audio.get_tags()) new_tags = {'foo': 'foo'} new_tags.update(self.tags) audio.write_tags(new_tags) self.assertEqual(self.tags, audio.get_tags()) os.remove(temp)
def write_metadata(song, filepath): """ Takes a dictionary of song info and the filepath to the folder containing the song, and writes the metadata for Title, Artist, and Album to the song. The song must have been renamed first :param song: a dictionary of song info (must include fields for 'title', 'artist', 'album', and 'time') :param filepath: the filepath to the folder that contains the song :return: void """ path_to_song = filepath + Util.get_song_filename(song) audio = Audio(path_to_song) audio.write_tags({ "title": song["title"], "artist": song["artist"], "album": song["album"] }) # access code preceded by 0o to represent octal number # Gives full read/write access to the song file, but not execute os.chmod(path_to_song, 0o666)
dirlist = os.listdir(os.getcwd()) elif (len(sys.argv) == 2): dirlist = os.listdir(sys.argv[1]) else: print("Expected one argument or fewer") sys.exit() count = 0 for song in dirlist: if (song[-4:] != ".mp3"): continue try: audio = Audio(os.getcwd() + '/' + song) except: continue if (not (audio.artist is None)): count += 1 artist = str(audio.artist).strip('\0') title = str(audio.title).strip('\0') if (os.path.isdir(str(os.getcwd() + '/' + artist))): shutil.move(str(os.getcwd() + '/' + song), os.getcwd() + '/' + artist) else: os.mkdir(artist) shutil.move(str(os.getcwd() + '/' + song),