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

This commit is contained in:
Martin Konecny 2012-08-15 18:31:07 -04:00
commit 45a4c8d896
15 changed files with 269 additions and 144 deletions

View File

@ -1,6 +1,88 @@
<?php
class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
{
private $criteriaOptions = array(
0 => "Select criteria",
"album_title" => "Album",
"bit_rate" => "Bit Rate",
"bpm" => "Bpm",
"comments" => "Comments",
"composer" => "Composer",
"conductor" => "Conductor",
"artist_name" => "Creator",
"disc_number" => "Disc Number",
"genre" => "Genre",
"isrc_number" => "ISRC",
"label" => "Label",
"language" => "Language",
"mtime" => "Last Modified",
"lptime" => "Last Played",
"length" => "Length",
"lyricist" => "Lyricist",
"mood" => "Mood",
"name" => "Name",
"orchestra" => "Orchestra",
"rating" => "Rating",
"sample_rate" => "Sample Rate",
"track_title" => "Title",
"track_number" => "Track Number",
"utime" => "Uploaded",
"year" => "Year"
);
private $criteriaTypes = array(
0 => "",
"album_title" => "s",
"artist_name" => "s",
"bit_rate" => "n",
"bpm" => "n",
"comments" => "s",
"composer" => "s",
"conductor" => "s",
"utime" => "n",
"mtime" => "n",
"lptime" => "n",
"disc_number" => "n",
"genre" => "s",
"isrc_number" => "s",
"label" => "s",
"language" => "s",
"length" => "n",
"lyricist" => "s",
"mood" => "s",
"name" => "s",
"orchestra" => "s",
"rating" => "n",
"sample_rate" => "n",
"track_title" => "s",
"track_number" => "n",
"year" => "n"
);
private $stringCriteriaOptions = array(
"0" => "Select modifier",
"contains" => "contains",
"does not contain" => "does not contain",
"is" => "is",
"is not" => "is not",
"starts with" => "starts with",
"ends with" => "ends with"
);
private $numericCriteriaOptions = array(
"0" => "Select modifier",
"is" => "is",
"is not" => "is not",
"is greater than" => "is greater than",
"is less than" => "is less than",
"is in the range" => "is in the range"
);
private $limitOptions = array(
"hours" => "hours",
"minutes" => "minutes",
"items" => "items"
);
public function init(){
@ -8,89 +90,6 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
public function startForm($p_blockId)
{
$criteriaOptions = array(
0 => "Select criteria",
"album_title" => "Album",
"bit_rate" => "Bit Rate",
"bpm" => "Bpm",
"comments" => "Comments",
"composer" => "Composer",
"conductor" => "Conductor",
"artist_name" => "Creator",
"disc_number" => "Disc Number",
"genre" => "Genre",
"isrc_number" => "ISRC",
"label" => "Label",
"language" => "Language",
"mtime" => "Last Modified",
"lptime" => "Last Played",
"length" => "Length",
"lyricist" => "Lyricist",
"mood" => "Mood",
"name" => "Name",
"orchestra" => "Orchestra",
"rating" => "Rating",
"sample_rate" => "Sample Rate",
"track_title" => "Title",
"track_number" => "Track Number",
"utime" => "Uploaded",
"year" => "Year"
);
$criteriaTypes = array(
0 => "",
"album_title" => "s",
"artist_name" => "s",
"bit_rate" => "n",
"bpm" => "s",
"comments" => "s",
"composer" => "s",
"conductor" => "s",
"utime" => "n",
"mtime" => "n",
"lptime" => "n",
"disc_number" => "n",
"genre" => "s",
"isrc_number" => "s",
"label" => "s",
"language" => "s",
"length" => "n",
"lyricist" => "s",
"mood" => "s",
"name" => "s",
"orchestra" => "s",
"rating" => "n",
"sample_rate" => "n",
"track_title" => "s",
"track_number" => "n",
"year" => "n"
);
$stringCriteriaOptions = array(
"0" => "Select modifier",
"contains" => "contains",
"does not contain" => "does not contain",
"is" => "is",
"is not" => "is not",
"starts with" => "starts with",
"ends with" => "ends with"
);
$numericCriteriaOptions = array(
"0" => "Select modifier",
"is" => "is",
"is not" => "is not",
"is greater than" => "is greater than",
"is less than" => "is less than",
"is in the range" => "is in the range"
);
$limitOptions = array(
"hours" => "hours",
"minutes" => "minutes",
"items" => "items"
);
// load type
$out = CcBlockQuery::create()->findPk($p_blockId);
if ($out->getDbType() == "static") {
@ -128,7 +127,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
if (isset($storedCrit["crit"])) {
$criteriaKeys = array_keys($storedCrit["crit"]);
}
$numElements = count($criteriaOptions);
$numElements = count($this->criteriaOptions);
for ($i = 0; $i < $numElements; $i++) {
$criteriaType = "";
@ -155,13 +154,13 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$criteria->setAttrib('class', 'input_select sp_input_select'.$invisible)
->setValue('Select criteria')
->setDecorators(array('viewHelper'))
->setMultiOptions($criteriaOptions);
->setMultiOptions($this->criteriaOptions);
if ($i != 0 && !isset($criteriaKeys[$i])) {
$criteria->setAttrib('disabled', 'disabled');
}
if (isset($criteriaKeys[$i])) {
$criteriaType = $criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
$criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
}
$this->addElement($criteria);
@ -176,9 +175,9 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
}
if (isset($criteriaKeys[$i])) {
if($criteriaType == "s"){
$criteriaModifers->setMultiOptions($stringCriteriaOptions);
$criteriaModifers->setMultiOptions($this->stringCriteriaOptions);
}else{
$criteriaModifers->setMultiOptions($numericCriteriaOptions);
$criteriaModifers->setMultiOptions($this->numericCriteriaOptions);
}
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
}else{
@ -217,7 +216,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$limit = new Zend_Form_Element_Select('sp_limit_options');
$limit->setAttrib('class', 'sp_input_select')
->setDecorators(array('viewHelper'))
->setMultiOptions($limitOptions);
->setMultiOptions($this->limitOptions);
if (isset($storedCrit["limit"])) {
$limit->setValue($storedCrit["limit"]["modifier"]);
}
@ -262,19 +261,117 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption"=> $openSmartBlockOption,
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap))
'criteriasLength' => count($this->criteriaOptions), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap))
));
}
function isValid($params){
Logging::log("isvalid called");
$isValid = true;
// reconstruct the params['criteria'] so we can populate the form
$formData = array();
foreach ($params['data'] as $ele) {
$formData[$ele['name']] = $ele['value'];
function preValidation($params) {
$data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']);
// add elelments that needs to be added
// set multioption for modifier according to creiteria_field
$modRowMap = array();
foreach ($data['criteria'] as $critKey=>$d) {
$count = 1;
foreach($d as $modKey=>$modInfo) {
if ($modKey == 0) {
$eleCrit = $this->getElement("sp_criteria_field_".$critKey."_".$modKey);
$eleCrit->setValue($this->criteriaOptions[$modInfo['sp_criteria_field']]);
$eleCrit->setAttrib("disabled", null);
$eleMod = $this->getElement("sp_criteria_modifier_".$critKey."_".$modKey);
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
if ($criteriaType == "s") {
$eleMod->setMultiOptions($this->stringCriteriaOptions);
} else if ($criteriaType == "n") {
$eleMod->setMultiOptions($this->numericCriteriaOptions);
} else {
$eleMod->setMultiOptions(array('0' => 'Select modifier'));
}
$eleMod->setValue($modInfo['sp_criteria_modifier']);
$eleMod->setAttrib("disabled", null);
$eleValue = $this->getElement("sp_criteria_value_".$critKey."_".$modKey);
$eleValue->setValue($modInfo['sp_criteria_value']);
$eleValue->setAttrib("disabled", null);
if (isset($modInfo['sp_criteria_extra'])) {
$eleExtra = $this->getElement("sp_criteria_extra_".$critKey."_".$modKey);
$eleExtra->setValue($modInfo['sp_criteria_extra']);
$eleValue->setAttrib('class', 'input_text sp_extra_input_text');
$eleExtra->setAttrib("disabled", null);
}
} else {
$criteria = new Zend_Form_Element_Select("sp_criteria_field_".$critKey."_".$modKey);
$criteria->setAttrib('class', 'input_select sp_input_select sp-invisible')
->setValue('Select criteria')
->setDecorators(array('viewHelper'))
->setMultiOptions($this->criteriaOptions);
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
$criteria->setValue($this->criteriaOptions[$modInfo['sp_criteria_field']]);
$this->addElement($criteria);
/****************** MODIFIER ***********/
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$critKey."_".$modKey);
$criteriaModifers->setValue('Select modifier')
->setAttrib('class', 'input_select sp_input_select')
->setDecorators(array('viewHelper'));
if ($criteriaType == "s") {
$criteriaModifers->setMultiOptions($this->stringCriteriaOptions);
} else if ($criteriaType == "n") {
$criteriaModifers->setMultiOptions($this->numericCriteriaOptions);
} else {
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
}
$criteriaModifers->setValue($modInfo['sp_criteria_modifier']);
$this->addElement($criteriaModifers);
/****************** VALUE ***********/
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$critKey."_".$modKey);
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
->setDecorators(array('viewHelper'));
$criteriaValue->setValue($modInfo['sp_criteria_value']);
$this->addElement($criteriaValue);
/****************** EXTRA ***********/
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$critKey."_".$modKey);
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
->setDecorators(array('viewHelper'));
if (isset($modInfo['sp_criteria_extra'])) {
$criteriaExtra->setValue($modInfo['sp_criteria_extra']);
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
}else{
$criteriaExtra->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtra);
$count++;
}
}
$modRowMap[$critKey] = $count;
}
$decorator = $this->getDecorator("ViewScript");
$existingModRow = $decorator->getOption("modRowMap");
foreach ($modRowMap as $key=>$v) {
$existingModRow[$key] = $v;
}
$decorator->setOption("modRowMap", $existingModRow);
// reconstruct the params['criteria'] so we can populate the form
$formData = array();
foreach ($params['data'] as $ele) {
$formData[$ele['name']] = $ele['value'];
}
$this->populate($formData);
return $data;
}
function isValid($params){
$isValid = true;
$data = $this->preValidation($params);
$criteria2PeerMap = array(
0 => "Select criteria",
"album_title" => "DbAlbumTitle",
@ -303,7 +400,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
"track_number" => "DbTrackNumber",
"year" => "DbYear"
);
$data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']);
// things we need to check
// 1. limit value shouldn't be empty and has upperbound of 24 hrs
// 2. sp_criteria or sp_criteria_modifier shouldn't be 0

View File

@ -1148,7 +1148,7 @@ EOT;
// e.g 192kps is stored as 192000
$spCriteriaValue = $criteria['value']*1000;
} else {
$spCriteriaValue = $criteria['value'];
$spCriteriaValue = addslashes($criteria['value']);
}
if ($spCriteriaModifier == "starts with") {
@ -1158,8 +1158,9 @@ EOT;
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
$spCriteriaValue = "%$spCriteriaValue%";
} else if ($spCriteriaModifier == "is in the range") {
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'";
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria <= '$criteria[extra]'";
}
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
try{
if ($i > 0) {

View File

@ -634,7 +634,7 @@ class Application_Model_StoredFile
$streamSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
}
//need to cast certain data as ints for the union to search on.
else if (in_array($key, array("track_number", "bit_rate", "sample_rate"))) {
else if (in_array($key, array("track_number", "bit_rate", "sample_rate", "bpm"))) {
$plSelect[] = "NULL::int AS ".$key;
$blSelect[] = "NULL::int AS ".$key;
$fileSelect[] = $key;

View File

@ -64,7 +64,7 @@ class CcFilesTableMap extends TableMap {
$this->addColumn('TRACK_NUMBER', 'DbTrackNumber', 'INTEGER', false, null, null);
$this->addColumn('CHANNELS', 'DbChannels', 'INTEGER', false, null, null);
$this->addColumn('URL', 'DbUrl', 'VARCHAR', false, 1024, null);
$this->addColumn('BPM', 'DbBpm', 'VARCHAR', false, 8, null);
$this->addColumn('BPM', 'DbBpm', 'INTEGER', false, null, null);
$this->addColumn('RATING', 'DbRating', 'VARCHAR', false, 8, null);
$this->addColumn('ENCODED_BY', 'DbEncodedBy', 'VARCHAR', false, 255, null);
$this->addColumn('DISC_NUMBER', 'DbDiscNumber', 'VARCHAR', false, 8, null);

View File

@ -189,7 +189,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
/**
* The value for the bpm field.
* @var string
* @var int
*/
protected $bpm;
@ -814,7 +814,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
/**
* Get the [bpm] column value.
*
* @return string
* @return int
*/
public function getDbBpm()
{
@ -1822,13 +1822,13 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
/**
* Set the value of [bpm] column.
*
* @param string $v new value
* @param int $v new value
* @return CcFiles The current object (for fluent API support)
*/
public function setDbBpm($v)
{
if ($v !== null) {
$v = (string) $v;
$v = (int) $v;
}
if ($this->bpm !== $v) {
@ -2678,7 +2678,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
$this->track_number = ($row[$startcol + 23] !== null) ? (int) $row[$startcol + 23] : null;
$this->channels = ($row[$startcol + 24] !== null) ? (int) $row[$startcol + 24] : null;
$this->url = ($row[$startcol + 25] !== null) ? (string) $row[$startcol + 25] : null;
$this->bpm = ($row[$startcol + 26] !== null) ? (string) $row[$startcol + 26] : null;
$this->bpm = ($row[$startcol + 26] !== null) ? (int) $row[$startcol + 26] : null;
$this->rating = ($row[$startcol + 27] !== null) ? (string) $row[$startcol + 27] : null;
$this->encoded_by = ($row[$startcol + 28] !== null) ? (string) $row[$startcol + 28] : null;
$this->disc_number = ($row[$startcol + 29] !== null) ? (string) $row[$startcol + 29] : null;

View File

@ -191,7 +191,7 @@
* @method CcFiles findOneByDbTrackNumber(int $track_number) Return the first CcFiles filtered by the track_number column
* @method CcFiles findOneByDbChannels(int $channels) Return the first CcFiles filtered by the channels column
* @method CcFiles findOneByDbUrl(string $url) Return the first CcFiles filtered by the url column
* @method CcFiles findOneByDbBpm(string $bpm) Return the first CcFiles filtered by the bpm column
* @method CcFiles findOneByDbBpm(int $bpm) Return the first CcFiles filtered by the bpm column
* @method CcFiles findOneByDbRating(string $rating) Return the first CcFiles filtered by the rating column
* @method CcFiles findOneByDbEncodedBy(string $encoded_by) Return the first CcFiles filtered by the encoded_by column
* @method CcFiles findOneByDbDiscNumber(string $disc_number) Return the first CcFiles filtered by the disc_number column
@ -255,7 +255,7 @@
* @method array findByDbTrackNumber(int $track_number) Return CcFiles objects filtered by the track_number column
* @method array findByDbChannels(int $channels) Return CcFiles objects filtered by the channels column
* @method array findByDbUrl(string $url) Return CcFiles objects filtered by the url column
* @method array findByDbBpm(string $bpm) Return CcFiles objects filtered by the bpm column
* @method array findByDbBpm(int $bpm) Return CcFiles objects filtered by the bpm column
* @method array findByDbRating(string $rating) Return CcFiles objects filtered by the rating column
* @method array findByDbEncodedBy(string $encoded_by) Return CcFiles objects filtered by the encoded_by column
* @method array findByDbDiscNumber(string $disc_number) Return CcFiles objects filtered by the disc_number column
@ -1061,20 +1061,29 @@ abstract class BaseCcFilesQuery extends ModelCriteria
/**
* Filter the query on the bpm column
*
* @param string $dbBpm The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param int|array $dbBpm The value to use as filter.
* Accepts an associative array('min' => $minValue, 'max' => $maxValue)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return CcFilesQuery The current query, for fluid interface
*/
public function filterByDbBpm($dbBpm = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($dbBpm)) {
if (is_array($dbBpm)) {
$useMinMax = false;
if (isset($dbBpm['min'])) {
$this->addUsingAlias(CcFilesPeer::BPM, $dbBpm['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($dbBpm['max'])) {
$this->addUsingAlias(CcFilesPeer::BPM, $dbBpm['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $dbBpm)) {
$dbBpm = str_replace('*', '%', $dbBpm);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(CcFilesPeer::BPM, $dbBpm, $comparison);

View File

@ -19,6 +19,10 @@ class BitrateFormatter {
{
$Kbps = bcdiv($this->_bitrate, 1000, 0);
return "{$Kbps} Kbps";
if($Kbps == 0) {
return "";
} else {
return "{$Kbps} Kbps";
}
}
}
}

View File

@ -57,6 +57,13 @@
<span class='sp_text_font'><?php echo $this->element->getElement('sp_limit_value')->getLabel() ?></span>
<?php echo $this->element->getElement('sp_limit_value')?>
<?php echo $this->element->getElement('sp_limit_options') ?>
<?php if($this->element->getElement("sp_limit_value")->hasErrors()) : ?>
<?php foreach($this->element->getElement("sp_limit_value")->getMessages() as $error): ?>
<span class='errors sp-errors'>
<?php echo $error; ?>
</span>
<?php endforeach; ?>
<?php endif; ?>
<br />
</dd>
<div class='sp_text_font sp_text_font_bold'>

View File

@ -38,7 +38,7 @@
<column name="track_number" phpName="DbTrackNumber" type="INTEGER" required="false"/>
<column name="channels" phpName="DbChannels" type="INTEGER" required="false"/>
<column name="url" phpName="DbUrl" type="VARCHAR" size="1024" required="false"/>
<column name="bpm" phpName="DbBpm" type="VARCHAR" size="8" required="false"/>
<column name="bpm" phpName="DbBpm" type="INTEGER" required="false"/>
<column name="rating" phpName="DbRating" type="VARCHAR" size="8" required="false"/>
<column name="encoded_by" phpName="DbEncodedBy" type="VARCHAR" size="255" required="false"/>
<column name="disc_number" phpName="DbDiscNumber" type="VARCHAR" size="8" required="false"/>

View File

@ -56,7 +56,7 @@ CREATE TABLE "cc_files"
"track_number" INTEGER,
"channels" INTEGER,
"url" VARCHAR(1024),
"bpm" VARCHAR(8),
"bpm" INTEGER,
"rating" VARCHAR(8),
"encoded_by" VARCHAR(255),
"disc_number" VARCHAR(8),

View File

@ -414,7 +414,8 @@ function sizeTextBoxes(ele, classToRemove, classToAdd) {
function populateModifierSelect(e) {
var criteria_type = getCriteriaOptionType(e),
index = getRowIndex($(e).parent()),
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+index+'"]');
critIndex = index.substring(0, 1),
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+critIndex+'"]');
$.each(divs, function(i, div){
$(div).children().remove();
@ -441,14 +442,12 @@ function getCriteriaOptionType(e) {
}
function callback(data, type) {
var form = $('#smart-playlist-form'),
json = $.parseJSON(data),
var json = $.parseJSON(data),
dt = $('table[id="library_display"]').dataTable();
form.find('span[class="errors sp-errors"]').remove();
if (type == 'shuffle' || type == 'generate') {
AIRTIME.playlist.fnOpenPlaylist(json);
form = $('#smart-playlist-form');
var form = $('#smart-playlist-form');
if (json.result == "0") {
if (type == 'shuffle') {
form.find('.success').text('Smart playlist shuffled');
@ -462,6 +461,7 @@ function callback(data, type) {
form.find('#smart_playlist_options').removeClass("closed");
} else {
AIRTIME.playlist.fnOpenPlaylist(json);
var form = $('#smart-playlist-form');
if (json.result == "0") {
$('#sp-success-saved').text('Smart playlist saved');
$('#sp-success-saved').show();
@ -470,6 +470,7 @@ function callback(data, type) {
var dt = $('table[id="library_display"]').dataTable();
dt.fnStandingRedraw();
}
form.find('#smart_playlist_options').removeClass("closed");
}
setTimeout(removeSuccessMsg, 5000);
}
@ -529,7 +530,7 @@ var criteriaTypes = {
"album_title" : "s",
"artist_name" : "s",
"bit_rate" : "n",
"bpm" : "s",
"bpm" : "n",
"comments" : "s",
"composer" : "s",
"conductor" : "s",

View File

@ -65,8 +65,6 @@ class BaseListener(object):
self.signal = signal
class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
# this class still don't handle the case where a dir was copied recursively
def process_IN_CLOSE_WRITE(self, event):
self.process_to_organize(event)
# got cookie

View File

@ -51,7 +51,7 @@ airtime_special = {
"MDATA_KEY_DURATION" :
lambda m: format_length(getattr(m.info, u'length', 0.0)),
"MDATA_KEY_BITRATE" :
lambda m: getattr(m.info, "bitrate", 0),
lambda m: getattr(m.info, "bitrate", ''),
"MDATA_KEY_SAMPLERATE" :
lambda m: getattr(m.info, u'sample_rate', 0),
"MDATA_KEY_MIME" :

View File

@ -62,7 +62,7 @@ def partition(f, alist):
Partition is very similar to filter except that it also returns the
elements for which f return false but in a tuple.
>>> partition(lambda x : x > 3, [1,2,3,4,5,6])
[4,5,6],[1,2,3]
([4, 5, 6], [1, 2, 3])
"""
return (filter(f, alist), filter(lambda x: not f(x), alist))
@ -104,6 +104,8 @@ def extension(path):
I.e. interpreter won't enforce None checks on the programmer
>>> extension("testing.php")
'php'
>>> extension("a.b.c.d.php")
'php'
>>> extension('/no/extension')
''
>>> extension('/path/extension.ml')
@ -117,15 +119,17 @@ def no_extension_basename(path):
"""
returns the extensionsless basename of a filepath
>>> no_extension_basename("/home/test.mp3")
'test'
u'test'
>>> no_extension_basename("/home/test")
'test'
u'test'
>>> no_extension_basename('blah.ml')
'blah'
u'blah'
>>> no_extension_basename('a.b.c.d.mp3')
u'a.b.c.d'
"""
base = unicode(os.path.basename(path))
if extension(base) == "": return base
else: return base.split(".")[-2]
else: return '.'.join(base.split(".")[0:-1])
def walk_supported(directory, clean_empties=False):
"""
@ -203,16 +207,16 @@ def parse_int(s):
Tries very hard to get some sort of integer result from s. Defaults to 0
when it failes
>>> parse_int("123")
123
'123'
>>> parse_int("123saf")
123
'123'
>>> parse_int("asdf")
0
''
"""
if s.isdigit(): return s
else:
try : return reduce(op.add, takewhile(lambda x: x.isdigit(), s))
except: return 0
try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s)))
except: return ''
def normalized_metadata(md, original_path):
"""
@ -239,14 +243,13 @@ def normalized_metadata(md, original_path):
# could possibly lead to subtle bugs down the road. Plus the following
# approach gives us the flexibility to use different defaults for different
# attributes
new_md = remove_whitespace(new_md)
new_md = apply_rules_dict(new_md, format_rules)
new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'],
default=no_extension_basename(original_path))
new_md = remove_whitespace(new_md)
new_md = default_to(dictionary=new_md, keys=path_md,
default=u'')
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_FTYPE'],
default=u'audioclip')
default=u'audioclip')
# In the case where the creator is 'Airtime Show Recorder' we would like to
# format the MDATA_KEY_TITLE slightly differently
# Note: I don't know why I'm doing a unicode string comparison here

View File

@ -67,4 +67,9 @@ class TestMMP(unittest.TestCase):
self.assertTrue( mmp.sub_path(d1, f1) )
self.assertTrue( mmp.sub_path(d2, f1) )
def test_parse_int(self):
self.assertEqual( mmp.parse_int("123"), "123" )
self.assertEqual( mmp.parse_int("123asf"), "123" )
self.assertEqual( mmp.parse_int("asdf"), "" )
if __name__ == '__main__': unittest.main()