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

This commit is contained in:
Martin Konecny 2012-08-31 17:21:48 -04:00
commit 886888a958
7 changed files with 102 additions and 74 deletions

View file

@ -39,9 +39,11 @@ class Application_Model_Datatables
/* /*
* query used to return data for a paginated/searchable datatable. * query used to return data for a paginated/searchable datatable.
*/ */
public static function findEntries($con, $displayColumns, $fromTable, $data, $dataProp = "aaData") public static function findEntries($con, $displayColumns, $fromTable,
$data, $dataProp = "aaData")
{ {
$librarySetting = Application_Model_Preference::getCurrentLibraryTableSetting(); $librarySetting = Application_Model_Preference::getCurrentLibraryTableSetting();
//$displayColumns[] = 'owner';
// map that maps original column position to db name // map that maps original column position to db name
$current2dbname = array(); $current2dbname = array();
@ -82,6 +84,7 @@ class Application_Model_Datatables
$sql = $selectorCount." FROM ".$fromTable; $sql = $selectorCount." FROM ".$fromTable;
$sqlTotalRows = $sql; $sqlTotalRows = $sql;
if (isset($searchTerms)) { if (isset($searchTerms)) {
$searchCols = array(); $searchCols = array();
for ($i = 0; $i < $data["iColumns"]; $i++) { for ($i = 0; $i < $data["iColumns"]; $i++) {
@ -135,8 +138,8 @@ class Application_Model_Datatables
$sql .= " OFFSET ".$data["iDisplayStart"]." LIMIT ".$displayLength; $sql .= " OFFSET ".$data["iDisplayStart"]." LIMIT ".$displayLength;
} }
} }
try { try {
$r = $con->query($sqlTotalRows); $r = $con->query($sqlTotalRows);
$totalRows = $r->fetchColumn(0); $totalRows = $r->fetchColumn(0);
@ -173,7 +176,6 @@ class Application_Model_Datatables
} catch (Exception $e) { } catch (Exception $e) {
Logging::debug($e->getMessage()); Logging::debug($e->getMessage());
} }
return array( return array(
"sEcho" => intval($data["sEcho"]), "sEcho" => intval($data["sEcho"]),
"iTotalDisplayRecords" => intval($totalDisplayRows), "iTotalDisplayRecords" => intval($totalDisplayRows),

View file

@ -635,9 +635,11 @@ class Application_Model_StoredFile
$displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length", $displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length",
"year", "utime", "mtime", "ftype", "track_number", "mood", "bpm", "composer", "info_url", "year", "utime", "mtime", "ftype", "track_number", "mood", "bpm", "composer", "info_url",
"bit_rate", "sample_rate", "isrc_number", "encoded_by", "label", "copyright", "mime", "bit_rate", "sample_rate", "isrc_number", "encoded_by", "label", "copyright", "mime",
"language", "filepath" "language", "filepath","owner"
); );
//Logging::info($datatables);
$plSelect = array(); $plSelect = array();
$blSelect = array(); $blSelect = array();
$fileSelect = array(); $fileSelect = array();
@ -647,7 +649,7 @@ class Application_Model_StoredFile
if ($key === "id") { if ($key === "id") {
$plSelect[] = "PL.id AS ".$key; $plSelect[] = "PL.id AS ".$key;
$blSelect[] = "BL.id AS ".$key; $blSelect[] = "BL.id AS ".$key;
$fileSelect[] = $key; $fileSelect[] = "FILES.id AS $key";
$streamSelect[] = "ws.id AS ".$key; $streamSelect[] = "ws.id AS ".$key;
} elseif ($key === "track_title") { } elseif ($key === "track_title") {
$plSelect[] = "name AS ".$key; $plSelect[] = "name AS ".$key;
@ -664,6 +666,11 @@ class Application_Model_StoredFile
$blSelect[] = "login AS ".$key; $blSelect[] = "login AS ".$key;
$fileSelect[] = $key; $fileSelect[] = $key;
$streamSelect[] = "login AS ".$key; $streamSelect[] = "login AS ".$key;
} elseif ($key === "owner") {
$plSelect[] = "login AS ".$key;
$blSelect[] = "login AS ".$key;
$fileSelect[] = "sub.login AS $key";
$streamSelect[] = "login AS ".$key;
} }
//same columns in each table. //same columns in each table.
else if (in_array($key, array("length", "utime", "mtime"))) { else if (in_array($key, array("length", "utime", "mtime"))) {
@ -705,7 +712,8 @@ class Application_Model_StoredFile
$plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))"; $plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))";
$blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))"; $blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))";
$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')"; $fileTable = "({$fileSelect} FROM cc_files AS FILES LEFT JOIN cc_subjs AS sub ON (sub.id = FILES.owner_id) WHERE file_exists = 'TRUE')";
//$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
$streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))"; $streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))";
$unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS"; $unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS";

View file

@ -410,7 +410,8 @@ var AIRTIME = (function(AIRTIME) {
/* Label */ { "sTitle" : "Label" , "mDataProp" : "label" , "bVisible" : false , "sClass" : "library_label" , "sWidth" : "125px" } , /* Label */ { "sTitle" : "Label" , "mDataProp" : "label" , "bVisible" : false , "sClass" : "library_label" , "sWidth" : "125px" } ,
/* Copyright */ { "sTitle" : "Copyright" , "mDataProp" : "copyright" , "bVisible" : false , "sClass" : "library_copyright" , "sWidth" : "125px" } , /* Copyright */ { "sTitle" : "Copyright" , "mDataProp" : "copyright" , "bVisible" : false , "sClass" : "library_copyright" , "sWidth" : "125px" } ,
/* Mime */ { "sTitle" : "Mime" , "mDataProp" : "mime" , "bVisible" : false , "sClass" : "library_mime" , "sWidth" : "80px" } , /* Mime */ { "sTitle" : "Mime" , "mDataProp" : "mime" , "bVisible" : false , "sClass" : "library_mime" , "sWidth" : "80px" } ,
/* Language */ {"sTitle": "Language", "mDataProp": "language", "bVisible": false, "sClass": "library_language", "sWidth": "125px"} /* Language */ { "sTitle" : "Language" , "mDataProp" : "language" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" } ,
/* Owner */ { "sTitle" : "Owner" , "mDataProp" : "owner" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }
], ],
"bProcessing": true, "bProcessing": true,

View file

@ -161,6 +161,7 @@ class Metadata(Loggable):
# Forcing the unicode through # Forcing the unicode through
try : fpath = fpath.decode("utf-8") try : fpath = fpath.decode("utf-8")
except : pass except : pass
if not mmp.file_playable(fpath): raise BadSongFile(fpath)
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

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import copy import copy
import subprocess
import os import os
import shutil import shutil
import re import re
@ -449,6 +450,21 @@ def owner_id(original_path):
except Exception: raise except Exception: raise
return owner_id return owner_id
def file_playable(pathname):
#when there is an single apostrophe inside of a string quoted by
#apostrophes, we can only escape it by replace that apostrophe with '\''.
#This breaks the string into two, and inserts an escaped single quote in
#between them. We run the command as pypo because otherwise the target file
#is opened with write permissions, and this causes an inotify ON_CLOSE_WRITE
#event to be fired :/
command = ("sudo -u pypo airtime-liquidsoap -c 'output.dummy" + \
"(audio_to_stereo(single(\"%s\")))' > /dev/null 2>&1") % \
pathname.replace("'", "'\\''")
return_code = subprocess.call(command, shell=True)
return (return_code == 0)
if __name__ == '__main__': if __name__ == '__main__':
import doctest import doctest
doctest.testmod() doctest.testmod()

View file

@ -87,34 +87,34 @@ def calculate_replay_gain(file_path):
temp_file_path = duplicate_file(file_path) temp_file_path = duplicate_file(file_path)
file_type = get_file_type(file_path) file_type = get_file_type(file_path)
nice_level = '15'
if file_type: if file_type:
if file_type == 'mp3': if file_type == 'mp3':
if run_process("which mp3gain > /dev/null") == 0: if run_process("which mp3gain > /dev/null") == 0:
out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path) out = get_process_output('nice -n %s mp3gain -q "%s" 2> /dev/null' % (nice_level, temp_file_path))
search = re.search(r'Recommended "Track" dB change: (.*)', out) search = re.search(r'Recommended "Track" dB change: (.*)', out)
else: else:
logger.warn("mp3gain not found") logger.warn("mp3gain not found")
elif file_type == 'vorbis': elif file_type == 'vorbis':
if run_process("which vorbisgain > /dev/null && which ogginfo > /dev/null") == 0: 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) run_process('nice -n %s vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % (nice_level,temp_file_path))
out = get_process_output('ogginfo "%s"' % temp_file_path) out = get_process_output('ogginfo "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out) search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else: else:
logger.warn("vorbisgain/ogginfo not found") logger.warn("vorbisgain/ogginfo not found")
elif file_type == 'flac': elif file_type == 'flac':
if run_process("which metaflac > /dev/null") == 0: if run_process("which metaflac > /dev/null") == 0:
out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path) out = get_process_output('nice -n %s metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % (nice_level, temp_file_path))
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out) search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else: else: logger.warn("metaflac not found")
logger.warn("metaflac not found")
else:
pass
#no longer need the temp, file simply remove it.
os.remove(temp_file_path)
except Exception, e: except Exception, e:
logger.error(str(e)) logger.error(str(e))
finally:
#no longer need the temp, file simply remove it.
try: os.remove(temp_file_path)
except: pass
replay_gain = 0 replay_gain = 0
if search: if search: