Esempio n. 1
0
def getRootFile(filename):
  path = os.path.dirname(filename)
  if 'video_ts' == helpers.splitPath(path.lower())[-1]:
    path = '/'.join(helpers.splitPath(path)[:-1])
  basename = os.path.basename(filename)
  (root_file, ext) = os.path.splitext(basename)
  return root_file
Esempio n. 2
0
def getRootFile(filename):
    path = os.path.dirname(filename)
    if 'video_ts' == helpers.splitPath(path.lower())[-1]:
        path = '/'.join(helpers.splitPath(path)[:-1])
    basename = os.path.basename(filename)
    (root_file, ext) = os.path.splitext(basename)
    return root_file
def updateAlbum(metadata, media, lang, find_extras=False, artist_extras={}, extra_type_map=None):
      
  # Clear out the title to ensure stale data doesn't clobber other agents' contributions.
  metadata.title = None

  valid_posters = []
  path = None
  for track in media.tracks:
    for item in media.tracks[track].items:
      for part in item.parts:
        filename = helpers.unicodize(part.file)
        path = os.path.dirname(filename)
        (file_root, fext) = os.path.splitext(filename)

        path_files = {}
        for p in os.listdir(path):
          path_files[p.lower()] = p

        # Look for posters
        poster_files = config.POSTER_FILES + [ os.path.basename(file_root), helpers.splitPath(path)[-1] ]
        for ext in config.ART_EXTS:
          for name in poster_files:
            file = (name + '.' + ext).lower()
            if file in path_files.keys():
              data = Core.storage.load(os.path.join(path, path_files[file]))
              poster_name = hashlib.md5(data).hexdigest()
              valid_posters.append(poster_name)

              if poster_name not in metadata.posters:
                metadata.posters[poster_name] = Proxy.Media(data)
                Log('Local asset image added: ' + file + ', for file: ' + filename)
              else:
                Log('Skipping local poster since its already added')

        # If there is an appropriate AudioHelper, use it.
        audio_helper = audiohelpers.AudioHelpers(part.file)
        if audio_helper != None:
          try: 
            valid_posters = valid_posters + audio_helper.process_metadata(metadata)
            
            # Album sort title.
            if hasattr(audio_helper, 'get_album_sort_title'):
              album_sort_title = audio_helper.get_album_sort_title()
              if album_sort_title and hasattr(metadata, 'title_sort'):
                metadata.title_sort = album_sort_title
            
            if hasattr(audio_helper, 'get_track_sort_title'):
              track_sort_title = audio_helper.get_track_sort_title()
              track_key = media.tracks[track].guid or track
              if track_sort_title and hasattr(metadata.tracks[track_key], 'title_sort'):
                metadata.tracks[track_key].title_sort = track_sort_title
          except:
            pass

        # Look for a video extra for this track.
        if find_extras:
          track_video = findTrackExtra(helpers.unicodize(part.file), extra_type_map)
          if track_video is not None:
            track_key = media.tracks[track].guid or track
            metadata.tracks[track_key].extras.add(track_video)
Esempio n. 4
0
    def update(self, metadata, media, lang):
        # Set title if needed.
        if media and metadata.title is None: metadata.title = media.title

        valid_posters = []
        for track in media.tracks:
            for item in media.tracks[track].items:
                for part in item.parts:
                    filename = helpers.unicodize(part.file)
                    path = os.path.dirname(filename)
                    (file_root, fext) = os.path.splitext(filename)

                    path_files = {}
                    for p in os.listdir(path):
                        path_files[p.lower()] = p

                    # Look for posters
                    poster_files = config.POSTER_FILES + [
                        os.path.basename(file_root),
                        helpers.splitPath(path)[-1]
                    ]
                    for ext in config.ART_EXTS:
                        for name in poster_files:
                            file = (name + '.' + ext).lower()
                            if file in path_files.keys():
                                data = Core.storage.load(
                                    os.path.join(path, path_files[file]))
                                poster_name = hashlib.md5(data).hexdigest()
                                valid_posters.append(poster_name)

                                if poster_name not in metadata.posters:
                                    metadata.posters[
                                        poster_name] = Proxy.Media(data)
                                    Log('Local asset image added: ' + file +
                                        ', for file: ' + filename)
                                else:
                                    Log('Skipping local poster since its already added'
                                        )

                    # If there is an appropriate AudioHelper, use it.
                    audio_helper = audiohelpers.AudioHelpers(part.file)
                    if audio_helper != None:
                        valid_posters = valid_posters + audio_helper.process_metadata(
                            metadata)

        metadata.posters.validate_keys(valid_posters)
Esempio n. 5
0
  def update(self, metadata, media, lang):
    # Set title if needed.
    if media and metadata.title is None: metadata.title = media.title
      
    valid_posters = []
    for track in media.tracks:
      for item in media.tracks[track].items:
        for part in item.parts:
          filename = helpers.unicodize(part.file)
          path = os.path.dirname(filename)
          (file_root, fext) = os.path.splitext(filename)

          path_files = {}
          for p in os.listdir(path):
            path_files[p.lower()] = p

          # Look for posters
          poster_files = config.POSTER_FILES + [ os.path.basename(file_root), helpers.splitPath(path)[-1] ]
          for ext in config.ART_EXTS:
            for name in poster_files:
              file = (name + '.' + ext).lower()
              if file in path_files.keys():
                data = Core.storage.load(os.path.join(path, path_files[file]))
                poster_name = hashlib.md5(data).hexdigest()
                valid_posters.append(poster_name)

                if poster_name not in metadata.posters:
                  metadata.posters[poster_name] = Proxy.Media(data)
                  Log('Local asset image added: ' + file + ', for file: ' + filename)
                else:
                  Log('Skipping local poster since its already added')

          # If there is an appropriate AudioHelper, use it.
          audio_helper = audiohelpers.AudioHelpers(part.file)
          if audio_helper != None:
            try: 
              valid_posters = valid_posters + audio_helper.process_metadata(metadata)
            except: pass

    metadata.posters.validate_keys(valid_posters)
Esempio n. 6
0
def updateAlbum(metadata,
                media,
                lang,
                find_extras=False,
                artist_extras={},
                extra_type_map=None):

    # Clear out the title to ensure stale data doesn't clobber other agents' contributions.
    metadata.title = None

    # clear out genres for this album so we will get genres for all tracks in audio_helper.process_metadata(metadata)
    metadata.genres.clear()

    valid_posters = []
    valid_art = []
    path = None
    for track in media.tracks:
        for item in media.tracks[track].items:
            for part in item.parts:
                filename = helpers.unicodize(part.file)
                path = os.path.dirname(filename)
                (file_root, fext) = os.path.splitext(filename)

                path_files = {}
                for p in os.listdir(path):
                    path_files[p.lower()] = p

                # Look for posters
                poster_files = config.ALBUM_POSTER_FILES + [
                    os.path.basename(file_root),
                    helpers.splitPath(path)[-1]
                ]
                for ext in config.ART_EXTS:
                    for name in poster_files:
                        file = (name + '.' + ext).lower()
                        if file in path_files.keys():
                            data = Core.storage.load(
                                os.path.join(path, path_files[file]))
                            poster_name = hashlib.md5(data).hexdigest()
                            valid_posters.append(poster_name)

                            if poster_name not in metadata.posters:
                                metadata.posters[poster_name] = Proxy.Media(
                                    data)
                                Log('Local asset image added (poster): ' +
                                    file + ', for file: ' + filename)
                            else:
                                Log('Skipping local poster since its already added'
                                    )
                    for name in config.ART_FILES:
                        file = (name + '.' + ext).lower()
                        if file in path_files.keys():
                            data = Core.storage.load(
                                os.path.join(path, path_files[file]))
                            art_name = hashlib.md5(data).hexdigest()
                            valid_art.append(art_name)

                            if art_name not in metadata.art:
                                metadata.art[art_name] = Proxy.Media(data)
                                Log('Local asset image added (art): ' + file +
                                    ', for file: ' + filename)
                            else:
                                Log('Skipping local art since its already added'
                                    )

                # If there is an appropriate AudioHelper, use it.
                audio_helper = audiohelpers.AudioHelpers(part.file)
                if audio_helper != None:
                    try:
                        valid_posters = valid_posters + audio_helper.process_metadata(
                            metadata)

                        # Album sort title.
                        if hasattr(audio_helper, 'get_album_sort_title'):
                            album_sort_title = audio_helper.get_album_sort_title(
                            )
                            if album_sort_title and hasattr(
                                    metadata, 'title_sort'):
                                metadata.title_sort = album_sort_title

                        if hasattr(audio_helper, 'get_track_sort_title'):
                            track_sort_title = audio_helper.get_track_sort_title(
                            )
                            track_key = media.tracks[track].guid or track
                            if track_sort_title and hasattr(
                                    metadata.tracks[track_key], 'title_sort'):
                                metadata.tracks[
                                    track_key].title_sort = track_sort_title
                    except:
                        pass

                # Look for a video extra for this track.
                if find_extras:
                    track_video = findTrackExtra(helpers.unicodize(part.file),
                                                 extra_type_map)
                    if track_video is not None:
                        track_key = media.tracks[track].guid or track
                        metadata.tracks[track_key].extras.add(track_video)

    metadata.posters.validate_keys(valid_posters)
    metadata.art.validate_keys(valid_art)
Esempio n. 7
0
def updateAlbum(metadata,
                media,
                lang,
                find_extras=False,
                artist_extras={},
                extra_type_map=None):

    # Clear out the title to ensure stale data doesn't clobber other agents' contributions.
    metadata.title = None

    # clear out genres for this album so we will get genres for all tracks in audio_helper.process_metadata(metadata)
    metadata.genres.clear()

    valid_posters = []
    valid_art = []
    valid_keys = defaultdict(list)
    path = None

    for index, track in enumerate(media.children):
        track_key = track.guid or index
        for item in track.items:
            for part in item.parts:
                filename = helpers.unicodize(part.file)
                path = os.path.dirname(filename)
                (file_root, fext) = os.path.splitext(filename)

                path_files = {}
                for p in os.listdir(path):
                    path_files[p.lower()] = p

                # Look for posters
                poster_files = config.ALBUM_POSTER_FILES + [
                    os.path.basename(file_root),
                    helpers.splitPath(path)[-1]
                ]
                path_file_keys = path_files.keys()
                while len(path_file_keys) > 0:
                    data_file = path_file_keys.pop(0)
                    if data_file in config.ALBUM_POSTER_DIRS and os.path.isdir(
                            os.path.join(path, path_files[data_file])):
                        for p in os.listdir(
                                os.path.join(path, path_files[data_file])):
                            p = os.path.join(path_files[data_file], p)
                            path_files[p.lower()] = p
                            path_file_keys.append(p.lower())
                        continue
                    poster_match = False
                    art_match = False
                    (art_base, art_ext) = os.path.splitext(data_file)
                    if not art_ext[1:] in config.ART_EXTS:
                        continue
                    if os.path.dirname(data_file) in config.ALBUM_POSTER_DIRS:
                        poster_match = True
                    if not poster_match:
                        for name in poster_files:
                            if art_base.startswith(name):
                                poster_match = True
                                break
                    if not poster_match:
                        for name in config.ART_FILES:
                            if art_base.startswith(name):
                                art_match = True
                                break
                    if poster_match or art_match:
                        data = Core.storage.load(
                            os.path.join(path, path_files[data_file]))
                        digest = hashlib.md5(data).hexdigest()
                        (valid_posters
                         if poster_match else valid_art).append(digest)
                        addAlbumImage(
                            metadata.posters if poster_match else metadata.art,
                            'poster' if poster_match else 'art', data_file,
                            filename, data, digest)
                # If there is an appropriate AudioHelper, use it.
                audio_helper = audiohelpers.AudioHelpers(part.file)
                if audio_helper != None:
                    try:
                        valid_posters = valid_posters + audio_helper.process_metadata(
                            metadata)

                        # Album sort title.
                        if hasattr(audio_helper, 'get_album_sort_title'):
                            album_sort_title = audio_helper.get_album_sort_title(
                            )
                            if album_sort_title and hasattr(
                                    metadata, 'title_sort'):
                                metadata.title_sort = album_sort_title

                        if hasattr(audio_helper, 'get_track_sort_title'):
                            track_sort_title = audio_helper.get_track_sort_title(
                            )
                            if track_sort_title and hasattr(
                                    metadata.tracks[track_key], 'title_sort'):
                                metadata.tracks[
                                    track_key].title_sort = track_sort_title
                    except:
                        pass

                # Look for a video extra for this track.
                if find_extras:
                    track_video = findTrackExtra(media, track,
                                                 helpers.unicodize(part.file),
                                                 extra_type_map)
                    if track_video is not None:
                        metadata.tracks[track_key].extras.add(track_video)

                # Look for lyrics.
                LYRIC_EXTS = ['txt', 'lrc']
                for ext in LYRIC_EXTS:
                    file = (file_root + '.' + ext)
                    if os.path.exists(file):
                        metadata.tracks[track_key].lyrics[
                            file] = Proxy.LocalFile(file, format=ext)
                        valid_keys[track_key].append(file)

    for key in metadata.tracks:
        metadata.tracks[key].lyrics.validate_keys(valid_keys[key])

    metadata.posters.validate_keys(valid_posters)
    metadata.art.validate_keys(valid_art)
Esempio n. 8
0
def updateAlbum(metadata,
                media,
                lang,
                find_extras=False,
                artist_extras={},
                extra_type_map=None,
                prefs={}):

    # clear out genres for this album so we will get genres for all tracks in audio_helper.process_metadata(metadata)
    metadata.genres.clear()

    valid_posters = []
    valid_art = []
    valid_keys = defaultdict(list)
    valid_track_keys = []
    path = None

    for index, track in enumerate(media.children):
        track_key = track.id or index
        valid_track_keys.append(track_key)

        for item in track.items:
            for part in item.parts:
                filename = helpers.unicodize(part.file)
                path = os.path.dirname(filename)
                (file_root, fext) = os.path.splitext(filename)

                path_files = {}

                if len(path) > 0:
                    for p in os.listdir(path):
                        path_files[p.lower()] = p

                # Look for posters
                poster_files = config.ALBUM_POSTER_FILES + [
                    os.path.basename(file_root),
                    helpers.splitPath(path)[-1]
                ]
                path_file_keys = path_files.keys()
                order = 1
                while len(path_file_keys) > 0:
                    data_file = path_file_keys.pop(0)
                    if data_file in config.ALBUM_POSTER_DIRS and os.path.isdir(
                            os.path.join(path, path_files[data_file])):
                        Log('Searching art subdir %s for file %s',
                            os.path.join(path, path_files[data_file]),
                            filename)
                        for p in os.listdir(
                                os.path.join(path, path_files[data_file])):
                            p = os.path.join(path_files[data_file], p)
                            path_files[p.lower()] = p
                            path_file_keys.append(p.lower())
                        continue
                    poster_match = False
                    art_match = False
                    (art_base, art_ext) = os.path.splitext(data_file)
                    if not art_ext[1:] in config.ART_EXTS:
                        continue
                    if os.path.dirname(data_file) in config.ALBUM_POSTER_DIRS:
                        poster_match = True
                    if not poster_match:
                        for name in poster_files:
                            if art_base.startswith(name):
                                poster_match = True
                                break
                    if not poster_match:
                        for name in config.ART_FILES:
                            if art_base.startswith(name):
                                art_match = True
                                break

                    # If we only want posters from the cloud, ignore anything we find.
                    if prefs['albumPosters'] == 2:
                        poster_match = False

                    if poster_match or art_match:
                        data = Core.storage.load(
                            os.path.join(path, path_files[data_file]))
                        digest = hashlib.md5(data).hexdigest()
                        (valid_posters
                         if poster_match else valid_art).append(digest)
                        addAlbumImage(
                            metadata.posters if poster_match else metadata.art,
                            'poster' if poster_match else 'art', data_file,
                            filename, data, digest, order)
                        order = order + 1
                # If there is an appropriate AudioHelper, use it.
                audio_helper = audiohelpers.AudioHelpers(part.file)
                if audio_helper != None:
                    try:
                        valid_posters = valid_posters + audio_helper.process_metadata(
                            metadata, prefs)
                        # Album title (making sure not to blank it out).
                        if hasattr(audio_helper, 'get_album_title'):
                            album_title = audio_helper.get_album_title()
                            if album_title:
                                album_title = CleanString(album_title)
                                if len(album_title) > 0:
                                    metadata.title = album_title

                        # Album sort title.
                        if hasattr(audio_helper, 'get_album_sort_title'):
                            metadata.title_sort = ''
                            album_sort_title = audio_helper.get_album_sort_title(
                            )
                            if album_sort_title and hasattr(
                                    metadata, 'title_sort'):
                                metadata.title_sort = CleanString(
                                    album_sort_title)

                        # Album summary
                        if hasattr(audio_helper, 'get_album_summary'):
                            metadata.summary = ''
                            album_summary = audio_helper.get_album_summary()
                            if album_summary:
                                metadata.summary = CleanString(album_summary)

                        if hasattr(audio_helper, 'get_track_sort_title'):
                            track_sort_title = audio_helper.get_track_sort_title(
                            )
                            metadata.tracks[track_key].title_sort = ''
                            if track_sort_title and hasattr(
                                    metadata.tracks[track_key], 'title_sort'):
                                metadata.tracks[
                                    track_key].title_sort = CleanString(
                                        track_sort_title)

                        # Track title
                        if hasattr(audio_helper, 'get_track_title'):
                            track_title = audio_helper.get_track_title()
                            metadata.tracks[track_key].title = ''
                            if track_title is not None:
                                metadata.tracks[track_key].title = CleanString(
                                    track_title)
                            else:
                                metadata.tracks[
                                    track_key].title = CleanFilename(part.file)

                        # Track index.
                        if hasattr(audio_helper, 'get_track_index'):
                            track_index = audio_helper.get_track_index()
                            if track_index is not None:
                                metadata.tracks[
                                    track_key].track_index = track_index

                        # Track parent index.
                        if hasattr(audio_helper, 'get_track_parent_index'):
                            track_parent_index = audio_helper.get_track_parent_index(
                            )
                            if track_parent_index is not None:
                                metadata.tracks[
                                    track_key].disc_index = track_parent_index

                        # Track artist.
                        if hasattr(audio_helper, 'get_track_artist'):
                            track_artist = audio_helper.get_track_artist()
                            metadata.tracks[
                                track_key].original_title = BLANK_FIELD
                            if track_artist is not None:
                                metadata.tracks[
                                    track_key].original_title = StringOrBlank(
                                        track_artist)
                    except:
                        Log('Exception reading tags')

                # Look for a video extra for this track.
                if find_extras:
                    track_video = findTrackExtra(media, track,
                                                 helpers.unicodize(part.file),
                                                 extra_type_map)
                    if track_video is not None:
                        metadata.tracks[track_key].extras.add(track_video)

                # Look for lyrics.
                LYRIC_EXTS = ['txt', 'lrc']
                for ext in LYRIC_EXTS:
                    file = (file_root + '.' + ext)
                    if os.path.exists(file):
                        Log('Found a lyric in %s', file)
                        metadata.tracks[track_key].lyrics[
                            file] = Proxy.LocalFile(file, format=ext)
                        valid_keys[track_key].append(file)

    for key in metadata.tracks:
        metadata.tracks[key].lyrics.validate_keys(valid_keys[key])

    metadata.tracks.validate_keys(valid_track_keys)
    metadata.posters.validate_keys(valid_posters)
    metadata.art.validate_keys(valid_art)