Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Martin Konecny 2012-08-17 15:41:53 -04:00
commit 99a3f6ba0c
4 changed files with 40 additions and 24 deletions

View File

@ -90,7 +90,7 @@ function setSmartPlaylistEvents() {
curr.find('[name^="sp_criteria_field"]').val(criteria); curr.find('[name^="sp_criteria_field"]').val(criteria);
var modifier = next.find('[name^="sp_criteria_modifier"]').val(); var modifier = next.find('[name^="sp_criteria_modifier"]').val();
populateModifierSelect(curr.find('[name^="sp_criteria_field"]')); populateModifierSelect(curr.find('[name^="sp_criteria_field"]'), false);
curr.find('[name^="sp_criteria_modifier"]').val(modifier); curr.find('[name^="sp_criteria_modifier"]').val(modifier);
var criteria_value = next.find('[name^="sp_criteria_value"]').val(); var criteria_value = next.find('[name^="sp_criteria_value"]').val();
@ -208,7 +208,7 @@ function setSmartPlaylistEvents() {
// disable extra field and hide the span // disable extra field and hide the span
disableAndHideExtraField($(this), index_num); disableAndHideExtraField($(this), index_num);
populateModifierSelect(this); populateModifierSelect(this, true);
}); });
/********** MODIFIER CHANGE **********/ /********** MODIFIER CHANGE **********/
@ -329,9 +329,20 @@ function setupUI() {
if (shuffleButton.hasClass('ui-state-disabled')) { if (shuffleButton.hasClass('ui-state-disabled')) {
shuffleButton.removeClass('ui-state-disabled'); shuffleButton.removeClass('ui-state-disabled');
} }
shuffleButton.live('click', function(){ //check if shuffle button already has a click event
buttonClickAction('shuffle', 'Playlist/smart-block-shuffle'); var clickEvents = $(document).data('events').click;
var hasEvent = false;
$.each(clickEvents, function(i, event) {
if (event.selector == shuffleButton.selector) {
hasEvent = true;
return false;
}
}); });
if (!hasEvent) {
shuffleButton.live('click', function(){
buttonClickAction('shuffle', 'Playlist/smart-block-shuffle');
});
}
} else if (!shuffleButton.hasClass('ui-state-disabled')) { } else if (!shuffleButton.hasClass('ui-state-disabled')) {
shuffleButton.addClass('ui-state-disabled'); shuffleButton.addClass('ui-state-disabled');
shuffleButton.die('click'); shuffleButton.die('click');
@ -402,12 +413,16 @@ function sizeTextBoxes(ele, classToRemove, classToAdd) {
} }
} }
function populateModifierSelect(e) { function populateModifierSelect(e, popAllMods) {
var criteria_type = getCriteriaOptionType(e), var criteria_type = getCriteriaOptionType(e),
index = getRowIndex($(e).parent()), index = getRowIndex($(e).parent()),
critIndex = index.substring(0, 1), divs;
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+critIndex+'"]');
if (popAllMods) {
index = index.substring(0, 1);
}
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+index+'"]');
$.each(divs, function(i, div){ $.each(divs, function(i, div){
$(div).children().remove(); $(div).children().remove();

View File

@ -121,10 +121,10 @@ class Metadata(Loggable):
def __init__(self, fpath): def __init__(self, fpath):
# Forcing the unicode through # Forcing the unicode through
try: fpath = fpath.decode("utf-8") try : fpath = fpath.decode("utf-8")
except: pass except : pass
try: full_mutagen = mutagen.File(fpath, easy=True) try : full_mutagen = mutagen.File(fpath, easy=True)
except Exception: raise BadSongFile(fpath) except Exception : raise BadSongFile(fpath)
self.path = fpath self.path = fpath
# TODO : Simplify the way all of these rules are handled right not it's # TODO : Simplify the way all of these rules are handled right not it's
# extremely unclear and needs to be refactored. # extremely unclear and needs to be refactored.
@ -162,6 +162,8 @@ class Metadata(Loggable):
# Finally, we "normalize" all the metadata here: # Finally, we "normalize" all the metadata here:
self.__metadata = mmp.normalized_metadata(self.__metadata, fpath) self.__metadata = mmp.normalized_metadata(self.__metadata, fpath)
# Now we must load the md5: # Now we must load the md5:
# TODO : perhaps we shouldn't hard code how many bytes we're reading
# from the file?
self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100) self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100)
def is_recorded(self): def is_recorded(self):

View File

@ -163,11 +163,13 @@ def apply_rules_dict(d, rules):
""" """
Consumes a dictionary of rules that maps some keys to lambdas which it Consumes a dictionary of rules that maps some keys to lambdas which it
applies to every matching element in d and returns a new dictionary with applies to every matching element in d and returns a new dictionary with
the rules applied the rules applied. If a rule returns none then it's not applied
""" """
new_d = copy.deepcopy(d) new_d = copy.deepcopy(d)
for k, rule in rules.iteritems(): for k, rule in rules.iteritems():
if k in d: new_d[k] = rule(d[k]) if k in d:
new_val = rule(d[k])
if new_val is not None: new_d[k] = new_val
return new_d return new_d
def default_to_f(dictionary, keys, default, condition): def default_to_f(dictionary, keys, default, condition):
@ -183,10 +185,6 @@ def default_to(dictionary, keys, default):
""" """
cnd = lambda dictionary, key: key not in dictionary cnd = lambda dictionary, key: key not in dictionary
return default_to_f(dictionary, keys, default, cnd) return default_to_f(dictionary, keys, default, cnd)
#new_d = copy.deepcopy(dictionary)
#for k in keys:
#if not (k in new_d): new_d[k] = default
#return new_d
def remove_whitespace(dictionary): def remove_whitespace(dictionary):
""" """
@ -205,18 +203,18 @@ def remove_whitespace(dictionary):
def parse_int(s): def parse_int(s):
""" """
Tries very hard to get some sort of integer result from s. Defaults to 0 Tries very hard to get some sort of integer result from s. Defaults to 0
when it failes when it fails
>>> parse_int("123") >>> parse_int("123")
'123' '123'
>>> parse_int("123saf") >>> parse_int("123saf")
'123' '123'
>>> parse_int("asdf") >>> parse_int("asdf")
'' None
""" """
if s.isdigit(): return s if s.isdigit(): return s
else: else:
try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s))) try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s)))
except: return '' except: return None
def normalized_metadata(md, original_path): def normalized_metadata(md, original_path):
""" """
@ -240,7 +238,8 @@ def normalized_metadata(md, original_path):
new_md = apply_rules_dict(new_md, format_rules) new_md = apply_rules_dict(new_md, format_rules)
new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'], new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'],
default=no_extension_basename(original_path)) default=no_extension_basename(original_path))
new_md = default_to(dictionary=new_md, keys=path_md, default=u'') new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_CREATOR',
'MDATA_KEY_SOURCE'], default=u'')
new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'], new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'],
default=u'audioclip') default=u'audioclip')
# In the case where the creator is 'Airtime Show Recorder' we would like to # In the case where the creator is 'Airtime Show Recorder' we would like to

View File

@ -48,7 +48,7 @@ class TestMMP(unittest.TestCase):
real_path1 = \ real_path1 = \
u'/home/rudi/throwaway/fucking_around/watch/unknown/unknown/ACDC_-_Back_In_Black-sample-64kbps-64kbps.ogg' u'/home/rudi/throwaway/fucking_around/watch/unknown/unknown/ACDC_-_Back_In_Black-sample-64kbps-64kbps.ogg'
self.assertTrue( 'unknown' in og, True ) self.assertTrue( 'unknown' in og, True )
self.assertEqual( og, real_path1 ) self.assertEqual( og, real_path1 ) # TODO : fix this failure
# for recorded it should be something like this # for recorded it should be something like this
# ./recorded/2012/07/2012-07-09-17-55-00-Untitled Show-256kbps.ogg # ./recorded/2012/07/2012-07-09-17-55-00-Untitled Show-256kbps.ogg
@ -70,6 +70,6 @@ class TestMMP(unittest.TestCase):
def test_parse_int(self): def test_parse_int(self):
self.assertEqual( mmp.parse_int("123"), "123" ) self.assertEqual( mmp.parse_int("123"), "123" )
self.assertEqual( mmp.parse_int("123asf"), "123" ) self.assertEqual( mmp.parse_int("123asf"), "123" )
self.assertEqual( mmp.parse_int("asdf"), "" ) self.assertEqual( mmp.parse_int("asdf"), None )
if __name__ == '__main__': unittest.main() if __name__ == '__main__': unittest.main()