i appreciate that some of you are trying to be helpful.
let me clarify the requirements again:
- the filesystem must remain unmodified. no symlinks. no changing whats
there. it is a correct set of collections of collections. it is
correctly tagged.
- users want to be able to use the "browse music folder" and see
everything, as would be natural per point 1.
- some number of items are duplicates. these should not show up in a
browse or search, but should continue to show up in a directory browse.
- lets leave it to me to decide what should be hidden or not. i've
already done that as shown below. i do understand the logic applied to
determine album alignment, and i do not consider this a difficult
problem. in fact, i believe application of the following logic will be
generally useful for some people, and not harmful for others. its
alright if you think that my requirements are a corner case. i find this
hard to believe, but lets not belabor that now.
- once items are tagged to be hidden, they should not show up in any
search or browse views, except when viewing the real directory
structure.
i've written the following code to do what i want, albeit in a very
messy and expensive way:
Code:
--------------------
#!/usr/bin/python
# presentation layer album dedupe
import sys
import MySQLdb
from collections import defaultdict
try:
conn = MySQLdb.connect (host = "127.0.0.1",
user = "root",
passwd = "",
port = 9092,
db = "slimserver")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cursor = conn.cursor ()
# AND (c1.year = c2.year OR c1.year = 0 OR c2.year = 0) \
cursor.execute ("select C2.id, C2.titlesort, C2.contributor, C2.year,
SUM(tracks.filesize) \
FROM albums as C1, albums as C2 \
JOIN tracks WHERE C1.titlesort = C2.titlesort AND C1.contributor =
C2.contributor \
AND (c1.year = c2.year OR c2.year = 0) \
AND C1.id != C2.id AND tracks.album = c2.id \
group by tracks.album order by titlesort")
d = defaultdict(list)
hidelist = []
while (1):
row = cursor.fetchone ()
if row == None:
break
d[row[1]].append((row[4],row[0]))
for k, v in d.items():
if len(v) > 1:
print "%s:" % k
largest = 0
selected = 0
# first pass gets largest value
for l, i in v:
if largest < l:
largest = l
# next pass determines rows to hide
for l, i in v:
if l != largest:
if not l:
print "hide: <Null> %d" % (i);
else:
print "hide: %d %d" % (l, i)
hidelist.append(i)
else:
if selected:
# duplicate size, arbitrary selection
print "hide: %d %d" % (l, i)
hidelist.append(i)
else:
selected+=1
print "keep: %d %d" % (l, i)
print "hiding %d duplicate albums" % (len(hidelist))
for i in hidelist:
updatestr = "UPDATE albums SET invisible = 1 WHERE id = " + str(i)
cursor.execute (updatestr)
# hacky, but works for now: just blow away records of bad dupes in the db
# everything above this line is fine. everything below this line should be
# replaced by a server side SELECT exception rather than this expensive
# set of deletes
cursor.execute ("delete tracks.* from tracks LEFT JOIN albums on tracks.album
= albums.id \
where albums.invisible = 1");
cursor.execute ("delete from albums where albums.invisible = 1");
cursor.close ()
conn.commit ()
conn.close ()
--------------------
As I have an intermediate step wherein I flag each album as invisible
by adding a column to the table for albums i don't want, and could
easily add that column to tracks as well, it seems much more reasonable
to just select those out when doing searches/browses. That way I'm not
in a race with the scanner, and don't have to run expensive deletes.
I tried to add this logic in Slim::Control::Queries.pm in the following
places, but don't see it reflected in the SQL queries being passed to
the server, so I apparently have misplaced my strategy somewhat:
in albumsQuery:
$where->{'me.invisible'} = {'!=' => '1'};
in artistsQuery:
$where->{'me.invisible'} = {'!=' => '1'};
$where_va->{'me.invisible'} = {'!=' => '1'};
in titlesQuery:
$where->{'album.invisible'} = {'!=' => '1'};
push @{$attr->{'join'}}, 'album';
So, without any more of the telling me why I don't know what I actually
want, can someone kindly help me figure out where I should place
modifications with this intent so that my searches and browses run
against the db select out rows flagged as invisible?
Thanks.
--
chroma
------------------------------------------------------------------------
chroma's Profile: http://forums.slimdevices.com/member.php?userid=22010
View this thread: http://forums.slimdevices.com/showthread.php?t=74288
_______________________________________________
discuss mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/discuss