Author: dmeyer
Date: Thu Feb 8 12:52:44 2007
New Revision: 9177
Modified:
trunk/ui/src/audio/audioitem.py
trunk/ui/src/config.cxml
trunk/ui/src/directory.py
trunk/ui/src/fxditem.py
trunk/ui/src/menu/item.py
trunk/ui/src/menu/mediaitem.py
trunk/ui/src/video/videoitem.py
Log:
update directory config and fix sorting
Modified: trunk/ui/src/audio/audioitem.py
==============================================================================
--- trunk/ui/src/audio/audioitem.py (original)
+++ trunk/ui/src/audio/audioitem.py Thu Feb 8 12:52:44 2007
@@ -68,23 +68,17 @@
self.length = 0
- def sort(self, mode=None):
+ def sort(self, mode='name'):
"""
Returns the string how to sort this item
"""
- if mode == 'date':
- if self.filename:
- return u'%s%s' % (os.stat(self.filename).st_ctime,
- str_to_unicode(self.filename))
- if mode == 'advanced':
- # sort by track number
+ if mode in ('name', 'smart'):
try:
- return '%s %0.3i-%s' % (self['discs'], int(self['trackno']),
- str_to_unicode(self.url))
- except ValueError:
- return '%s-%s' % (unicode(self['trackno']),
- str_to_unicode(self.url))
- return str_to_unicode(self.url)
+ track = int(self.info.get('trackno'))
+ except (ValueError, KeyError, TypeError):
+ track = 0
+ return u'%20d %s' % (track, self.name)
+ return MediaItem.sort(self, mode)
def set_url(self, url):
Modified: trunk/ui/src/config.cxml
==============================================================================
--- trunk/ui/src/config.cxml (original)
+++ trunk/ui/src/config.cxml Thu Feb 8 12:52:44 2007
@@ -3,58 +3,69 @@
<group name="directory">
<desc>Directory settings</desc>
- <group name="sort">
- <desc>Settings how to sort items in a directory</desc>
- <var name="type" default="tv-by-date">
- <desc>
- How to sort the items in a directory. Valid values are
- 'name' (sort by name), 'date' (sort by date) and
- 'tv-by-date' (sort by name and only sort directories in the
- tv menu by date)
- </desc>
- <values>
- <value>name</value>
- <value>date</value>
- <value>tv-by-date</value>
- </values>
- </var>
- <var name="reverse" default="False">
- <desc>Sort directory items in reverse order</desc>
- </var>
- <var name="smart" default="True">
- <desc>Ignore 'The' and 'A' when sorting by name</desc>
- </var>
- </group>
-
- <group name="playlist">
- <desc>Setting for handling a directory as playlist</desc>
-
- <var name="autoplay" default="True">
- <desc>Autoplay an item if only one item is in the
directory</desc>
- </var>
-
- <var name="isplaylist" default="audio,image">
- <desc>
- Make all items a playlist. So when one is finished, the
- next one will start. It's also possible to browse through
- the list with UP and DOWN. The value is a comma sperated
- list of media types.
- </desc>
- </var>
-
- <var name="include" default="audio,image">
- <desc>
- Add playlist file from the directory. The value is a comma
- sperated list of media types.
- </desc>
- </var>
- <var name="random" default="audio">
- <desc>
- Add a random playlist item. The value is a comma sperated
- list of media types.
- </desc>
- </var>
- </group>
+ <var name="sort" default="smart">
+ <desc>
+ How to sort the items in a directory. Valid values are
+ 'name' (name of the item, maybe based on metadata), 'smart'
+ (like name but ignore "The" and "A" at the beginning),
+ 'filename', 'date-old-first' and 'date-new-first'.
+ </desc>
+ <values>
+ <value>name</value>
+ <value>smart</value>
+ <value>filename</value>
+ <value>date-old-first</value>
+ <value>date-new-first</value>
+ </values>
+ </var>
+
+ <var name="tvsort" default="date-old-first">
+ <desc>
+ How to sort the items in a directory in the tv menu.
+ </desc>
+ <values>
+ <value>name</value>
+ <value>smart</value>
+ <value>filename</value>
+ <value>date-old-first</value>
+ <value>date-new-first</value>
+ </values>
+ </var>
+
+ <var name="autoplay-single-item" default="True">
+ <desc>Autoplay an item if only one item is in the directory</desc>
+ </var>
+
+ <var name="autoplay-items" type="str">
+ <desc>
+ Make play and not brose the default action if a directory only
+ contains files and no subdirectories. The value is a comma
+ sperated list of media types.
+ </desc>
+ </var>
+
+ <var name="add-playlist-items" default="audio,image">
+ <desc>
+ Add playlist file from the directory. The value is a comma
+ sperated list of media types.
+ </desc>
+ </var>
+
+ <var name="add-random-playlist" default="audio">
+ <desc>
+ Add a random playlist item. The value is a comma sperated
+ list of media types.
+ </desc>
+ </var>
+
+ <var name="isplaylist" default="audio,image">
+ <desc>
+ Make all items a playlist. So when one is finished, the
+ next one will start. It's also possible to browse through
+ the list with UP and DOWN. The value is a comma sperated
+ list of media types.
+ </desc>
+ </var>
<var name="use-metadata" default="True">
<desc>Use names from metadata and not the filename</desc>
Modified: trunk/ui/src/directory.py
==============================================================================
--- trunk/ui/src/directory.py (original)
+++ trunk/ui/src/directory.py Thu Feb 8 12:52:44 2007
@@ -61,18 +61,18 @@
# variables for 'configure' submenu
CONFIGURE = [
- ('sort_type', _('Sort By Date'),
- _('Sort directory by date and not by name.')),
+ ('sort', _('Sort'),
+ _('How to sort items.')),
('autoplay_single_item', _('Autoplay Single Item'),
_('Don\'t show directory if only one item exists and auto select the
item.')),
+ ('autoplay_items', _('Autoplay Items'),
+ _('Autoplay the whole directory (as playlist) when it contains only
files.')),
('use_metadata', _('Use Tag Names'),
_('Use the names from the media files tags as display name.')),
('sort_reverse', _('Reverse Sort'),
_('Show the items in the list in reverse order.')),
('isplaylist', _('Is Playlist'),
_('Handle the directory as playlist and play the next item when ine is
done.')) ,
- ('autoplay_items', _('Autoplay Items'),
- _('Autoplay the whole directory (as playlist) when it contains only
files.')),
('hide_played', _('Hide Played Items'),
_('Hide items already played.'))]
@@ -80,39 +80,12 @@
# get config object directory
config = config.directory
-# mapping from internal names to config file
-CONFIG_MAPPING = {
- 'sort_type': config.sort.type,
- 'autoplay_single_item': config.playlist.autoplay,
- 'use_metadata': config.use_metadata,
- 'sort_reverse': config.sort.reverse,
- 'isplaylist': config.playlist.isplaylist,
- }
-
# register to beacon as string: on/off/auto
kaa.beacon.register_file_type_attrs('dir',
freevo_num_items = (dict, kaa.beacon.ATTR_SIMPLE),
**dict([ ('freevo_' + x[0], (str, kaa.beacon.ATTR_SIMPLE)) for x in
CONFIGURE ])
)
-def smartsort(x,y):
- """
- Compares strings after stripping off 'The' and 'A' to be 'smarter'
- Also obviously ignores the full path when looking for 'The' and 'A'
- """
- m = os.path.basename(x)
- n = os.path.basename(y)
-
- for word in ('The', 'A'):
- word += ' '
- if m.find(word) == 0:
- m = m.replace(word, '', 1)
- if n.find(word) == 0:
- n = n.replace(word, '', 1)
-
- return cmp(m.upper(),n.upper()) # be case insensitive
-
-
def find_start_string(s1, s2):
"""
Find similar start in both strings
@@ -255,6 +228,7 @@
return '%d:%02d' % (length / 60, length % 60)
if key.startswith('config:'):
+
value = self.info.get('tmp:%s' % key[7:])
if value is not None:
return value
@@ -263,17 +237,17 @@
return value == 'yes'
if isinstance(self.parent, DirItem):
return self.parent[key]
- # config does not know about autoplay_items and hide_played
- value = CONFIG_MAPPING.get(key[7:], False)
- if not isinstance(value, (list, tuple)):
- if value in (1, True):
- return True
- if value in (0, False):
- return False
+ if key == 'config:sort':
+ if self.display_type == 'tv':
+ return config.tvsort
+ return config.sort
+ # config does not know about hide_played
+ value = getattr(config, key[7:], False)
+ if isinstance(value, bool):
return value
if self.display_type == 'tv':
- return 'video' in value
- return self.display_type in value
+ return 'video' in value.split(',')
+ return self.display_type in value.split(',')
return Item.__getitem__(self, key)
@@ -461,25 +435,27 @@
# sort all items
#
- # sort directories
- if config.sort.smart:
- dir_items.sort(lambda l, o: smartsort(l.dir,o.dir))
- else:
- dir_items.sort(lambda l, o: cmp(l.dir.upper(), o.dir.upper()))
+ def _sortfunc(m):
+ return lambda l, o: cmp(l.sort(m).lower(), o.sort(m).lower())
- # sort playlist
- pl_items.sort(lambda l, o: cmp(l.name.upper(), o.name.upper()))
+ # sort directories by name
+ dir_items.sort(_sortfunc('name'))
- # sort normal items
- sort_type = self['config:sort_type']
- if sort_type == 'tv-by-date' and not self.display_type == 'tv':
- sort_type = False
- if sort_type:
- play_items.sort(lambda l, o: cmp(l.sort('date').upper(),
- o.sort('date').upper()))
+ # sort playlist by name or delete if they should not be displayed
+ if self.display_type and not self.display_type in \
+ config.add_playlist_items.split(','):
+ pl_items = []
else:
- play_items.sort(lambda l, o: cmp(l.sort().upper(),
- o.sort().upper()))
+ pl_items.sort(_sortfunc('name'))
+
+ sorttype = self['config:sort']
+ play_items.sort(_sortfunc(sorttype))
+ if sorttype == 'date-new-first':
+ play_items.reverse()
+
+ #
+ # final settings
+ #
# update num_items information if needed
num_items_all = self.info.get('freevo_num_items') or {}
@@ -490,28 +466,18 @@
num_items[2] = len(dir_items)
self.info['freevo_num_items'] = copy.copy(num_items_all)
- if self['config:sort_reverse']:
- dir_items.reverse()
- play_items.reverse()
- pl_items.reverse()
-
- # delete pl_items if they should not be displayed
- if self.display_type and not self.display_type in \
- config.playlist.include:
- pl_items = []
# add all playable items to the playlist of the directory
# to play one files after the other
if self['config:isplaylist']:
self.playlist = play_items
-
# build a list of all items
items = dir_items + pl_items + play_items
# random playlist (only active for audio)
if self.display_type and self.display_type in \
- config.playlist.random and len(play_items) > 1:
+ config.add_random_playlist and len(play_items) > 1:
pl = Playlist(_('Random playlist'), play_items, self,
random=True)
pl.autoplay = True
Modified: trunk/ui/src/fxditem.py
==============================================================================
--- trunk/ui/src/fxditem.py (original)
+++ trunk/ui/src/fxditem.py Thu Feb 8 12:52:44 2007
@@ -146,15 +146,6 @@
self.display_type = parent.display_type
- def sort(self, mode=None):
- """
- Returns the string how to sort this item
- """
- if mode == 'date':
- return '0'
- return self.name
-
-
def actions(self):
"""
actions for this item
Modified: trunk/ui/src/menu/item.py
==============================================================================
--- trunk/ui/src/menu/item.py (original)
+++ trunk/ui/src/menu/item.py Thu Feb 8 12:52:44 2007
@@ -132,9 +132,19 @@
"""
Returns the string how to sort this item
"""
- return u'0%s' % self.name
-
+ if mode == 'name':
+ return self.name
+ if mode == 'smart':
+ name = self.name
+ if name.lower().startswith('the '):
+ return name[4:]
+ if name.lower().startswith('a '):
+ return name[2:]
+ return name
+ print 'oops', mode, self
+ return ''
+
def actions(self):
"""
Returns a list of possible actions on this item. The first
Modified: trunk/ui/src/menu/mediaitem.py
==============================================================================
--- trunk/ui/src/menu/mediaitem.py (original)
+++ trunk/ui/src/menu/mediaitem.py Thu Feb 8 12:52:44 2007
@@ -193,11 +193,15 @@
"""
Returns the string how to sort this item
"""
- if mode == 'date' and self.filename:
- uf = unicode(self.filename, errors = 'replace')
- return u'%s%s' % (os.stat(self.filename).st_ctime, uf)
-
- return u'0%s' % self.name
+ if mode == 'date':
+ if self.filename:
+ return u'%s%s' % (os.stat(self.filename).st_ctime, self.name)
+ return u'0%s' % self.name
+ if mode == 'filename':
+ if self.filename:
+ return unicode(self.filename, errors = 'replace')
+ return self.name
+ return Item.sort(self, mode)
def cache(self):
Modified: trunk/ui/src/video/videoitem.py
==============================================================================
--- trunk/ui/src/video/videoitem.py (original)
+++ trunk/ui/src/video/videoitem.py Thu Feb 8 12:52:44 2007
@@ -98,16 +98,10 @@
show_name = None
self.tv_show = False
- if self.name.find(u"The ") == 0:
- self.sort_name = self.name[4:]
- self.sort_name = self.name
-
if self.info['episode'] and self.info['subtitle']:
# get informations for recordings
show_name = (self.name, '', self.info['episode'], \
self.info['subtitle'])
- self.sort_name += u' ' + self.info['episode'] + u' ' + \
- self.info['subtitle']
elif VIDEO_SHOW_REGEXP_MATCH(self.name) and not self.network_play:
# split tv show files based on regexp
show_name = VIDEO_SHOW_REGEXP_SPLIT(self.name)
@@ -130,8 +124,6 @@
self.show_name = show_name
self.tv_show_name = show_name[0]
self.tv_show_ep = show_name[3]
- if self.mode == 'file' and os.path.isfile(self.filename):
- self.sort_name += u' ' +
str_to_unicode(str(os.stat(self.filename).st_ctime))
def set_url(self, url):
@@ -237,17 +229,6 @@
return MediaItem.__getitem__(self, key)
- def sort(self, mode=None):
- """
- Returns the string how to sort this item
- """
- if mode == 'date' and self.mode == 'file' and \
- os.path.isfile(self.filename):
- return u'%s%s' % (os.stat(self.filename).st_ctime,
- str_to_unicode(self.filename))
- return self.sort_name
-
-
def __set_next_available_subitem(self):
"""
select the next available subitem. Loops on each subitem and checks if
-------------------------------------------------------------------------
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