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

This commit is contained in:
James 2012-08-08 15:29:28 -04:00
commit ab19d6f511
5 changed files with 118 additions and 66 deletions
airtime_mvc
application/views/scripts/library
public
css
js/airtime
python_apps/media-monitor/airtimefilemonitor

View File

@ -84,10 +84,13 @@
if (strlen($crit["display_name"]) > $critMaxStrLen) {
$crit["display_name"] = substr($crit["display_name"], 0, 12)."...";
}
if (strlen($crit["modifier"]) > $critMaxStrLen) {
$crit["modifier"] = substr($crit["modifier"], 0, 12)."...";
}
?>
<tr>
<td class='file-md-qtip-criteria-width-crit file-md-qtip-nowrap'><?php echo $crit["display_name"] ?></td>
<td class='file-md-qtip-criteria-width-mod'><?php echo $crit["modifier"] ?></td>
<td class='file-md-qtip-criteria-width-mod file-md-qtip-nowrap'><?php echo $crit["modifier"] ?></td>
<td class='file-md-qtip-criteria-width file-md-qtip-nowrap'><?php echo $crit["value"] ?>
<?php if (isset($crit["extra"])) { ?>
to <?php echo $crit["extra"] ?></td>

View File

@ -451,7 +451,7 @@ table.library-get-file-md.table-small{
}
.file-md-qtip-criteria-width-mod{
width:60px;
width:70px;
}
.file-md-qtip-criteria-width{

View File

@ -341,6 +341,7 @@ var AIRTIME = (function(AIRTIME){
// functions in smart_playlistbuilder.js
setupUI();
appendAddButton();
appendModAddButton();
removeButtonCheck();
}

View File

@ -17,6 +17,7 @@ function setSmartPlaylistEvents() {
$(this).hide();
}
appendAddButton();
appendModAddButton();
removeButtonCheck();
});
@ -87,6 +88,8 @@ function setSmartPlaylistEvents() {
var count = list_length - curr_pos;
var next = curr.next();
var item_to_hide;
var prev;
var index;
//remove error message from current row, if any
var error_element = curr.find('span[class="errors sp-errors"]');
@ -94,10 +97,13 @@ function setSmartPlaylistEvents() {
error_element.remove();
}
/* assign next row to current row for all rows below and including
* the row getting removed
*/
for (var i=0; i<count; i++) {
/* assign next row to current row for all rows below and including
* the row getting removed
*/
for (var i=0; i<count; i++) {
index = getRowIndex(curr);
var criteria = next.find('[name^="sp_criteria_field"]').val();
curr.find('[name^="sp_criteria_field"]').val(criteria);
@ -107,12 +113,6 @@ function setSmartPlaylistEvents() {
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
curr.find('[name^="sp_criteria_value"]').val(criteria_value);
var id = curr.find('[name^="sp_criteria"]').attr('id'),
delimiter = '_',
start = 3,
tokens = id.split(delimiter).slice(start),
index = tokens.join(delimiter);
/* if current and next row have the extra criteria value
* (for 'is in the range' modifier), then assign the next
@ -143,16 +143,34 @@ function setSmartPlaylistEvents() {
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
}
/* determine if current row is a modifier row
* if it is, make the criteria select invisible
*/
prev = curr.prev();
if (curr.find('[name^="sp_criteria_field"]').val() == prev.find('[name^="sp_criteria_field"]').val()) {
if (!curr.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
curr.find('select[name^="sp_criteria_field"]').addClass('sp-invisible');
}
} else {
if (curr.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
curr.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible');
}
}
curr = next;
next = curr.next();
}
/* Disable the last visible row since it holds the values the user removed
* Reset the values to empty and resize the criteria value textbox
* in case the row had the extra criteria textbox
*/
item_to_hide = list.find('div:visible:last');
item_to_hide.children().attr('disabled', 'disabled');
if (item_to_hide.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
item_to_hide.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible');
}
item_to_hide.find('[name^="sp_criteria_field"]').val(0).end()
.find('[name^="sp_criteria_modifier"]').val(0).end()
.find('[name^="sp_criteria_value"]').val('').end()
@ -163,12 +181,22 @@ function setSmartPlaylistEvents() {
list.next().show();
//check if last row is a modifier row
var last_row = list.find('div:visible:last');
if (last_row.find('[name^="sp_criteria_field"]').val() == last_row.prev().find('[name^="sp_criteria_field"]').val()) {
if (!last_row.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
last_row.find('select[name^="sp_criteria_field"]').addClass('sp-invisible');
}
}
// always put '+' button on the last enabled row
appendAddButton();
reindexElements();
// always put '+' button on the last modifier row
appendModAddButton();
reindexElements();
// remove the 'x' button if only one row is enabled
removeButtonCheck();
});
@ -247,13 +275,15 @@ function setSmartPlaylistEvents() {
removeButtonCheck();
}
var static_length = $('.playlist_title').children('h4[id$="_length"]').text();
/*
function setStaticLengthHolder(lenVal) {
static_length = lenVal;
function getRowIndex(ele) {
var id = ele.find('[name^="sp_criteria"]').attr('id'),
delimiter = '_',
start = 3,
tokens = id.split(delimiter).slice(start),
index = tokens.join(delimiter);
return index;
}
*/
function setFadeIcon(){
var contents = $("#spl_sortable");
@ -350,12 +380,10 @@ function setupUI() {
$('button[id="generate_button"]').show();
$('button[id="shuffle_button"]').show();
$('#spl_sortable').show();
//$('.playlist_title').children('h4[id$="_length"]').text(static_length);
} else {
$('button[id="generate_button"]').hide();
$('button[id="shuffle_button"]').hide();
$('#spl_sortable').hide();
//$('.playlist_title').children('h4[id$="_length"]').text(dynamic_length);
}
}
@ -412,26 +440,27 @@ function sizeTextBoxes(ele, classToRemove, classToAdd) {
}
function populateModifierSelect(e) {
/*var criteria = $(e).val(),
criteria_type = criteriaTypes[criteria],*/
var criteria_type = getCriteriaOptionType(e),
div = $(e).siblings('select[id^="sp_criteria_modifier"]');
index = getRowIndex($(e).parent()),
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+index+'"]');
div.children().remove();
if (criteria_type == 's') {
$.each(stringCriteriaOptions, function(key, value){
div.append($('<option></option>')
.attr('value', key)
.text(value));
});
} else {
$.each(numericCriteriaOptions, function(key, value){
div.append($('<option></option>')
.attr('value', key)
.text(value));
});
}
$.each(divs, function(i, div){
$(div).children().remove();
if (criteria_type == 's') {
$.each(stringCriteriaOptions, function(key, value){
$(div).append($('<option></option>')
.attr('value', key)
.text(value));
});
} else {
$.each(numericCriteriaOptions, function(key, value){
$(div).append($('<option></option>')
.attr('value', key)
.text(value));
});
}
});
}
function getCriteriaOptionType(e) {

View File

@ -40,7 +40,7 @@ def duplicate_file(file_path):
fsrc = open(file_path, 'r')
fdst = tempfile.NamedTemporaryFile(delete=False)
print "Copying %s to %s" % (file_path, fdst.name)
logger.info("Copying %s to %s" % (file_path, fdst.name))
shutil.copyfileobj(fsrc, fdst)
@ -49,6 +49,26 @@ def duplicate_file(file_path):
return fdst.name
def get_file_type(file_path):
file_type = None
if re.search(r'mp3$', file_path, re.IGNORECASE):
file_type = 'mp3'
elif re.search(r'og(g|a)$', file_path, re.IGNORECASE):
file_type = 'vorbis'
elif re.search(r'flac$', file_path, re.IGNORECASE):
file_type = 'flac'
else:
mime_type = get_mime_type(file_path) == "audio/mpeg"
if 'mpeg' in mime_type:
file_type = 'mp3'
elif 'ogg' in mime_type:
file_type = 'vorbis'
elif 'flac' in mime_type:
file_type = 'flac'
return file_type
def calculate_replay_gain(file_path):
"""
This function accepts files of type mp3/ogg/flac and returns a calculated ReplayGain value in dB.
@ -66,36 +86,35 @@ def calculate_replay_gain(file_path):
search = None
temp_file_path = duplicate_file(file_path)
if re.search(r'mp3$', file_path, re.IGNORECASE) or get_mime_type(temp_file_path) == "audio/mpeg":
if run_process("which mp3gain > /dev/null") == 0:
out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path)
search = re.search(r'Recommended "Track" dB change: (.*)', out)
file_type = get_file_type(file_path)
if file_type:
if file_type == 'mp3':
if run_process("which mp3gain > /dev/null") == 0:
out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path)
search = re.search(r'Recommended "Track" dB change: (.*)', out)
else:
logger.warn("mp3gain not found")
elif file_type == 'vorbis':
if run_process("which vorbisgain > /dev/null && which ogginfo > /dev/null") == 0:
run_process('vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % temp_file_path)
out = get_process_output('ogginfo "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else:
logger.warn("vorbisgain/ogginfo not found")
elif file_type == 'flac':
if run_process("which metaflac > /dev/null") == 0:
out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else:
logger.warn("metaflac not found")
else:
print "mp3gain not found"
#Log warning
elif re.search(r'og(g|a)$', file_path, re.IGNORECASE) or get_mime_type(temp_file_path) == "application/ogg":
if run_process("which vorbisgain > /dev/null && which ogginfo > /dev/null") == 0:
run_process('vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % temp_file_path)
out = get_process_output('ogginfo "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else:
print "vorbisgain/ogginfo not found"
#Log warning
elif re.search(r'flac$', file_path, re.IGNORECASE) or get_mime_type(temp_file_path) == "audio/x-flac":
if run_process("which metaflac > /dev/null") == 0:
out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else:
print "metaflac not found"
#Log warning
else:
pass
#Log unknown file type.
pass
#no longer need the temp, file simply remove it.
os.remove(temp_file_path)
except Exception, e:
print e
logger.error(str(e))
replay_gain = 0
if search: