mishmash package

Submodules

mishmash.config module

class mishmash.config.Config(filename, **kwargs)[source]

Bases: nicfit.config.Config

db_url
music_libs
class mishmash.config.MusicLibrary(name, paths=None, excludes=None, sync=True)[source]

Bases: object

static fromConfig(config)[source]

mishmash.console module

mishmash.console.promptArtist(text, name=None, default_name=None, default_city=None, default_state=None, default_country=None, artist=None)[source]
mishmash.console.selectArtist(heading, choices=None, multiselect=False, allow_create=True)[source]

mishmash.core module

class mishmash.core.Command(subparsers=None, **kwargs)[source]

Bases: nicfit.command.Command

Base class for MishMash commands.

Construct a command. Any kwargs are added to the class object using setattr. All commands have an ArgumentParser, either constructed here or when subparsers is given a new parser is created using its add_parser method.

run(args, config)[source]
exception mishmash.core.CommandError(msg, exit_status=1)[source]

Bases: Exception

Base error type for nicfit.command.Command errors.

mishmash.database module

class mishmash.database.DatabaseInfo(engine, SessionMaker, connection)

Bases: tuple

Create new instance of DatabaseInfo(engine, SessionMaker, connection)

SessionMaker

Alias for field number 1

connection

Alias for field number 2

engine

Alias for field number 0

mishmash.database.dropAll(url)[source]
mishmash.database.getTag(t, session, lid, add=False)[source]
mishmash.database.init(db_url, engine_args=None, session_args=None, trans_mgr=None, scoped=False)[source]
mishmash.database.search(session, query)[source]

mishmash.orm module

Object to relational database mappings for all tables.

class mishmash.orm.Album(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

DATE_LIMIT = 24
TITLE_LIMIT = 256
artist
artist_id
date_added
duration
getBestDate()[source]
id
images

one-to-many album images.

lib_id
library
original_release_date
recording_date
release_date
tags
title
tracks
type
class mishmash.orm.AlbumDate(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Custom column type for eyed3.core.Date objects. That is, dates than can have empty rather than default date fields. For example, 1994 with no month and day is different than 1994-01-01, as datetime provides.

Construct a TypeDecorator.

Arguments sent here are passed to the constructor of the class assigned to the impl class level attribute, assuming the impl is a callable, and the resulting object is assigned to the self.impl instance attribute (thus overriding the class attribute of the same name).

If the class level impl is not a callable (the unusual case), it will be assigned to the same instance attribute ‘as-is’, ignoring those arguments passed to the constructor.

Subclasses can override this to customize the generation of self.impl entirely.

impl = String(length=24)
process_bind_param(value, dialect)[source]

Receive a bound parameter value to be converted.

Subclasses override this method to return the value that should be passed along to the underlying TypeEngine object, and from there to the DBAPI execute() method.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.
  • dialect – the Dialect in use.
process_result_value(value, dialect)[source]

Receive a result-row column value to be converted.

Subclasses should implement this method to operate on data fetched from the database.

Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying TypeEngine object, originally from the DBAPI cursor method fetchone() or similar.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.
  • dialect – the Dialect in use.

This operation should be designed to be reversible by the “process_bind_param” method of this class.

class mishmash.orm.Artist(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

CITY_LIMIT = 64
COUNTRY_LIMIT = 3
NAME_LIMIT = 256
SORT_NAME_LIMIT = 258
STATE_LIMIT = 32
albums

all albums by the artist

static checkUnique(artists)[source]
date_added
getAlbumsByType(album_type)[source]
getTrackSingles()[source]
id
images

one-to-many artist images.

is_various_artist
lib_id
library
name
origin(n=3, country_code='country_name', title_case=True)[source]
origin_city
origin_country
origin_state
sort_name
tags

one-to-many (artist->tag) and many-to-one (tag->artist)

tracks

all tracks by the artist

url_name
class mishmash.orm.Image(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

ARTIST_TYPE = 'ARTIST'
BACK_COVER_TYPE = 'BACK_COVER'
DESC_LIMIT = 1024
FRONT_COVER_TYPE = 'FRONT_COVER'
IMAGE_TYPES = ['FRONT_COVER', 'BACK_COVER', 'MISC_COVER', 'LOGO', 'ARTIST', 'LIVE']
LIVE_TYPE = 'LIVE'
LOGO_TYPE = 'LOGO'
MD5_LIMIT = 32
MIMETYPE_LIMIT = 32
MISC_COVER_TYPE = 'MISC_COVER'
data
description

The description will be the base file name when the source if a file.

static fromFile(path, type_)[source]
static fromTagFrame(img, type_)[source]
id
md5
mime_type
size
type
class mishmash.orm.Library(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

NAME_LIMIT = 64
add(album)[source]
albums()[source]
id
classmethod iterall(session, names=None)[source]

Iterate over all Library rows found in session. :param names: Optional sequence of names to filter on.

last_sync
name
class mishmash.orm.Meta(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

Table meta used for storing database schema version, timestamps, and any other metadata about the music collection.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

VERSION_LIMIT = 32
last_sync

A UTC timestamp of the last sync operation.

version

The MishMash version defines the database schema.

class mishmash.orm.OrmObject[source]

Bases: object

Base classes for all other mishmash.orm classes.

mishmash.orm.TABLES = [Table('meta', MetaData(bind=None), Column('version', String(length=32), table=<meta>, primary_key=True, nullable=False), Column('last_sync', DateTime(), table=<meta>), schema=None), Table('libraries', MetaData(bind=None), Column('id', Integer(), table=<libraries>, primary_key=True, nullable=False, default=Sequence('libraries_id_seq', metadata=MetaData(bind=None))), Column('name', Unicode(length=64), table=<libraries>, nullable=False), Column('last_sync', DateTime(), table=<libraries>), schema=None), Table('tags', MetaData(bind=None), Column('id', Integer(), table=<tags>, primary_key=True, nullable=False, default=Sequence('tags_id_seq', metadata=MetaData(bind=None))), Column('name', Unicode(length=64), table=<tags>, nullable=False), Column('lib_id', Integer(), ForeignKey('libraries.id'), table=<tags>, nullable=False), schema=None), Table('artists', MetaData(bind=None), Column('id', Integer(), table=<artists>, primary_key=True, nullable=False, default=Sequence('artists_id_seq', metadata=MetaData(bind=None))), Column('name', Unicode(length=256), table=<artists>, nullable=False), Column('sort_name', Unicode(length=258), table=<artists>, nullable=False), Column('date_added', DateTime(), table=<artists>, nullable=False, default=ColumnDefault(<function datetime.now>)), Column('origin_city', Unicode(length=64), table=<artists>), Column('origin_state', Unicode(length=32), table=<artists>), Column('origin_country', String(length=3), table=<artists>), Column('lib_id', Integer(), ForeignKey('libraries.id'), table=<artists>, nullable=False), schema=None), Table('albums', MetaData(bind=None), Column('id', Integer(), table=<albums>, primary_key=True, nullable=False, default=Sequence('albums_id_seq', metadata=MetaData(bind=None))), Column('title', Unicode(length=256), table=<albums>, nullable=False), Column('type', Enum('lp', 'ep', 'compilation', 'live', 'various', 'demo', 'single', name='album_types'), table=<albums>, nullable=False, default=ColumnDefault('lp')), Column('date_added', DateTime(), table=<albums>, nullable=False, default=ColumnDefault(<function datetime.now>)), Column('release_date', AlbumDate(length=24), table=<albums>), Column('original_release_date', AlbumDate(length=24), table=<albums>), Column('recording_date', AlbumDate(length=24), table=<albums>), Column('artist_id', Integer(), ForeignKey('artists.id'), table=<albums>, nullable=False), Column('lib_id', Integer(), ForeignKey('libraries.id'), table=<albums>, nullable=False), schema=None), Table('tracks', MetaData(bind=None), Column('id', Integer(), table=<tracks>, primary_key=True, nullable=False, default=Sequence('tracks_id_seq', metadata=MetaData(bind=None))), Column('path', String(length=2048), table=<tracks>, nullable=False), Column('size_bytes', Integer(), table=<tracks>, nullable=False), Column('ctime', DateTime(), table=<tracks>, nullable=False), Column('mtime', DateTime(), table=<tracks>, nullable=False), Column('date_added', DateTime(), table=<tracks>, nullable=False, default=ColumnDefault(<function datetime.now>)), Column('time_secs', Float(), table=<tracks>, nullable=False), Column('title', Unicode(length=256), table=<tracks>, nullable=False), Column('track_num', SmallInteger(), table=<tracks>), Column('track_total', SmallInteger(), table=<tracks>), Column('media_num', SmallInteger(), table=<tracks>), Column('media_total', SmallInteger(), table=<tracks>), Column('bit_rate', SmallInteger(), table=<tracks>), Column('variable_bit_rate', Boolean(), table=<tracks>), Column('metadata_format', Enum('ID3v1.0', 'ID3v1.1', 'ID3v2.2', 'ID3v2.3', 'ID3v2.4', name='metadata_format'), table=<tracks>, nullable=False), Column('artist_id', Integer(), ForeignKey('artists.id'), table=<tracks>, nullable=False), Column('album_id', Integer(), ForeignKey('albums.id'), table=<tracks>), Column('lib_id', Integer(), ForeignKey('libraries.id'), table=<tracks>, nullable=False), schema=None), Table('images', MetaData(bind=None), Column('id', Integer(), table=<images>, primary_key=True, nullable=False, default=Sequence('images_id_seq', metadata=MetaData(bind=None))), Column('type', Enum('FRONT_COVER', 'BACK_COVER', 'MISC_COVER', 'LOGO', 'ARTIST', 'LIVE', name='image_types'), table=<images>, nullable=False), Column('mime_type', String(length=32), table=<images>, nullable=False), Column('md5', String(length=32), table=<images>, nullable=False), Column('size', Integer(), table=<images>, nullable=False), Column('description', String(length=1024), table=<images>, nullable=False), Column('data', LargeBinary(), table=<images>, nullable=False), schema=None), Table('artist_tags', MetaData(bind=None), Column('artist_id', Integer(), ForeignKey('artists.id'), table=<artist_tags>), Column('tag_id', Integer(), ForeignKey('tags.id'), table=<artist_tags>), schema=None), Table('album_tags', MetaData(bind=None), Column('album_id', Integer(), ForeignKey('albums.id'), table=<album_tags>), Column('tag_id', Integer(), ForeignKey('tags.id'), table=<album_tags>), schema=None), Table('track_tags', MetaData(bind=None), Column('track_id', Integer(), ForeignKey('tracks.id'), table=<track_tags>), Column('tag_id', Integer(), ForeignKey('tags.id'), table=<track_tags>), schema=None), Table('artist_images', MetaData(bind=None), Column('artist_id', Integer(), ForeignKey('artists.id'), table=<artist_images>), Column('img_id', Integer(), ForeignKey('images.id'), table=<artist_images>), schema=None), Table('album_images', MetaData(bind=None), Column('album_id', Integer(), ForeignKey('albums.id'), table=<album_images>), Column('img_id', Integer(), ForeignKey('images.id'), table=<album_images>), schema=None)]

All the table instances. Order matters (esp. for postgresql). The tables are created in normal order, and dropped in reverse order.

class mishmash.orm.Tag(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

NAME_LIMIT = 64
id
lib_id
library
name
class mishmash.orm.Track(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, mishmash.orm.OrmObject

Along with the column args a audio_file keyword may be passed for this class to use for initialization.

METADATA_FORMATS = ['ID3v1.0', 'ID3v1.1', 'ID3v2.2', 'ID3v2.3', 'ID3v2.4']
PATH_LIMIT = 2048
TITLE_LIMIT = 256
album
album_id
artist
artist_id
bit_rate
ctime
date_added
id
lib_id
library
media_num
media_total
metadata_format
mtime
path
size_bytes
tags
time_secs
title
track_num
track_total
update(audio_file)[source]
variable_bit_rate
mishmash.orm.album_images = Table('album_images', MetaData(bind=None), Column('album_id', Integer(), ForeignKey('albums.id'), table=<album_images>), Column('img_id', Integer(), ForeignKey('images.id'), table=<album_images>), schema=None)

Pivot table ‘album_images’ for mapping an album ID to a value in the images table.

mishmash.orm.album_tags = Table('album_tags', MetaData(bind=None), Column('album_id', Integer(), ForeignKey('albums.id'), table=<album_tags>), Column('tag_id', Integer(), ForeignKey('tags.id'), table=<album_tags>), schema=None)

Pivot table ‘album_tags’ for mapping an album ID to a value in the tags table.

mishmash.orm.artist_images = Table('artist_images', MetaData(bind=None), Column('artist_id', Integer(), ForeignKey('artists.id'), table=<artist_images>), Column('img_id', Integer(), ForeignKey('images.id'), table=<artist_images>), schema=None)

Pivot table ‘artist_images’ for mapping an artist ID to a value in the images table.

mishmash.orm.artist_tags = Table('artist_tags', MetaData(bind=None), Column('artist_id', Integer(), ForeignKey('artists.id'), table=<artist_tags>), Column('tag_id', Integer(), ForeignKey('tags.id'), table=<artist_tags>), schema=None)

Pivot table ‘artist_tags’ for mapping an artist ID to a value in the tags table.

mishmash.orm.getSortName(name)[source]
mishmash.orm.set_sqlite_pragma(dbapi_connection, connection_record)[source]

Allows foreign keys to work in sqlite.

mishmash.orm.track_tags = Table('track_tags', MetaData(bind=None), Column('track_id', Integer(), ForeignKey('tracks.id'), table=<track_tags>), Column('tag_id', Integer(), ForeignKey('tags.id'), table=<track_tags>), schema=None)

Pivot table ‘track_tags’ for mapping a track ID to a value in the tags table.

mishmash.util module

mishmash.util.commonDirectoryPrefix(*args)[source]
mishmash.util.mostCommonItem(lst)[source]

Choose the most common item from the list, or the first item if all items are unique.

mishmash.util.normalizeCountry(country_str, target='iso3c', title_case=False)[source]

Return a normalized name/code for country in country_str. The input can be a code or name, the target determines output value. 3 character ISO code is the default (iso3c), ‘country_name’, and ‘iso2c’ are common also. See countrycode.countrycode for details and other options. Raises ValueError if the country is unrecognized.

mishmash.util.safeDbUrl(db_url)[source]

Obfuscates password from a database URL.

mishmash.util.sortByDate(things, prefer_recording_date=False)[source]
mishmash.util.splitNameByPrefix(s)[source]

Module contents

mishmash.getLogger(name=None)[source]