本文整理汇总了Python中lib.beets.mediafile.MediaFile.lower方法的典型用法代码示例。如果您正苦于以下问题:Python MediaFile.lower方法的具体用法?Python MediaFile.lower怎么用?Python MediaFile.lower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.beets.mediafile.MediaFile
的用法示例。
在下文中一共展示了MediaFile.lower方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: libraryScan
# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import lower [as 别名]
def libraryScan(dir=None, append=False, ArtistID=None, ArtistName=None):
if not dir:
dir = headphones.MUSIC_DIR
# If we're appending a dir, it's coming from the post processor which is
# already bytestring
if not append:
dir = dir.encode(headphones.SYS_ENCODING)
if not os.path.isdir(dir):
logger.warn('Cannot find directory: %s. Not scanning' % dir.decode(headphones.SYS_ENCODING))
return
myDB = db.DBConnection()
if not append:
# Clean up bad filepaths
tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL')
for track in tracks:
if not os.path.isfile(track['Location'].encode(headphones.SYS_ENCODING)):
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [None, None, None, track['TrackID']])
myDB.action('DELETE from have')
logger.info('Scanning music directory: %s' % dir)
new_artists = []
bitrates = []
song_list = []
for r,d,f in os.walk(dir):
for files in f:
# MEDIA_FORMATS = music file extensions, e.g. mp3, flac, etc
if any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS):
song = os.path.join(r, files)
# We need the unicode path to use for logging, inserting into database
unicode_song_path = song.decode(headphones.SYS_ENCODING, 'replace')
# Try to read the metadata
try:
f = MediaFile(song)
except:
logger.error('Cannot read file: ' + unicode_song_path)
continue
# Grab the bitrates for the auto detect bit rate option
if f.bitrate:
bitrates.append(f.bitrate)
# Use the album artist over the artist if available
if f.albumartist:
f_artist = f.albumartist
elif f.artist:
f_artist = f.artist
else:
f_artist = None
# Add the song to our song list -
# TODO: skip adding songs without the minimum requisite information (just a matter of putting together the right if statements)
song_dict = { 'TrackID' : f.mb_trackid,
'ReleaseID' : f.mb_albumid,
'ArtistName' : f_artist,
'AlbumTitle' : f.album,
'TrackNumber': f.track,
'TrackLength': f.length,
'Genre' : f.genre,
'Date' : f.date,
'TrackTitle' : f.title,
'BitRate' : f.bitrate,
'Format' : f.format,
'Location' : unicode_song_path }
song_list.append(song_dict)
# Now we start track matching
total_number_of_songs = len(song_list)
logger.info("Found " + str(total_number_of_songs) + " tracks in: '" + dir + "'. Matching tracks to the appropriate releases....")
# Sort the song_list by most vague (e.g. no trackid or releaseid) to most specific (both trackid & releaseid)
# When we insert into the database, the tracks with the most specific information will overwrite the more general matches
song_list = helpers.multikeysort(song_list, ['ReleaseID', 'TrackID'])
# We'll use this to give a % completion, just because the track matching might take a while
song_count = 0
for song in song_list:
song_count += 1
completion_percentage = float(song_count)/total_number_of_songs * 100
if completion_percentage%10 == 0:
logger.info("Track matching is " + str(completion_percentage) + "% complete")
#.........这里部分代码省略.........
示例2: libraryScan
# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import lower [as 别名]
def libraryScan(dir=None):
if not dir:
dir = headphones.MUSIC_DIR
try:
dir = str(dir)
except UnicodeEncodeError:
dir = unicode(dir).encode('unicode_escape')
if not os.path.isdir(dir):
logger.warn('Cannot find directory: %s. Not scanning' % dir)
return
myDB = db.DBConnection()
# Clean up bad filepaths
tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL')
for track in tracks:
if not os.path.isfile(track['Location'].encode(headphones.SYS_ENCODING)):
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [None, None, None, track['TrackID']])
logger.info('Scanning music directory: %s' % dir)
new_artists = []
bitrates = []
myDB.action('DELETE from have')
for r,d,f in os.walk(dir):
for files in f:
# MEDIA_FORMATS = music file extensions, e.g. mp3, flac, etc
if any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS):
song = os.path.join(r, files)
file = unicode(os.path.join(r, files), headphones.SYS_ENCODING, errors='replace')
# Try to read the metadata
try:
f = MediaFile(song)
except:
logger.error('Cannot read file: ' + file)
continue
# Grab the bitrates for the auto detect bit rate option
if f.bitrate:
bitrates.append(f.bitrate)
# Try to find a match based on artist/album/tracktitle
if f.albumartist:
f_artist = f.albumartist
elif f.artist:
f_artist = f.artist
else:
continue
if f_artist and f.album and f.title:
track = myDB.action('SELECT TrackID from tracks WHERE CleanName LIKE ?', [helpers.cleanName(f_artist +' '+f.album+' '+f.title)]).fetchone()
if not track:
track = myDB.action('SELECT TrackID from tracks WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [f_artist, f.album, f.title]).fetchone()
if track:
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [file, f.bitrate, f.format, track['TrackID']])
continue
# Try to match on mbid if available and we couldn't find a match based on metadata
if f.mb_trackid:
# Wondering if theres a better way to do this -> do one thing if the row exists,
# do something else if it doesn't
track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone()
if track:
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [file, f.bitrate, f.format, track['TrackID']])
continue
# if we can't find a match in the database on a track level, it might be a new artist or it might be on a non-mb release
new_artists.append(f_artist)
# The have table will become the new database for unmatched tracks (i.e. tracks with no associated links in the database
myDB.action('INSERT INTO have (ArtistName, AlbumTitle, TrackNumber, TrackTitle, TrackLength, BitRate, Genre, Date, TrackID, Location, CleanName, Format) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [f_artist, f.album, f.track, f.title, f.length, f.bitrate, f.genre, f.date, f.mb_trackid, file, helpers.cleanName(f_artist+' '+f.album+' '+f.title), f.format])
logger.info('Completed scanning of directory: %s' % dir)
logger.info('Checking filepaths to see if we can find any matches')
# 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 = ''
#.........这里部分代码省略.........
示例3: libraryScan
# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import lower [as 别名]
def libraryScan(dir=None):
if not dir:
dir = headphones.MUSIC_DIR
try:
dir = str(dir)
except UnicodeEncodeError:
dir = unicode(dir).encode("unicode_escape")
if not os.path.isdir(dir):
logger.warn("Cannot find directory: %s. Not scanning" % dir)
return
myDB = db.DBConnection()
# Clean up bad filepaths
tracks = myDB.select("SELECT Location, TrackID from tracks WHERE Location IS NOT NULL")
for track in tracks:
if not os.path.isfile(track["Location"].encode(headphones.SYS_ENCODING)):
myDB.action(
"UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?",
[None, None, None, track["TrackID"]],
)
logger.info("Scanning music directory: %s" % dir)
new_artists = []
bitrates = []
myDB.action("DELETE from have")
for r, d, f in os.walk(dir):
for files in f:
# MEDIA_FORMATS = music file extensions, e.g. mp3, flac, etc
if any(files.lower().endswith("." + x.lower()) for x in headphones.MEDIA_FORMATS):
song = os.path.join(r, files)
file = unicode(os.path.join(r, files), headphones.SYS_ENCODING, errors="replace")
# Try to read the metadata
try:
f = MediaFile(song)
except:
logger.error("Cannot read file: " + file)
continue
# Grab the bitrates for the auto detect bit rate option
if f.bitrate:
bitrates.append(f.bitrate)
# Try to find a match based on artist/album/tracktitle
if f.albumartist:
f_artist = f.albumartist
elif f.artist:
f_artist = f.artist
else:
continue
if f_artist and f.album and f.title:
track = myDB.action(
"SELECT TrackID from tracks WHERE CleanName LIKE ?",
[helpers.cleanName(f_artist + " " + f.album + " " + f.title)],
).fetchone()
if not track:
track = myDB.action(
"SELECT TrackID from tracks WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?",
[f_artist, f.album, f.title],
).fetchone()
if track:
myDB.action(
"UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?",
[file, f.bitrate, f.format, track["TrackID"]],
)
continue
# Try to match on mbid if available and we couldn't find a match based on metadata
if f.mb_trackid:
# Wondering if theres a better way to do this -> do one thing if the row exists,
# do something else if it doesn't
track = myDB.action("SELECT TrackID from tracks WHERE TrackID=?", [f.mb_trackid]).fetchone()
if track:
myDB.action(
"UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?",
[file, f.bitrate, f.format, track["TrackID"]],
)
continue
# if we can't find a match in the database on a track level, it might be a new artist or it might be on a non-mb release
new_artists.append(f_artist)
# The have table will become the new database for unmatched tracks (i.e. tracks with no associated links in the database
myDB.action(
#.........这里部分代码省略.........
示例4: libraryScan
# 需要导入模块: from lib.beets.mediafile import MediaFile [as 别名]
# 或者: from lib.beets.mediafile.MediaFile import lower [as 别名]
def libraryScan(dir=None):
if not dir:
dir = headphones.MUSIC_DIR
dir = dir.encode(headphones.SYS_ENCODING)
if not os.path.isdir(dir):
logger.warn('Cannot find directory: %s. Not scanning' % dir.decode(headphones.SYS_ENCODING))
return
myDB = db.DBConnection()
# Clean up bad filepaths
tracks = myDB.select('SELECT Location, TrackID from tracks WHERE Location IS NOT NULL')
for track in tracks:
if not os.path.isfile(track['Location'].encode(headphones.SYS_ENCODING)):
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [None, None, None, track['TrackID']])
logger.info('Scanning music directory: %s' % dir)
new_artists = []
bitrates = []
myDB.action('DELETE from have')
for r,d,f in os.walk(dir):
for files in f:
# MEDIA_FORMATS = music file extensions, e.g. mp3, flac, etc
if any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS):
song = os.path.join(r, files)
# We need the unicode path to use for logging, inserting into database
unicode_song_path = song.decode(headphones.SYS_ENCODING, 'replace')
# Try to read the metadata
try:
f = MediaFile(song)
except:
logger.error('Cannot read file: ' + unicode_song_path)
continue
# Grab the bitrates for the auto detect bit rate option
if f.bitrate:
bitrates.append(f.bitrate)
# Try to find a match based on artist/album/tracktitle
if f.albumartist:
f_artist = f.albumartist
elif f.artist:
f_artist = f.artist
else:
continue
if f_artist and f.album and f.title:
track = myDB.action('SELECT TrackID from tracks WHERE CleanName LIKE ?', [helpers.cleanName(f_artist +' '+f.album+' '+f.title)]).fetchone()
if not track:
track = myDB.action('SELECT TrackID from tracks WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [f_artist, f.album, f.title]).fetchone()
if track:
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [unicode_song_path, f.bitrate, f.format, track['TrackID']])
continue
# Try to match on mbid if available and we couldn't find a match based on metadata
if f.mb_trackid:
# Wondering if theres a better way to do this -> do one thing if the row exists,
# do something else if it doesn't
track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone()
if track:
myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [unicode_song_path, f.bitrate, f.format, track['TrackID']])
continue
# if we can't find a match in the database on a track level, it might be a new artist or it might be on a non-mb release
new_artists.append(f_artist)
# The have table will become the new database for unmatched tracks (i.e. tracks with no associated links in the database
myDB.action('INSERT INTO have (ArtistName, AlbumTitle, TrackNumber, TrackTitle, TrackLength, BitRate, Genre, Date, TrackID, Location, CleanName, Format) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [f_artist, f.album, f.track, f.title, f.length, f.bitrate, f.genre, f.date, f.mb_trackid, unicode_song_path, helpers.cleanName(f_artist+' '+f.album+' '+f.title), f.format])
logger.info('Completed scanning 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']])
#.........这里部分代码省略.........