mirror of
https://github.com/beetbox/beets.git
synced 2025-12-23 09:03:49 +01:00
merge in some fixes from wlof's repository
This commit is contained in:
commit
f69f69cecf
12 changed files with 49 additions and 26 deletions
|
|
@ -95,9 +95,9 @@ ALBUM_KEYS_ITEM = [f[0] for f in ALBUM_FIELDS if f[2]]
|
||||||
|
|
||||||
# Default search fields for various granularities.
|
# Default search fields for various granularities.
|
||||||
ARTIST_DEFAULT_FIELDS = ('artist',)
|
ARTIST_DEFAULT_FIELDS = ('artist',)
|
||||||
ALBUM_DEFAULT_FIELDS = ARTIST_DEFAULT_FIELDS + ('album', 'genre')
|
ALBUM_DEFAULT_FIELDS = ('album', 'albumartist', 'genre')
|
||||||
ITEM_DEFAULT_FIELDS = ALBUM_DEFAULT_FIELDS + \
|
ITEM_DEFAULT_FIELDS = ARTIST_DEFAULT_FIELDS + ALBUM_DEFAULT_FIELDS + \
|
||||||
('albumartist', 'title', 'comments')
|
('title', 'comments')
|
||||||
|
|
||||||
# Logger.
|
# Logger.
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
@ -1004,11 +1004,22 @@ class Library(BaseLibrary):
|
||||||
self.conn.execute(query, subvars)
|
self.conn.execute(query, subvars)
|
||||||
item._clear_dirty()
|
item._clear_dirty()
|
||||||
|
|
||||||
def remove(self, item, delete=False):
|
def _remove(self, item, delete=False):
|
||||||
|
"""Removes this item from the library. If delete, then item's file
|
||||||
|
is also deleted from disk.
|
||||||
|
"""
|
||||||
self.conn.execute('DELETE FROM items WHERE id=?', (item.id,))
|
self.conn.execute('DELETE FROM items WHERE id=?', (item.id,))
|
||||||
if delete:
|
if delete:
|
||||||
os.unlink(_syspath(item.path))
|
os.unlink(_syspath(item.path))
|
||||||
|
|
||||||
|
def remove(self, item, delete=False):
|
||||||
|
"""Removes this item, and the associated album if the removed item
|
||||||
|
was the last associated item of the album.
|
||||||
|
"""
|
||||||
|
album = self.get_album(item)
|
||||||
|
self._remove(item, delete)
|
||||||
|
if album and not album.items():
|
||||||
|
album._remove(delete)
|
||||||
|
|
||||||
# Browsing.
|
# Browsing.
|
||||||
|
|
||||||
|
|
@ -1190,6 +1201,27 @@ class Album(BaseAlbum):
|
||||||
)
|
)
|
||||||
return ResultIterator(c, self._library)
|
return ResultIterator(c, self._library)
|
||||||
|
|
||||||
|
def _remove(self, delete=False):
|
||||||
|
"""Removes this album from the library. If delete, then album
|
||||||
|
art is deleted from disk, and the directories are removed
|
||||||
|
recursively (if empty).
|
||||||
|
"""
|
||||||
|
# Delete art and directory if empty.
|
||||||
|
if delete:
|
||||||
|
artpath = self.artpath
|
||||||
|
if artpath:
|
||||||
|
os.unlink(_syspath(artpath))
|
||||||
|
try:
|
||||||
|
os.removedirs(_syspath(os.path.dirname(artpath)))
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Remove album from database.
|
||||||
|
self._library.conn.execute(
|
||||||
|
'DELETE FROM albums WHERE id=?',
|
||||||
|
(self.id,)
|
||||||
|
)
|
||||||
|
|
||||||
def remove(self, delete=False):
|
def remove(self, delete=False):
|
||||||
"""Removes this album and all its associated items from the
|
"""Removes this album and all its associated items from the
|
||||||
library. If delete, then the items' files are also deleted
|
library. If delete, then the items' files are also deleted
|
||||||
|
|
@ -1197,19 +1229,10 @@ class Album(BaseAlbum):
|
||||||
"""
|
"""
|
||||||
# Remove items.
|
# Remove items.
|
||||||
for item in self.items():
|
for item in self.items():
|
||||||
self._library.remove(item, delete)
|
self._library._remove(item, delete)
|
||||||
|
|
||||||
# Delete art.
|
|
||||||
if delete:
|
|
||||||
artpath = self.artpath
|
|
||||||
if artpath:
|
|
||||||
os.unlink(_syspath(artpath))
|
|
||||||
|
|
||||||
# Remove album.
|
# Remove album.
|
||||||
self._library.conn.execute(
|
self._remove(delete)
|
||||||
'DELETE FROM albums WHERE id=?',
|
|
||||||
(self.id,)
|
|
||||||
)
|
|
||||||
|
|
||||||
def move(self, copy=False):
|
def move(self, copy=False):
|
||||||
"""Moves (or copies) all items to their destination. Any
|
"""Moves (or copies) all items to their destination. Any
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -17,7 +17,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
from beets.autotag import art
|
from beets.autotag import art
|
||||||
|
|
||||||
class MockHeaders(object):
|
class MockHeaders(object):
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import re
|
import re
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
from beets import autotag
|
from beets import autotag
|
||||||
from beets.library import Item
|
from beets.library import Item
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import ntpath
|
import ntpath
|
||||||
import posixpath
|
import posixpath
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
import beets.library
|
import beets.library
|
||||||
|
|
||||||
def lib(): return beets.library.Library('rsrc' + os.sep + 'test.blb')
|
def lib(): return beets.library.Library('rsrc' + os.sep + 'test.blb')
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
from os.path import join
|
from os.path import join
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
import beets.library
|
import beets.library
|
||||||
from test_db import item
|
from test_db import item
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import time
|
||||||
import musicbrainz2.model
|
import musicbrainz2.model
|
||||||
import musicbrainz2.webservice as mbws
|
import musicbrainz2.webservice as mbws
|
||||||
import _common
|
import _common
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
from beets.autotag import mb
|
from beets.autotag import mb
|
||||||
|
|
||||||
def nullfun(): pass
|
def nullfun(): pass
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest, sys, os, shutil, datetime
|
import unittest, sys, os, shutil, datetime
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
import beets.mediafile
|
import beets.mediafile
|
||||||
|
|
||||||
class EdgeTest(unittest.TestCase):
|
class EdgeTest(unittest.TestCase):
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ layer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest, sys, os, shutil, datetime
|
import unittest, sys, os, shutil, datetime
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
import beets.mediafile
|
import beets.mediafile
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
from beetsplug import bpd
|
from beetsplug import bpd
|
||||||
|
|
||||||
class FauxPathTest(unittest.TestCase):
|
class FauxPathTest(unittest.TestCase):
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest, sys, os
|
import unittest, sys, os
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
import beets.library
|
import beets.library
|
||||||
import test_db
|
import test_db
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import textwrap
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
import logging
|
import logging
|
||||||
import _common
|
import _common
|
||||||
sys.path.append('..')
|
sys.path.insert(0, '..')
|
||||||
from beets import library
|
from beets import library
|
||||||
from beets import ui
|
from beets import ui
|
||||||
from beets.ui import commands
|
from beets.ui import commands
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue