예제 #1
0
    def rm_ogg_cover(self, episode):
        filename = episode.local_filename(create=False)
        if filename is None:
            return

        basename, extension = os.path.splitext(filename)

        if episode.file_type() != 'audio':
            return

        if extension.lower() != '.ogg':
            return

        try:
            ogg = OggVorbis(filename)

            found = False
            for key in ogg.keys():
                if key.startswith('cover'):
                    found = True
                    ogg.pop(key)

            if found:
                logger.info('Removed cover art from OGG file: %s', filename)
                ogg.save()
        except Exception, e:
            logger.warn('Failed to remove OGG cover: %s', e, exc_info=True)
예제 #2
0
    def rm_ogg_cover(self, episode):
        filename = episode.local_filename(create=False)
        if filename is None:
            return

        basename, extension = os.path.splitext(filename)

        if episode.file_type() != 'audio':
            return

        if extension.lower() != '.ogg':
            return

        try:
            ogg = OggVorbis(filename)

            found = False
            for key in ogg.keys():
                if key.startswith('cover'):
                    found = True
                    ogg.pop(key)

            if found:
                logger.info('Removed cover art from OGG file: %s', filename)
                ogg.save()
        except Exception, e:
            logger.warn('Failed to remove OGG cover: %s', e, exc_info=True)
def rm_ogg_cover(episode):
    filename = episode.local_filename(create=False, check_only=True)
    if filename is None:
        return

    (basename, extension) = os.path.splitext(filename)
    if episode.file_type() == "audio" and extension.lower().endswith("ogg"):
        logger.info(u"trying to remove cover from %s" % filename)
        found = False

        try:
            ogg = OggVorbis(filename)
            for key in ogg.keys():
                if key.startswith("cover"):
                    found = True
                    ogg.pop(key)

            if found:
                logger.info(u"removed cover from the ogg file successfully")
                ogg.save()
            else:
                logger.info(u"there was no cover to remove in the ogg file")
        except:
            None
예제 #4
0
def initiateOGG(filename, directory, thumbnails, options):
    audio = OggVorbis(str(directory) + "/" + str(filename))
    # verify artist information is present before preceeding
    if ' - ' not in filename and str(audio['artist'][0]) == '':
        messagebox.showinfo("No artist information found, aborting procedure")
        return False, False, False

    # transcribe formal tagnames into informal counterpart
    formalTagDict = {
        'artist': 'Artist',
        'album': 'Album',
        'albumartist': 'Album_Artist',
        'bpm': 'BPM',
        'comment': 'Comment',
        'compilation': 'Compilation',
        'copyright': 'Copyright',
        'discnumber': 'Discnumber',
        'genre': 'Genre',
        'metadata_block_picture': 'Image',
        'initialkey': 'Key',
        'date': 'Release_Date',
        'title': 'Title',
        'replaygain_track_gain': 'ReplayGain',
    }
    # transcribe informal tagnames into formal counterpart
    informalTagDict = {v: k for k, v in formalTagDict.items()}
    fileParameters = []
    for tag in audio:
        # delete extraneous tags if the tag is not in the list of selected tags and the delete unselected tags option is activated
        if (tag not in formalTagDict
                or formalTagDict[tag] not in options["Selected Tags (L)"]
            ) and options["Delete Unselected Tags (B)"].get() == True:
            audio.pop(tag)
            audio.save()
        else:
            fileParameters.append(tag)
    for tag in options["Selected Tags (L)"]:
        if tag in informalTagDict:
            tag = informalTagDict[tag]
            # add tags of interest if missing
            if tag not in fileParameters:
                try:
                    audio[tag] = ""
                    audio.save()
                except:
                    messagebox.showinfo(
                        "Permission Error",
                        "Unable to save tags, file may be open somewhere")
                    return False, False, False

    # check for discrepancies between tags and filename
    # check both artist and title tags
    if ' - ' in filename:
        artist = filename.split(' - ')[0]
        title = filename[filename.index(filename.split(' - ')[1]):filename.
                         rfind('.')]
        if artist != str(audio['artist'][0]) or title != str(
                audio['title'][0]):
            # save artist and title to tag if both are empty
            if str(audio['artist'][0]) == '' and str(audio['title'][0]) == '':
                audio['artist'] = artist
                audio['title'] = title
                audio.save()
            else:
                audio, filename = compareArtistAndTitle(
                    audio, artist, title, filename, directory, options)
    # only check title tag
    else:
        title = filename[:filename.rfind('.')]
        if title != str(audio['title'][0]):
            # save title to tag if tag is empty
            if str(audio['title'][0]) == '':
                audio['title'] = title
                audio.save()
            else:
                audio, filename = compareTitle(audio, title, filename,
                                               directory, options)

    # handle naming format and typo check
    if options["Audio naming format (S)"].get() == "Artist - Title" or options[
            'Audio naming format (S)'].get() == 'Title':
        namingConvention = options['Audio naming format (S)'].get()
        artist = str(audio['artist'][0])
        audio, filename = handleStaticNamingConvention(audio, filename, artist,
                                                       title, directory,
                                                       namingConvention)
        if options["Scan Filename and Tags (B)"].get(
        ) == True and type(audio) != bool:
            audio, filename, options = extractArtistAndTitle(
                audio, filename, directory, options, namingConvention)

    if type(audio) != bool:
        # save thumbnail to list
        images = audio["metadata_block_picture"]
        if images[0] != '':
            data = base64.b64decode(images[0])
            image = Picture(data)
            stream = BytesIO(image.data)
            image = Image.open(stream).convert("RGBA")
            thumbnails = saveThumbnail(image, thumbnails)
            stream.close()
        else:
            thumbnails = saveThumbnail("NA", thumbnails)
    return audio, filename, informalTagDict, thumbnails, options