eyed3.utils package¶
Submodules¶
eyed3.utils.art module¶
-
eyed3.utils.art.
FRONT_COVER
= 'FRONT_COVER'¶ Album front cover.
-
eyed3.utils.art.
BACK_COVER
= 'BACK_COVER'¶ Album back cover.
-
eyed3.utils.art.
MISC_COVER
= 'MISC_COVER'¶ Other part of the album cover; liner notes, gate-fold, etc.
-
eyed3.utils.art.
LOGO
= 'LOGO'¶ Artist/band logo.
-
eyed3.utils.art.
ARTIST
= 'ARTIST'¶ Artist/band images.
-
eyed3.utils.art.
LIVE
= 'LIVE'¶ Artist/band images.
-
eyed3.utils.art.
FILENAMES
= {'ARTIST': ['artist*'], 'BACK_COVER': ['cover-back', 'back', 'cover-back_*'], 'FRONT_COVER': ['cover-front', 'cover-alternate*', 'cover', 'folder', 'front', 'cover-front_*', 'flier'], 'LIVE': ['live*'], 'LOGO': ['logo*'], 'MISC_COVER': ['cover-insert*', 'cover-liner*', 'cover-disc', 'cover-media*']}¶ A mapping of art types to lists of filename patterns (excluding file extension): type -> [file_pattern, ..].
-
eyed3.utils.art.
TO_ID3_ART_TYPES
= {'ARTIST': [7, 8, 10], 'BACK_COVER': [4], 'FRONT_COVER': [3, 0, 1, 5], 'LIVE': [15, 14], 'LOGO': [19], 'MISC_COVER': [6]}¶ A mapping of art types to ID3 APIC (image) types: type -> [apic_type, ..]
-
eyed3.utils.art.
FROM_ID3_ART_TYPES
= {0: 'FRONT_COVER', 1: 'FRONT_COVER', 3: 'FRONT_COVER', 4: 'BACK_COVER', 5: 'FRONT_COVER', 6: 'MISC_COVER', 7: 'ARTIST', 8: 'ARTIST', 10: 'ARTIST', 14: 'LIVE', 15: 'LIVE', 19: 'LOGO'}¶ A mapping of ID3 art types to eyeD3 art types; the opposite of TO_ID3_ART_TYPES.
eyed3.utils.binfuncs module¶
-
eyed3.utils.binfuncs.
bytes2bin
(bytes, sz=8)[source]¶ Accepts a string of
bytes
(chars) and returns an array of bits representing the bytes in big endian byte order. An optional maxsz
for each byte (default 8 bits/byte) which can be used to mask out higher bits.
-
eyed3.utils.binfuncs.
bin2dec
(x)[source]¶ Convert
x
, an array of “bits” (MSB first), to it’s decimal value.
eyed3.utils.console module¶
-
class
eyed3.utils.console.
AnsiFore
[source]¶ Bases:
object
-
GREY
= 30¶
-
RED
= 31¶
-
GREEN
= 32¶
-
YELLOW
= 33¶
-
BLUE
= 34¶
-
MAGENTA
= 35¶
-
CYAN
= 36¶
-
WHITE
= 37¶
-
RESET
= 39¶
-
-
class
eyed3.utils.console.
AnsiBack
[source]¶ Bases:
object
-
GREY
= 40¶
-
RED
= 41¶
-
GREEN
= 42¶
-
YELLOW
= 43¶
-
BLUE
= 44¶
-
MAGENTA
= 45¶
-
CYAN
= 46¶
-
WHITE
= 47¶
-
RESET
= 49¶
-
-
class
eyed3.utils.console.
AnsiStyle
[source]¶ Bases:
object
-
RESET_ALL
= 0¶
-
BRIGHT
= 1¶
-
RESET_BRIGHT
= 22¶
-
DIM
= 2¶
-
RESET_DIM
= 22¶
-
ITALICS
= 3¶
-
RESET_ITALICS
= 23¶
-
UNDERLINE
= 4¶
-
RESET_UNDERLINE
= 24¶
-
BLINK_SLOW
= 5¶
-
RESET_BLINK_SLOW
= 25¶
-
BLINK_FAST
= 6¶
-
RESET_BLINK_FAST
= 26¶
-
INVERSE
= 7¶
-
RESET_INVERSE
= 27¶
-
STRIKE_THRU
= 9¶
-
RESET_STRIKE_THRU
= 29¶
-
-
class
eyed3.utils.console.
Spinner
(msg, file=None, step=1, chars=None, use_unicode=True, print_done=True)[source]¶ Bases:
object
A class to display a spinner in the terminal.
It is designed to be used with the with statement:
with Spinner("Reticulating splines", "green") as s: for item in enumerate(items): s.next()
-
class
eyed3.utils.console.
ProgressBar
(total_or_items, file=None)[source]¶ Bases:
object
A class to display a progress bar in the terminal.
It is designed to be used either with the with statement:
with ProgressBar(len(items)) as bar: for item in enumerate(items): bar.update()
or as a generator:
for item in ProgressBar(items): item.process()
- total_or_items : int or sequence
- If an int, the number of increments in the process being tracked. If a sequence, the items to iterate over.
- file : writable file-like object, optional
- The file to write the progress bar to. Defaults to sys.stdout. If file is not a tty (as determined by calling its isatty member, if any), the scrollbar will be completely silent.
-
update
(value=None)[source]¶ Update the progress bar to the given value (out of the total given to the constructor).
-
classmethod
map
(function, items, multiprocess=False, file=None)[source]¶ Does a map operation while displaying a progress bar with percentage complete.
def work(i): print(i) ProgressBar.map(work, range(50))
Parameters:
- function : function
- Function to call for each step
- items : sequence
- Sequence where each element is a tuple of arguments to pass to function.
- multiprocess : bool, optional
- If True, use the multiprocessing module to distribute each task to a different processor core.
- file : writeable file-like object, optional
- The file to write the progress bar to. Defaults to sys.stdout. If file is not a tty (as determined by calling its isatty member, if any), the scrollbar will be completely silent.
-
eyed3.utils.console.
cformat
(msg, fg, bg=None, styles=None)[source]¶ Format
msg
with foreground and optional background. Optionalstyles
lists will also be applied. The formatted string is returned.
eyed3.utils.log module¶
-
class
eyed3.utils.log.
Logger
(name)[source]¶ Bases:
logging.Logger
Base class for all loggers
eyed3.utils.prompt module¶
-
eyed3.utils.prompt.
DISABLE_PROMPT
= None¶ Whenever a prompt occurs and this value is not
None
it can beexit
to call sys.exit (see EXIT_STATUS) orraise
to throw a RuntimeError, which can be caught if desired.
-
exception
eyed3.utils.prompt.
PromptExit
[source]¶ Bases:
RuntimeError
Raised when
DISABLE_PROMPT
is ‘raise’ andprompt
is called.
-
eyed3.utils.prompt.
prompt
(msg, default=None, required=True, type_=<class 'str'>, validate=None, choices=None)[source]¶ Prompt user for imput, the prequest is in
msg
. Ifdefault
is notNone
it will be displayed as the default and returned if not input is entered. The valueNone
is only returned ifrequired
isFalse
. The response is passed totype_
for conversion (default is unicode) before being returned. An optional list of valid responses can be provided inchoices
.
Module contents¶
-
eyed3.utils.
os_walk
(top='.', topdown=True, onerror=None, *, follow_symlinks=True, dir_fd=None)¶ Directory tree generator.
This behaves exactly like walk(), except that it yields a 4-tuple
dirpath, dirnames, filenames, dirfddirpath, dirnames and filenames are identical to walk() output, and dirfd is a file descriptor referring to the directory dirpath.
The advantage of fwalk() over walk() is that it’s safe against symlink races (when follow_symlinks is False).
- If dir_fd is not None, it should be a file descriptor open to a directory,
- and top should be relative; top will then be relative to that directory. (dir_fd is always supported for fwalk.)
Caution: Since fwalk() yields file descriptors, those are only valid until the next iteration step, so you should dup() them if you want to keep them for a longer period.
Example:
import os for root, dirs, files, rootfd in os.fwalk(‘python/Lib/email’):
print(root, “consumes”, end=”“) print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]),
end=”“)print(“bytes in”, len(files), “non-directory files”) if ‘CVS’ in dirs:
dirs.remove(‘CVS’) # don’t visit CVS directories
-
eyed3.utils.
guessMimetype
(filename, with_encoding=False, all_types=False)[source]¶ Return the mime-type for
filename
(or list of possible types when all_types is True).If
with_encoding
is True the encoding is included and a 2-tuple is returned, (mine, enc).
-
eyed3.utils.
walk
(handler, path, excludes=None, fs_encoding='utf-8')[source]¶ A wrapper around os.walk which handles exclusion patterns and multiple path types (unicode, pathlib.Path, bytes).
-
class
eyed3.utils.
FileHandler
[source]¶ Bases:
object
A handler interface for
eyed3.utils.walk()
callbacks.-
handleFile
(f)[source]¶ Called for each file walked. The file
f
is the full path and the return value is ignored. If the walk should abort the method should raise aStopIteration
exception.
-
-
eyed3.utils.
requireUnicode
(*args)[source]¶ Function decorator to enforce unicode argument types.
None
is a valid argument value, in all cases, regardless of not being unicode.*args
Positional arguments may be numeric argument index values (requireUnicode(1, 3) - requires argument 1 and 3 are unicode) or keyword argument names (requireUnicode(“title”)) or a combination thereof.
-
eyed3.utils.
requireBytes
(*args)[source]¶ Function decorator to enforce unicode argument types.
None
is a valid argument value, in all cases, regardless of not being unicode.*args
Positional arguments may be numeric argument index values (requireUnicode(1, 3) - requires argument 1 and 3 are unicode) or keyword argument names (requireUnicode(“title”)) or a combination thereof.
-
eyed3.utils.
formatTime
(seconds, total=None, short=False)[source]¶ Format
seconds
(number of seconds) as a string representation. Whenshort
is False (the default) the format is:HH:MM:SS.Otherwise, the format is exacly 6 characters long and of the form:
1w 3d 2d 4h 1h 5m 1m 4s 15sIf
total
is not None it will also be formatted and appended to the result seperated by ‘ / ‘.
-
eyed3.utils.
KB_BYTES
= 1024¶ Number of bytes per KB (2^10)
-
eyed3.utils.
MB_BYTES
= 1048576¶ Number of bytes per MB (2^20)
-
eyed3.utils.
GB_BYTES
= 1073741824¶ Number of bytes per GB (2^30)
-
eyed3.utils.
KB_UNIT
= 'KB'¶ Kilobytes abbreviation
-
eyed3.utils.
MB_UNIT
= 'MB'¶ Megabytes abbreviation
-
eyed3.utils.
GB_UNIT
= 'GB'¶ Gigabytes abbreviation
-
eyed3.utils.
formatSize
(size, short=False)[source]¶ Format
size
(nuber of bytes) into string format doing KB, MB, or GB conversion where necessary.When
short
is False (the default) the format is smallest unit of bytes and largest gigabytes; ‘234 GB’. The short version is 2-4 characters long and of the form256b 64k 1.1G
-
eyed3.utils.
chunkCopy
(src_fp, dest_fp, chunk_sz=524288)[source]¶ Copy
src_fp
todest_fp
inchunk_sz
byte increments.
-
class
eyed3.utils.
ArgumentParser
(*args, **kwargs)[source]¶ Bases:
argparse.ArgumentParser
Subclass of argparse.ArgumentParser that adds version and log level options.
-
eyed3.utils.
datePicker
(thing, prefer_recording_date=False)[source]¶ This function returns a date of some sort, amongst all the possible dates (members called release_date, original_release_date, and recording_date of type eyed3.core.Date).
The order of preference is: 1) date of original release 2) date of this versions release 3) the recording date.
Unless
prefer_recording_date
isTrue
in which case the order is 3, 1, 2.None
will be returned if no dates are available.