当前位置: 首页>>代码示例>>Python>>正文


Python MediaFile.save方法代码示例

本文整理汇总了Python中lib.beets.mediafile.MediaFile.save方法的典型用法代码示例。如果您正苦于以下问题:Python MediaFile.save方法的具体用法?Python MediaFile.save怎么用?Python MediaFile.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.beets.mediafile.MediaFile的用法示例。


在下文中一共展示了MediaFile.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: embedLyrics

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
def embedLyrics(downloaded_track_list):
    logger.info('Adding lyrics')
    
    # TODO: If adding lyrics for flac & lossy, only fetch the lyrics once
    # and apply it to both files
    for downloaded_track in downloaded_track_list:
        
        try:
            f = MediaFile(downloaded_track)
        except:
            logger.error('Could not read %s. Not checking lyrics' % downloaded_track.decode(headphones.SYS_ENCODING, 'replace'))
            continue
            
        if f.albumartist and f.title:
            metalyrics = lyrics.getLyrics(f.albumartist, f.title)
        elif f.artist and f.title:
            metalyrics = lyrics.getLyrics(f.artist, f.title)
        else:
            logger.info('No artist/track metadata found for track: %s. Not fetching lyrics' % downloaded_track.decode(headphones.SYS_ENCODING, 'replace'))
            metalyrics = None
            
        if lyrics:
            logger.debug('Adding lyrics to: %s' % downloaded_track.decode(headphones.SYS_ENCODING, 'replace'))
            f.lyrics = metalyrics
            f.save()
开发者ID:Kiger333,项目名称:headphones,代码行数:27,代码来源:postprocessor.py

示例2: write

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
 def write(self):
     """Writes the item's metadata to the associated file.
     """
     f = MediaFile(syspath(self.path))
     for key in ITEM_KEYS_WRITABLE:
         setattr(f, key, getattr(self, key))
     f.save()
开发者ID:Calimerorulez,项目名称:headphones,代码行数:9,代码来源:library.py

示例3: write

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
 def write(self):
     """Writes the item's metadata to the associated file.
     """
     f = MediaFile(syspath(self.path))
     for key in ITEM_KEYS_WRITABLE:
         if getattr(self, key):  #make sure it has a value before we set it and create blank tags with wrong types
             setattr(f, key, getattr(self, key))
     f.save()
开发者ID:BigDoom,项目名称:headphones,代码行数:10,代码来源:library.py

示例4: write

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
    def write(self):
        """Writes the item's metadata to the associated file.
        """
        f = MediaFile(syspath(self.path))
        plugins.send("write", item=self, mf=f)
        for key in ITEM_KEYS_WRITABLE:
            setattr(f, key, getattr(self, key))
        f.save()

        # The file has a new mtime.
        self.mtime = self.current_mtime()
开发者ID:rodikal,项目名称:headphones,代码行数:13,代码来源:library.py

示例5: embedAlbumArt

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
def embedAlbumArt(artwork, downloaded_track_list):
    logger.info("Embedding album art")

    for downloaded_track in downloaded_track_list:
        try:
            f = MediaFile(downloaded_track)
        except:
            logger.error("Could not read %s. Not adding album art" % downloaded_track)

        logger.debug("Adding album art to: %s" % downloaded_track)
        f.art = artwork
        f.save()
开发者ID:raiker,项目名称:headphones,代码行数:14,代码来源:postprocessor.py

示例6: embedAlbumArt

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
def embedAlbumArt(artwork, downloaded_track_list):
	logger.info('Embedding album art')
	
	for downloaded_track in downloaded_track_list:
		try:
			f = MediaFile(downloaded_track)
		except:
			logger.error('Could not read %s. Not adding album art' % downloaded_track)
			continue
			
		logger.debug('Adding album art to: %s' % downloaded_track)
		f.art = artwork
		f.save()
开发者ID:SimonHova,项目名称:headphones,代码行数:15,代码来源:postprocessor.py

示例7: embedAlbumArt

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
def embedAlbumArt(artwork, downloaded_track_list):
    logger.info('Embedding album art')
    
    for downloaded_track in downloaded_track_list:
        try:
            f = MediaFile(downloaded_track)
        except:
            logger.error(u'Could not read %s. Not adding album art' % downloaded_track.decode(headphones.SYS_ENCODING, 'replace'))
            continue
            
        logger.debug('Adding album art to: %s' % downloaded_track)
        f.art = artwork
        f.save()
开发者ID:Kiger333,项目名称:headphones,代码行数:15,代码来源:postprocessor.py

示例8: embedLyrics

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
def embedLyrics(downloaded_track_list):
  logger.info('Adding lyrics')

  for downloaded_track in downloaded_track_list:
    try:
      f = MediaFile(downloaded_track)
    except:
      logger.error('Could not read %s. Not checking lyrics' % downloaded_track)

    if f.albumartist and f.title:
      metalyrics = lyrics.getLyrics(f.albumartist, f.title)
    elif f.artist and f.title:
      metalyrics = lyrics.getLyrics(f.artist, f.title)
    else:
      logger.info('No artist/track metadata found for track: %s. Not fetching lyrics' % downloaded_track)
      metalyrics = None

    if lyrics:
      logger.debug('Adding lyrics to: %s' % downloaded_track)
      f.lyrics = metalyrics
      f.save()
开发者ID:JohnPostlethwait,项目名称:headphones,代码行数:23,代码来源:postprocessor.py

示例9: libraryScan

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]

#.........这里部分代码省略.........
            "$First": firstchar,
            "$artist": artist.lower(),
            "$album": album.lower(),
            "$year": year,
            "$type": releasetype.lower(),
            "$first": firstchar.lower(),
        }

        folder = helpers.replace_all(headphones.FOLDER_FORMAT, albumvalues)
        folder = folder.replace("./", "_/").replace(":", "_").replace("?", "_")

        if folder.endswith("."):
            folder = folder.replace(folder[len(folder) - 1], "_")

        if not track["TrackNumber"]:
            tracknumber = ""
        else:
            tracknumber = "%02d" % track["TrackNumber"]

        title = track["TrackTitle"]

        trackvalues = {
            "$Track": tracknumber,
            "$Title": title,
            "$Artist": release["ArtistName"],
            "$Album": release["AlbumTitle"],
            "$Year": year,
            "$track": tracknumber,
            "$title": title.lower(),
            "$artist": release["ArtistName"].lower(),
            "$album": release["AlbumTitle"].lower(),
            "$year": year,
        }

        new_file_name = helpers.replace_all(headphones.FILE_FORMAT, trackvalues).replace("/", "_") + ".*"

        new_file_name = new_file_name.replace("?", "_").replace(":", "_")

        full_path_to_file = os.path.normpath(os.path.join(headphones.MUSIC_DIR, folder, new_file_name)).encode(
            headphones.SYS_ENCODING, "replace"
        )

        match = glob.glob(full_path_to_file)

        if match:

            logger.info("Found a match: %s. Writing MBID to metadata" % match[0])

            unipath = unicode(match[0], headphones.SYS_ENCODING, errors="replace")

            myDB.action("UPDATE tracks SET Location=? WHERE TrackID=?", [unipath, track["TrackID"]])
            myDB.action("DELETE from have WHERE Location=?", [unipath])

            # Try to insert the appropriate track id so we don't have to keep doing this
            try:
                f = MediaFile(match[0])
                f.mb_trackid = track["TrackID"]
                f.save()
                myDB.action(
                    "UPDATE tracks SET BitRate=?, Format=? WHERE TrackID=?", [f.bitrate, f.format, track["TrackID"]]
                )

                logger.debug("Wrote mbid to track: %s" % match[0])

            except:
                logger.error("Error embedding track id into: %s" % match[0])
                continue

    logger.info("Done checking empty filepaths")
    logger.info("Done syncing library with directory: %s" % dir)

    # Clean up the new artist list
    unique_artists = {}.fromkeys(new_artists).keys()
    current_artists = myDB.select("SELECT ArtistName, ArtistID from artists")

    artist_list = [f for f in unique_artists if f.lower() not in [x[0].lower() for x in current_artists]]

    # Update track counts
    logger.info("Updating track counts")

    for artist in current_artists:
        havetracks = len(
            myDB.select(
                "SELECT TrackTitle from tracks WHERE ArtistID like ? AND Location IS NOT NULL", [artist["ArtistID"]]
            )
        ) + len(myDB.select("SELECT TrackTitle from have WHERE ArtistName like ?", [artist["ArtistName"]]))
        myDB.action("UPDATE artists SET HaveTracks=? WHERE ArtistID=?", [havetracks, artist["ArtistID"]])

    logger.info("Found %i new artists" % len(artist_list))

    if len(artist_list):
        if headphones.ADD_ARTISTS:
            logger.info("Importing %i new artists" % len(artist_list))
            importer.artistlist_to_mbids(artist_list)
        else:
            logger.info("To add these artists, go to Manage->Manage New Artists")
            headphones.NEW_ARTISTS = artist_list

    if headphones.DETECT_BITRATE:
        headphones.PREFERRED_BITRATE = sum(bitrates) / len(bitrates) / 1000
开发者ID:Geojim,项目名称:headphones,代码行数:104,代码来源:librarysync.py

示例10: libraryScan

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]

#.........这里部分代码省略.........
			
		artist = release['ArtistName'].replace('/', '_')
		album = release['AlbumTitle'].replace('/', '_')
	
		if release['ArtistName'].startswith('The '):
			sortname = release['ArtistName'][4:]
		else:
			sortname = release['ArtistName']
		
		if sortname.isdigit():
			firstchar = '0-9'
		else:
			firstchar = sortname[0]
			
		lowerfirst = firstchar.lower()
		
		albumvalues = {	'artist':	artist,
						'album':	album,
						'year':		year,
						'first':	firstchar,
						'lowerfirst':	lowerfirst
					}
				
		
		folder = helpers.replace_all(headphones.FOLDER_FORMAT, albumvalues)
		folder = folder.replace('./', '_/').replace(':','_').replace('?','_')
		
		if folder.endswith('.'):
			folder = folder.replace(folder[len(folder)-1], '_')

		if not track['TrackNumber']:
			tracknumber = ''
		else:
			tracknumber = '%02d' % track['TrackNumber']
			
		trackvalues = {	'tracknumber':	tracknumber,
						'title':		track['TrackTitle'],
						'artist':		release['ArtistName'],
						'album':		release['AlbumTitle'],
						'year':			year
						}
		
		new_file_name = helpers.replace_all(headphones.FILE_FORMAT, trackvalues).replace('/','_') + '.*'
		
		new_file_name = new_file_name.replace('?','_').replace(':', '_')
		
		full_path_to_file = os.path.normpath(os.path.join(headphones.MUSIC_DIR, folder, new_file_name)).encode(headphones.SYS_ENCODING, 'replace')

		match = glob.glob(full_path_to_file)
		
		if match:

			logger.info('Found a match: %s. Writing MBID to metadata' % match[0])
			
			unipath = unicode(match[0], headphones.SYS_ENCODING, errors='replace')

			myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [unipath, track['TrackID']])
			myDB.action('DELETE from have WHERE Location=?', [unipath])
			
			# Try to insert the appropriate track id so we don't have to keep doing this
			try:
				f = MediaFile(match[0])
				f.mb_trackid = track['TrackID']
				f.save()
				myDB.action('UPDATE tracks SET BitRate=?, Format=? WHERE TrackID=?', [f.bitrate, f.format, track['TrackID']])

				logger.debug('Wrote mbid to track: %s' % match[0])

			except:
				logger.error('Error embedding track id into: %s' % match[0])
				continue

	logger.info('Done checking empty filepaths')
	logger.info('Done syncing library with directory: %s' % dir)
	
	# Clean up the new artist list
	unique_artists = {}.fromkeys(new_artists).keys()
	current_artists = myDB.select('SELECT ArtistName, ArtistID from artists')
	
	artist_list = [f for f in unique_artists if f.lower() not in [x[0].lower() for x in current_artists]]
	
	# Update track counts
	logger.info('Updating track counts')

	for artist in current_artists:
		havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID like ? AND Location IS NOT NULL', [artist['ArtistID']])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist['ArtistName']]))
		myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artist['ArtistID']])
		
	logger.info('Found %i new artists' % len(artist_list))

	if len(artist_list):
		if headphones.ADD_ARTISTS:
			logger.info('Importing %i new artists' % len(artist_list))
			importer.artistlist_to_mbids(artist_list)
		else:
			logger.info('To add these artists, go to Manage->Manage New Artists')
			headphones.NEW_ARTISTS = artist_list
	
	if headphones.DETECT_BITRATE:
		headphones.PREFERRED_BITRATE = sum(bitrates)/len(bitrates)/1000
开发者ID:KenanKonings,项目名称:headphones,代码行数:104,代码来源:librarysync.py

示例11: fileSystemScan

# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import save [as 别名]
  def fileSystemScan(self):
    # Now check empty file paths to see if we can find a match based on their folder format
    tracks = myDB.select('SELECT * from tracks WHERE Location IS NULL')

    for track in tracks:
      release = myDB.action('SELECT * from albums WHERE AlbumID=?', [track['AlbumID']]).fetchone()

      try:
        year = release['ReleaseDate'][:4]
      except TypeError:
        year = ''

      artist = release['ArtistName'].replace('/', '_')
      album = release['AlbumTitle'].replace('/', '_')

      if release['ArtistName'].startswith('The '):
        sortname = release['ArtistName'][4:]
      else:
        sortname = release['ArtistName']

      if sortname.isdigit():
        firstchar = '0-9'
      else:
        firstchar = sortname[0]

      lowerfirst = firstchar.lower()
      albumvalues = { 'artist': artist,
        'album':  album,
        'year':   year,
        'first':  firstchar,
        'lowerfirst': lowerfirst
      }

      folder = helpers.replace_all(headphones.FOLDER_FORMAT, albumvalues)
      folder = folder.replace('./', '_/').replace(':','_').replace('?','_')

      if folder.endswith('.'):
        folder = folder.replace(folder[len(folder)-1], '_')

      if not track['TrackNumber']:
        tracknumber = ''
      else:
        tracknumber = '%02d' % track['TrackNumber']

      trackvalues = { 'tracknumber':  tracknumber,
        'title':    track['TrackTitle'],
        'artist':   release['ArtistName'],
        'album':    release['AlbumTitle'],
        'year':     year
      }

      new_file_name = helpers.replace_all(headphones.FILE_FORMAT, trackvalues).replace('/','_') + '.*'
      new_file_name = new_file_name.replace('?','_').replace(':', '_')
      full_path_to_file = os.path.normpath(os.path.join(headphones.MUSIC_DIR, folder, new_file_name)).encode(headphones.SYS_ENCODING, 'replace')
      match = glob.glob(full_path_to_file)

      if match:
        logger.info('Found a match: %s. Writing MBID to metadata' % match[0])

        unipath = unicode(match[0], headphones.SYS_ENCODING, errors='replace')

        myDB.action('UPDATE tracks SET Location=? WHERE TrackID=?', [unipath, track['TrackID']])
        myDB.action('DELETE from have WHERE Location=?', [unipath])

        # Try to insert the appropriate track id so we don't have to keep doing this
        try:
          f = MediaFile(match[0])
          f.mb_trackid = track['TrackID']
          f.save()
          myDB.action('UPDATE tracks SET BitRate=? WHERE TrackID=?', [f.bitrate, track['TrackID']])

          logger.debug('Wrote mbid to track: %s' % match[0])
        except:
          logger.error('Error embedding track id into: %s' % match[0])
          continue
开发者ID:JohnPostlethwait,项目名称:headphones,代码行数:77,代码来源:librarysync.py


注:本文中的lib.beets.mediafile.MediaFile.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。