@@ -1565,7 +1565,8 @@ def script(self, statements):
1565
1565
1566
1566
1567
1567
class Library (object ):
1568
- """A music library using an SQLite database as a metadata store."""
1568
+ """A database of music containing songs and albums.
1569
+ """
1569
1570
def __init__ (self , path = 'library.blb' ,
1570
1571
directory = '~/Music' ,
1571
1572
path_formats = ((PF_KEY_DEFAULT ,
@@ -1703,19 +1704,17 @@ def _tx_stack(self):
1703
1704
yield self ._tx_stacks [thread_id ]
1704
1705
1705
1706
def transaction (self ):
1706
- """Get a transaction object for interacting with the database.
1707
- This should *always* be used as a context manager .
1707
+ """Get a :class:`Transaction` object for interacting directly
1708
+ with the underlying SQLite database .
1708
1709
"""
1709
1710
return Transaction (self )
1710
1711
1711
1712
1712
1713
# Adding objects to the database.
1713
1714
1714
1715
def add (self , item ):
1715
- """Add the item as a new object to the library database. The id
1716
- field will be updated; the new id is returned. If copy, then
1717
- each item is copied to the destination location before it is
1718
- added.
1716
+ """Add the :class:`Item` object to the library database. The
1717
+ item's id field will be updated; the new id is returned.
1719
1718
"""
1720
1719
item .added = time .time ()
1721
1720
if not item ._lib :
@@ -1756,7 +1755,7 @@ def add(self, item):
1756
1755
def add_album (self , items ):
1757
1756
"""Create a new album in the database with metadata derived
1758
1757
from its items. The items are added to the database if they
1759
- don't yet have an ID. Returns an Album object.
1758
+ don't yet have an ID. Returns an :class:` Album` object.
1760
1759
"""
1761
1760
# Set the metadata from the first item.
1762
1761
album_values = dict ((key , items [0 ][key ]) for key in ALBUM_KEYS_ITEM )
@@ -1809,15 +1808,17 @@ def _fetch(self, model_cls, query, order_by=None):
1809
1808
return Results (model_cls , rows , self , None if where else query )
1810
1809
1811
1810
def albums (self , query = None ):
1812
- """Get a sorted list of Album objects matching the given query.
1811
+ """Get a sorted list of :class:`Album` objects matching the
1812
+ given query.
1813
1813
"""
1814
1814
order = '{0}, album' .format (
1815
1815
_orelse ("albumartist_sort" , "albumartist" )
1816
1816
)
1817
1817
return self ._fetch (Album , query , order )
1818
1818
1819
1819
def items (self , query = None ):
1820
- """Get a sorted list of Item objects matching the given query.
1820
+ """Get a sorted list of :class:`Item` objects matching the given
1821
+ query.
1821
1822
"""
1822
1823
order = '{0}, album' .format (
1823
1824
_orelse ("artist_sort" , "artist" )
@@ -1834,14 +1835,15 @@ def _get(self, model_cls, id):
1834
1835
return self ._fetch (model_cls , MatchQuery ('id' , id )).get ()
1835
1836
1836
1837
def get_item (self , id ):
1837
- """Fetch an Item by its ID. Returns None if no match is found.
1838
+ """Fetch an :class:`Item` by its ID. Returns `None` if no match is
1839
+ found.
1838
1840
"""
1839
1841
return self ._get (Item , id )
1840
1842
1841
1843
def get_album (self , item_or_id ):
1842
- """Given an album ID or an item associated with an album,
1843
- return an Album object for the album. If no such album exists,
1844
- returns None.
1844
+ """Given an album ID or an item associated with an album, return
1845
+ an :class:` Album` object for the album. If no such album exists,
1846
+ returns ` None` .
1845
1847
"""
1846
1848
if isinstance (item_or_id , int ):
1847
1849
album_id = item_or_id
0 commit comments