Beispiel #1
0
 def get_album_sort_title(self):
     try:
         tags = MFile(self.filename)
         return tags.get('albumsort')[0]
     except:
         try:
             tags = MFile(self.filename)
             return tags.get('albumsortorder')[0]
         except:
             return None
Beispiel #2
0
 def get_artist_sort_title(self):
     try:
         tags = MFile(self.filename)
         return tags.get('performersortorder')[0]
     except:
         try:
             tags = MFile(self.filename)
             return tags.get('albumartistsort')[0]
         except:
             return None
Beispiel #3
0
    def process_metadata(self, metadata, prefs):

        Log('Reading ID3 tags from: ' + self.filename)
        try:
            self.tags = tags = MFile(self.filename)
            Log('Found tags: ' + str(tags.keys()))
        except:
            Log('An error occurred while attempting to read ID3 tags from ' +
                self.filename)
            return

        # Release Date (original_available_at)
        metadata.originally_available_at = parse_datefield_select_highest(
            tags, 'TDRC', metadata.originally_available_at)

        # Release Date (available_at)
        metadata.available_at = parse_datefield_select_highest(
            tags, 'TDRL', metadata.available_at)

        # Genres
        try:
            genres = tags.get('TCON')
            if genres is not None and len(genres.text) > 0:
                for genre in genres.text:
                    for sub_genre in parse_genres(genre):
                        sub_genre_stripped = sub_genre.strip()
                        if sub_genre_stripped:
                            if sub_genre_stripped not in metadata.genres:
                                metadata.genres.add(sub_genre_stripped)
        except Exception, e:
            Log('Exception reading TCON (genre): ' + str(e))
Beispiel #4
0
 def get_track_artist(self):
     album_artist = self.get_artist_title()
     try:
         tags = MFile(self.filename)
         track_artist = tags.get('artist')[0]
         if str(track_artist) != str(album_artist) or album_artist is None:
             return track_artist
     except:
         try:
             tags = MFile(self.filename)
             track_artist = tags.get('artist_credit')[0]
             if track_artist != album_artist and album_artist is not None:
                 return track_artist
         except:
             pass
         return None
Beispiel #5
0
 def save(pf):
     metadata = Metadata()
     metadata.copy(pf.metadata)
     mf = MFile(pf.filename)
     if mf is not None:
         mf.delete()
     return pf._save_and_rename(pf.filename, metadata)
Beispiel #6
0
def AudioHelpers(filename):
    filename = helpers.unicodize(filename)
    try:
        tag = MFile(filename, None, True)
    except Exception, e:
        Log('Error getting file details for %s: %s' % (filename, e))
        return None
 def update_tracks(self, media_id, file):
     try:
         tags = MFile(file, None, True)
         artist_str = " / ".join(tags["artist"])
         update_track(media_id, artist_str)
     except Exception, e:
         PlexLog.error(e)
Beispiel #8
0
 def get_artist_title(self):
     try:
         tags = MFile(self.filename, easy=True)
         tag = tags.get('albumartist')
         return tag[0]
     except:
         return None
Beispiel #9
0
 def get_artist_title(self):
     try:
         tags = MFile(self.filename)
         tag = tags.get('albumartist')
         if tag and len(tag[0]) > 0:
             return tag[0]
         tag = tags.get('album artist')
         if tag and len(tag[0]) > 0:
             return tag[0]
         tag = tags.get('artist')
         return tag[0]
     except:
         try:
             tags = MFile(self.filename)
             return tags.get('album artist')[0]
         except:
             return None
Beispiel #10
0
    def get_artist_title(self):
        try:
            self.tags = tags = MFile(self.filename)
            return self.tags.get('TPE2')
        except:
            pass

        return None
Beispiel #11
0
 def get_artist_sort_title(self):
     try:
         tags = MFile(self.filename, easy=True)
         tag = tags.get('albumartistsort')  # 'soaa'
         if tag:
             return tag[0]
         return tags.get('artistsort')[0]  # 'soar'
     except:
         return None
Beispiel #12
0
 def __init__(self, filename):
     super(OGGAudioHelper, self).__init__(filename)
     try:
         Log('Reading OGG tags from: ' + self.filename)
         self.tags = MFile(self.filename)
         Log('Found OGG tags: ' + str(self.tags.keys()))
     except:
         Log('An error occured while attempting to parse the OGG file: ' +
             self.filename)
Beispiel #13
0
 def get_track_genres(self):
     genre_list = []
     try:
         self.tags = tags = MFile(self.filename)
         genres = self.tags.get('TCON')
         if genres is not None and len(genres.text) > 0:
             for genre in genres.text:
                 for sub_genre in parse_genres(genre):
                     genre_list.append(sub_genre.strip())
     except Exception, e:
         Log('Exception reading TCON (genre): ' + str(e))
Beispiel #14
0
    def get_artist_sort_title(self):
        try:
            self.tags = tags = MFile(self.filename)
            tag = self.tags.get('TSO2')
            if tag:
                return tag

            return self.tags.get('TSOP')
        except:
            pass

        return None
Beispiel #15
0
 def get_track_genres(self):
     genre_list = []
     try:
         tags = MFile(self.filename)
         genres = tags.get('\xa9gen')
         if genres is not None and len(genres) > 0:
             for genre in genres:
                 for sub_genre in parse_genres(genre):
                     if sub_genre.strip():
                         genre_list.append(sub_genre.strip())
     except Exception, e:
         Log('Exception reading (genre): ' + str(e))
Beispiel #16
0
def AudioHelpers(filename):
    if len(filename) > 0:
        filename = helpers.unicodize(filename)
        try:
            tag = MFile(filename, None, True)
        except Exception, e:
            Log('Error getting file details for %s: %s' % (filename, e))
            return None

        if tag is not None:
            for cls in [
                    ID3AudioHelper, MP4AudioHelper, FLACAudioHelper,
                    OGGAudioHelper, ASFAudioHelper
            ]:
                if cls.is_helper_for(type(tag).__name__):
                    return cls(filename)
Beispiel #17
0
    def process_metadata(self, metadata):

        Log('Reading OGG tags from: ' + self.filename)
        try:
            tags = MFile(self.filename)
            Log('Found tags: ' + str(tags.keys()))
        except:
            Log('An error occured while attempting to parse the OGG file: ' +
                self.filename)
            return

        # Genres
        try:
            genres = tags.get('genre')
            if genres is not None and len(genres) > 0:
                metadata.genres.clear()
                for genre in genres:
                    for sub_genre in parse_genres(genre):
                        metadata.genres.add(sub_genre.strip())
        except Exception, e:
            Log('Exception reading genre: ' + str(e))
Beispiel #18
0
    def process_metadata(self, metadata):

        Log('Reading MP4 tags from: ' + self.filename)
        try:
            tags = MFile(self.filename)
            Log('Found tags: ' + str(tags.keys()))
        except:
            Log('An error occurred while attempting to parse the MP4 file: ' +
                self.filename)
            return

        # Genres
        try:
            genres = tags.get('\xa9gen')
            if genres is not None and len(genres) > 0:
                for genre in genres:
                    for sub_genre in parse_genres(genre):
                        sub_genre_stripped = sub_genre.strip()
                        if sub_genre_stripped:
                            if sub_genre_stripped not in metadata.genres:
                                metadata.genres.add(sub_genre_stripped)
        except Exception, e:
            Log('Exception reading \xa9gen (genre): ' + str(e))
Beispiel #19
0
    def process_metadata(self, metadata):

        Log('Reading ID3 tags from: ' + self.filename)
        try:
            self.tags = tags = MFile(self.filename)
            Log('Found tags: ' + str(tags.keys()))
        except:
            Log('An error occurred while attempting to read ID3 tags from ' +
                self.filename)
            return

        # Release Date (original_available_at)
        try:
            year = tags.get('TDRC')
            if year is not None and len(year.text) > 0:
                available = Datetime.ParseDate('01-01-' +
                                               str(year.text[0])).date()
                if metadata.originally_available_at is None:
                    metadata.originally_available_at = available
                elif (available > metadata.originally_available_at):
                    # more then one date: use highest one
                    metadata.originally_available_at = available
        except Exception, e:
            Log('Exception reading TDRC (year): ' + str(e))
Beispiel #20
0
 def get_track_artist(self):
     try:
         tags = MFile(self.filename, easy=True)
         return tags.get('artist')[0]
     except:
         return None
Beispiel #21
0
 def get_album_sort_title(self):
     try:
         tags = MFile(self.filename, easy=True)
         return tags.get('albumsort')[0]  # 'soal'
     except:
         return None
Beispiel #22
0
 def get_track_sort_title(self):
     try:
         tags = MFile(self.filename, easy=True)
         return tags.get('titlesort')[0]  # 'sonm'
     except:
         return None
Beispiel #23
0
 def get_album_summary(self):
     try:
         tags = MFile(self.filename, easy=True)
         return tags.get('description')[0]
     except:
         return None
Beispiel #24
0
 def get_album_title(self):
     try:
         tags = MFile(self.filename)
         return tags.get('album')[0]
     except:
         return None
Beispiel #25
0
 def get_album_title(self):
     try:
         tags = MFile(self.filename, easy=True)
         return tags.get('album')[0]  # 'alb'
     except:
         return None
Beispiel #26
0
 def get_track_parent_index(self):
     try:
         tags = MFile(self.filename)
         return tags.get('disk')[0][0]
     except:
         return None
Beispiel #27
0
 def get_track_title(self):
     try:
         tags = MFile(self.filename)
         return tags.get('title')[0]
     except:
         return None
Beispiel #28
0
 def get_track_parent_index(self):
     try:
         tags = MFile(self.filename)
         return int(cleanTrackAndDisk(tags.get('discnumber')[0]))
     except:
         return None
Beispiel #29
0
def getInfoFromTag(filename, language):
    compil = '0'
    tag = MFile(filename, None, True)
    if tag is None:
        return (None, None, None, None, None, None, None)
    elif type(tag).__name__ in ('EasyID3', 'EasyMP3', 'EasyTrueAudio', 'ID3',
                                'MP3', 'TrueAudio'):  # All use ID3 tags
        artist = mp3tagGrabber(tag, filename, 'artist', language, force=True)
        album = mp3tagGrabber(tag, filename, 'album', language, force=True)
        title = mp3tagGrabber(tag, filename, 'title', language, force=True)
        track = cleanTrackAndDisk(
            mp3tagGrabber(tag, filename, 'track', language, 'tracknumber'))
        disc = cleanTrackAndDisk(
            mp3tagGrabber(tag, filename, 'disk', language, 'discnumber'))
        TPE2 = mp3tagGrabber(tag, filename, 'TPE2', language, 'performer')
        try:
            compil = tag['compilation'][0]
        except:
            pass
    elif type(
            tag
    ).__name__ is 'AIFF':  # Uses ID3 tags, but has a different header than MP3 and no 'Easy' mutagen class
        artist = mutagenGrabber(tag, 'TPE1', language)
        if artist is None:
            artist = mutagenGrabber(tag, 'TP1', language)

        album = mutagenGrabber(tag, 'TALB', language)
        if album is None:
            album = mutagenGrabber(tag, 'TAL', language)

        title = mutagenGrabber(tag, 'TIT2', language)
        if title is None:
            title = mutagenGrabber(tag, 'TT2', language)

        track = cleanTrackAndDisk(mutagenGrabber(tag, 'TRCK', language))
        if track is None:
            track = cleanTrackAndDisk(mutagenGrabber(tag, 'TRK', language))

        disc = cleanTrackAndDisk(mutagenGrabber(tag, 'TPOS', language))

        TPE2 = mutagenGrabber(tag, 'TPE2', language)
        if TPE2 is None:
            TPE2 = mutagenGrabber(tag, 'TP2', language)

        try:
            compil = tag['compilation'][0]
        except:
            pass
    elif type(tag).__name__ is 'ASF':
        artist = getWMAstring(mutagenGrabber(tag, 'Author', language))
        album = getWMAstring(mutagenGrabber(tag, 'WM/AlbumTitle', language))
        title = getWMAstring(mutagenGrabber(tag, 'Title', language))
        track = cleanTrackAndDisk(
            mutagenGrabber(tag, 'WM/TrackNumber', language))
        disc = cleanTrackAndDisk(mutagenGrabber(tag, 'WM/PartOfSet', language))
        TPE2 = getWMAstring(mutagenGrabber(tag, 'WM/AlbumArtist', language))
    else:
        artist = mutagenGrabber(tag, 'artist', language)
        album = mutagenGrabber(tag, 'album', language)
        title = mutagenGrabber(tag, 'title', language)
        track = cleanTrackAndDisk(mutagenGrabber(tag, 'tracknumber', language))
        disc = cleanTrackAndDisk(mutagenGrabber(tag, 'discnumber', language))
        TPE2 = mutagenGrabber(tag, 'albumartist', language)
        if TPE2 == None:
            TPE2 = mutagenGrabber(tag, 'album artist', language)
        try:
            compil = tag['compilation'][0]
            if tag['compilation'][0] == True: compil = '1'
        except:
            pass

    return (artist, album, title, track, disc, TPE2, compil)
Beispiel #30
0
 def get_track_index(self):
     try:
         tags = MFile(self.filename)
         return tags.get('trkn')[0][0]
     except:
         return None