Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
ab19d6f511
|
@ -84,10 +84,13 @@
|
||||||
if (strlen($crit["display_name"]) > $critMaxStrLen) {
|
if (strlen($crit["display_name"]) > $critMaxStrLen) {
|
||||||
$crit["display_name"] = substr($crit["display_name"], 0, 12)."...";
|
$crit["display_name"] = substr($crit["display_name"], 0, 12)."...";
|
||||||
}
|
}
|
||||||
|
if (strlen($crit["modifier"]) > $critMaxStrLen) {
|
||||||
|
$crit["modifier"] = substr($crit["modifier"], 0, 12)."...";
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<tr>
|
<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-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"] ?>
|
<td class='file-md-qtip-criteria-width file-md-qtip-nowrap'><?php echo $crit["value"] ?>
|
||||||
<?php if (isset($crit["extra"])) { ?>
|
<?php if (isset($crit["extra"])) { ?>
|
||||||
to <?php echo $crit["extra"] ?></td>
|
to <?php echo $crit["extra"] ?></td>
|
||||||
|
|
|
@ -451,7 +451,7 @@ table.library-get-file-md.table-small{
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-md-qtip-criteria-width-mod{
|
.file-md-qtip-criteria-width-mod{
|
||||||
width:60px;
|
width:70px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-md-qtip-criteria-width{
|
.file-md-qtip-criteria-width{
|
||||||
|
|
|
@ -341,6 +341,7 @@ var AIRTIME = (function(AIRTIME){
|
||||||
// functions in smart_playlistbuilder.js
|
// functions in smart_playlistbuilder.js
|
||||||
setupUI();
|
setupUI();
|
||||||
appendAddButton();
|
appendAddButton();
|
||||||
|
appendModAddButton();
|
||||||
removeButtonCheck();
|
removeButtonCheck();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ function setSmartPlaylistEvents() {
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
}
|
}
|
||||||
appendAddButton();
|
appendAddButton();
|
||||||
|
appendModAddButton();
|
||||||
removeButtonCheck();
|
removeButtonCheck();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -87,6 +88,8 @@ function setSmartPlaylistEvents() {
|
||||||
var count = list_length - curr_pos;
|
var count = list_length - curr_pos;
|
||||||
var next = curr.next();
|
var next = curr.next();
|
||||||
var item_to_hide;
|
var item_to_hide;
|
||||||
|
var prev;
|
||||||
|
var index;
|
||||||
|
|
||||||
//remove error message from current row, if any
|
//remove error message from current row, if any
|
||||||
var error_element = curr.find('span[class="errors sp-errors"]');
|
var error_element = curr.find('span[class="errors sp-errors"]');
|
||||||
|
@ -94,10 +97,13 @@ function setSmartPlaylistEvents() {
|
||||||
error_element.remove();
|
error_element.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assign next row to current row for all rows below and including
|
/* assign next row to current row for all rows below and including
|
||||||
* the row getting removed
|
* the row getting removed
|
||||||
*/
|
*/
|
||||||
for (var i=0; i<count; i++) {
|
for (var i=0; i<count; i++) {
|
||||||
|
|
||||||
|
index = getRowIndex(curr);
|
||||||
|
|
||||||
var criteria = next.find('[name^="sp_criteria_field"]').val();
|
var criteria = next.find('[name^="sp_criteria_field"]').val();
|
||||||
curr.find('[name^="sp_criteria_field"]').val(criteria);
|
curr.find('[name^="sp_criteria_field"]').val(criteria);
|
||||||
|
|
||||||
|
@ -107,12 +113,6 @@ function setSmartPlaylistEvents() {
|
||||||
|
|
||||||
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
|
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
|
||||||
curr.find('[name^="sp_criteria_value"]').val(criteria_value);
|
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
|
/* if current and next row have the extra criteria value
|
||||||
* (for 'is in the range' modifier), then assign the next
|
* (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);
|
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;
|
curr = next;
|
||||||
next = curr.next();
|
next = curr.next();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable the last visible row since it holds the values the user removed
|
/* Disable the last visible row since it holds the values the user removed
|
||||||
* Reset the values to empty and resize the criteria value textbox
|
* Reset the values to empty and resize the criteria value textbox
|
||||||
* in case the row had the extra criteria textbox
|
* in case the row had the extra criteria textbox
|
||||||
*/
|
*/
|
||||||
item_to_hide = list.find('div:visible:last');
|
item_to_hide = list.find('div:visible:last');
|
||||||
item_to_hide.children().attr('disabled', 'disabled');
|
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()
|
item_to_hide.find('[name^="sp_criteria_field"]').val(0).end()
|
||||||
.find('[name^="sp_criteria_modifier"]').val(0).end()
|
.find('[name^="sp_criteria_modifier"]').val(0).end()
|
||||||
.find('[name^="sp_criteria_value"]').val('').end()
|
.find('[name^="sp_criteria_value"]').val('').end()
|
||||||
|
@ -163,12 +181,22 @@ function setSmartPlaylistEvents() {
|
||||||
|
|
||||||
list.next().show();
|
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
|
// always put '+' button on the last enabled row
|
||||||
appendAddButton();
|
appendAddButton();
|
||||||
|
|
||||||
|
reindexElements();
|
||||||
|
|
||||||
// always put '+' button on the last modifier row
|
// always put '+' button on the last modifier row
|
||||||
appendModAddButton();
|
appendModAddButton();
|
||||||
|
|
||||||
reindexElements();
|
|
||||||
// remove the 'x' button if only one row is enabled
|
// remove the 'x' button if only one row is enabled
|
||||||
removeButtonCheck();
|
removeButtonCheck();
|
||||||
});
|
});
|
||||||
|
@ -247,13 +275,15 @@ function setSmartPlaylistEvents() {
|
||||||
removeButtonCheck();
|
removeButtonCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
var static_length = $('.playlist_title').children('h4[id$="_length"]').text();
|
function getRowIndex(ele) {
|
||||||
|
var id = ele.find('[name^="sp_criteria"]').attr('id'),
|
||||||
/*
|
delimiter = '_',
|
||||||
function setStaticLengthHolder(lenVal) {
|
start = 3,
|
||||||
static_length = lenVal;
|
tokens = id.split(delimiter).slice(start),
|
||||||
|
index = tokens.join(delimiter);
|
||||||
|
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
function setFadeIcon(){
|
function setFadeIcon(){
|
||||||
var contents = $("#spl_sortable");
|
var contents = $("#spl_sortable");
|
||||||
|
@ -350,12 +380,10 @@ function setupUI() {
|
||||||
$('button[id="generate_button"]').show();
|
$('button[id="generate_button"]').show();
|
||||||
$('button[id="shuffle_button"]').show();
|
$('button[id="shuffle_button"]').show();
|
||||||
$('#spl_sortable').show();
|
$('#spl_sortable').show();
|
||||||
//$('.playlist_title').children('h4[id$="_length"]').text(static_length);
|
|
||||||
} else {
|
} else {
|
||||||
$('button[id="generate_button"]').hide();
|
$('button[id="generate_button"]').hide();
|
||||||
$('button[id="shuffle_button"]').hide();
|
$('button[id="shuffle_button"]').hide();
|
||||||
$('#spl_sortable').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) {
|
function populateModifierSelect(e) {
|
||||||
/*var criteria = $(e).val(),
|
|
||||||
criteria_type = criteriaTypes[criteria],*/
|
|
||||||
var criteria_type = getCriteriaOptionType(e),
|
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();
|
$.each(divs, function(i, div){
|
||||||
|
$(div).children().remove();
|
||||||
if (criteria_type == 's') {
|
|
||||||
$.each(stringCriteriaOptions, function(key, value){
|
if (criteria_type == 's') {
|
||||||
div.append($('<option></option>')
|
$.each(stringCriteriaOptions, function(key, value){
|
||||||
.attr('value', key)
|
$(div).append($('<option></option>')
|
||||||
.text(value));
|
.attr('value', key)
|
||||||
});
|
.text(value));
|
||||||
} else {
|
});
|
||||||
$.each(numericCriteriaOptions, function(key, value){
|
} else {
|
||||||
div.append($('<option></option>')
|
$.each(numericCriteriaOptions, function(key, value){
|
||||||
.attr('value', key)
|
$(div).append($('<option></option>')
|
||||||
.text(value));
|
.attr('value', key)
|
||||||
});
|
.text(value));
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCriteriaOptionType(e) {
|
function getCriteriaOptionType(e) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ def duplicate_file(file_path):
|
||||||
fsrc = open(file_path, 'r')
|
fsrc = open(file_path, 'r')
|
||||||
fdst = tempfile.NamedTemporaryFile(delete=False)
|
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)
|
shutil.copyfileobj(fsrc, fdst)
|
||||||
|
|
||||||
|
@ -49,6 +49,26 @@ def duplicate_file(file_path):
|
||||||
|
|
||||||
return fdst.name
|
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):
|
def calculate_replay_gain(file_path):
|
||||||
"""
|
"""
|
||||||
This function accepts files of type mp3/ogg/flac and returns a calculated ReplayGain value in dB.
|
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
|
search = None
|
||||||
temp_file_path = duplicate_file(file_path)
|
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":
|
file_type = get_file_type(file_path)
|
||||||
if run_process("which mp3gain > /dev/null") == 0:
|
|
||||||
out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path)
|
if file_type:
|
||||||
search = re.search(r'Recommended "Track" dB change: (.*)', out)
|
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:
|
else:
|
||||||
print "mp3gain not found"
|
pass
|
||||||
#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.
|
|
||||||
|
|
||||||
#no longer need the temp, file simply remove it.
|
#no longer need the temp, file simply remove it.
|
||||||
os.remove(temp_file_path)
|
os.remove(temp_file_path)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
logger.error(str(e))
|
||||||
|
|
||||||
replay_gain = 0
|
replay_gain = 0
|
||||||
if search:
|
if search:
|
||||||
|
|
Loading…
Reference in New Issue