Author: dmeyer
Date: Sun Oct 29 18:33:27 2006
New Revision: 1938

Modified:
   trunk/beacon/src/crawl.py
   trunk/beacon/src/parser.py
   trunk/beacon/src/server.py

Log:
generate more directory attributes based on items

Modified: trunk/beacon/src/crawl.py
==============================================================================
--- trunk/beacon/src/crawl.py   (original)
+++ trunk/beacon/src/crawl.py   Sun Oct 29 18:33:27 2006
@@ -459,9 +459,65 @@
                 yield kaa.notifier.YieldContinue
             counter += 1
 
-        # TODO: when all files and subdirs are scanned, check some extra
-        # stuff. If all items have the same Artist/Album/Image, set this
-        # for the directory, too. Also sum up all 'length' values of the
-        # items and set it for directory
-
+        if not subdirs:
+            # No subdirectories that need to be checked. Add some extra
+            # attributes based on the found items (recursive back to parents)
+            self._add_directory_attributes(directory)
         yield subdirs
+
+
+    def _add_directory_attributes(self, directory):
+        """
+        Add some extra attributes for a directory recursive. This function
+        checkes album, artist, image and length. When there are changes,
+        go up to the parent and check it, too.
+        """
+        data = { 'length': 0, 'artist': u'', 'album': u'', 'image': '' }
+        check_attr = data.keys()[:]
+        check_attr.remove('length')
+        
+        for child in self.db.query(parent=directory):
+            data['length'] += child._beacon_data.get('length', 0) or 0
+            for attr in check_attr:
+                value = child._beacon_data.get(attr, data[attr])
+                if data[attr] == '':
+                    data[attr] = value
+                if data[attr] != value:
+                    data[attr] = None
+                    check_attr.remove(attr)
+
+        if data['image'] and not (data['artist'] or data['album']):
+            # We have neither artist nor album. So this seems to be a video
+            # or an image directory and we don't want to set the image from
+            # maybe one item in that directory as our directory image.
+            data['image'] = None
+            
+        if not directory._beacon_data['image_from_items'] and \
+               directory._beacon_data['image']:
+            # The directory had an image defined and found by the parser.
+            # Delete image from data, we don't want to override it.
+            del data['image']
+            
+        for attr in data.keys():
+            if not data[attr]:
+                # Set empty string to None
+                data[attr] = None
+        for attr in data.keys():
+            if data[attr] != directory._beacon_data[attr]:
+                break
+        else:
+            # no changes.
+            return True
+
+        if 'image' in data:
+            # Mark that this image was taken based on this function, later
+            # scans can remove it if it differs.
+            data['image_from_items'] = True
+
+        # update directory in database
+        self.db.update_object(directory._beacon_id, **data)
+        directory._beacon_data.update(data)
+
+        # check parent
+        if directory._beacon_parent.filename in self.monitoring:
+            self._add_directory_attributes(directory._beacon_parent)

Modified: trunk/beacon/src/parser.py
==============================================================================
--- trunk/beacon/src/parser.py  (original)
+++ trunk/beacon/src/parser.py  Sun Oct 29 18:33:27 2006
@@ -129,7 +129,6 @@
 
     t1 = time.time()
 
-    attributes = { 'mtime': mtime, 'image': None }
     # FIXME: add force parameter from config file:
     # - always force (slow but best result)
     # - never force (faster but maybe wrong)
@@ -137,6 +136,9 @@
     metadata = kaa.metadata.parse(item.filename)
     if not metadata:
         metadata = {}
+
+    attributes = { 'mtime': mtime, 'image': metadata.get('image') }
+    
     if db.object_types().has_key(metadata.get('media')):
         type = metadata['media']
     elif item._beacon_isdir:
@@ -164,10 +166,12 @@
     produced_load = 1
 
     if type == 'dir':
-        for cover in ('cover.jpg', 'cover.png'):
-            if os.path.isfile(item.filename + cover):
-                attributes['image'] = item.filename + cover
-                break
+        attributes['image_from_items'] = False
+        if not attributes.get('image'):
+            for cover in ('cover.jpg', 'cover.png'):
+                if os.path.isfile(item.filename + cover):
+                    attributes['image'] = item.filename + cover
+                    break
         # TODO: do some more stuff here:
         # Audio directories may have a different cover if there is only
         # one jpg in a dir of mp3 files or a files with 'front' in the name.

Modified: trunk/beacon/src/server.py
==============================================================================
--- trunk/beacon/src/server.py  (original)
+++ trunk/beacon/src/server.py  Sun Oct 29 18:33:27 2006
@@ -88,6 +88,12 @@
         self._db = Database(dbdir, None)
         self._next_client = 0
 
+        self._db.register_object_type_attrs("dir",
+            image_from_items = (bool, ATTR_SIMPLE),
+            artist = (unicode, ATTR_SIMPLE),
+            album = (unicode, ATTR_SIMPLE),
+            length = (int, ATTR_SIMPLE))
+
         # files
 
         self.register_file_type_attrs("video",

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to