def get(cls, filename, tags=True, duration=True): parser_class = None size = os.path.getsize(filename) if not size > 0: return TinyTag(None, 0) if cls == TinyTag: """choose which tag reader should be used by file extension""" mapping = { ('.mp3', ): ID3, ('.oga', '.ogg'): Ogg, ('.wav'): Wave, ('.flac'): Flac, } for fileextension, tagclass in mapping.items(): if filename.lower().endswith(fileextension): parser_class = tagclass else: # use class on which the method was invoked as parser parser_class = cls if parser_class is None: raise LookupError('No tag reader found to support filetype! ') with open(filename, 'rb') as af: tag = parser_class(af, size) tag.load(tags=tags, duration=duration) return tag
def _read_tags(self, p, debug=0): size = os.path.getsize(p) with open(p, "rb") as handler: self.tiny = TinyTag(p, size).get(p) self.handler = handler if debug > 0: print("read_tags({}), size={}".format(p, size)) return 0
def insert(self, path, metadata_dict): """ Inserts Dataframe given its input(path, dict of metadata) Does not add duplicates (based upon path) (same song, different Youtube link, will be added) """ #Don't add duplicates if path in self.tags or path == None: return current_music_data = {} current_music_data['path'] = path current_music_data['title'] = metadata_dict["title"] current_music_data['artist'] = metadata_dict["artist"] current_music_data['emotion'] = random.randint(0,6) #random emotion for each song song_tag = TinyTag(None, 0) #File handler and file-size not-relevant for this program song_tag.artist = current_music_data['artist'] song_tag.title = current_music_data['title'] #pd.append must be stored into a new place, otherwise nothing happens self.Music = self.Music.append(current_music_data, ignore_index = True) self.tags[path] = song_tag
def test_unsubclassed_tinytag_parse_tag(): tag = TinyTag(None, 0) tag._parse_tag(None)
def test_unsubclassed_tinytag_duration(): tag = TinyTag(None, 0) tag._determine_duration(None)
def test_show_hint_for_wrong_usage(): TinyTag('filename.mp3', 0)