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

This commit is contained in:
James 2011-08-02 11:25:18 -04:00
commit 2cfe729379
7 changed files with 161 additions and 8 deletions

View File

@ -580,6 +580,61 @@ class Airtime190Upgrade{
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE); $CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
} }
public static function backupFileInfoInStorToFile($values) {
echo "Save DbMd to File".PHP_EOL;
$stor_dir = realpath($values['general']['base_files_dir']."/stor");
$files = CcFilesQuery::create()
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
->find();
$dumpFile = __DIR__."/storDump.txt";
$fh = fopen($dumpFile, 'w') or die("can't open file to backup stor.");
$s = "SF_BACKUP_1.9.0";
foreach ($files as $file) {
$filepath = $file->getDbFilepath();
if (substr($filepath, 0, strlen($stor_dir)) == $stor_dir) {
$recorded_show = CcShowInstancesQuery::create()
->filterByDbRecordedFile($file->getDbId())
->findOne();
if (isset($recorded_show)) {
$start_time = $recorded_show->getDbStarts();
$title = $file->getDbTrackTitle();
$start_time = str_replace(" ", "-", $start_time);
$start_time = str_replace(":", "-", $start_time);
//$start_time like yyyy-mm-dd-hh-MM-ss
list($yyyy, $mm, $dd, $hh, $MM, $ss) = explode("-", $start_time);
$data = "1$s$filepath$s$title$s$yyyy$s$mm$s$dd$s$hh$s$MM\n";
}
else {
$artist = $file->getDbArtistName();
$album = $file->getDbAlbumTitle();
$track = $file->getDbTrackNumber();
$title = $file->getDbTrackTitle();
$data = "0$s$filepath$s$title$s$artist$s$album$s$track\n";
}
fwrite($fh, $data);
}
}
fclose($fh);
}
/* Old database had a "fullpath" column that stored the absolute path of each track. We have to /* Old database had a "fullpath" column that stored the absolute path of each track. We have to
* change it so that the "fullpath" column has path relative to the "directory" column. * change it so that the "fullpath" column has path relative to the "directory" column.
*/ */
@ -617,7 +672,7 @@ class Airtime190Upgrade{
$cwd = __DIR__; $cwd = __DIR__;
$mediaMonitorUpgradePath = __DIR__."/media-monitor-upgrade.py"; $mediaMonitorUpgradePath = __DIR__."/media-monitor-upgrade.py";
$command = "cd $cwd && su -c \"python $mediaMonitorUpgradePath\""; $command = "cd $cwd && python $mediaMonitorUpgradePath";
exec($command, $output); exec($command, $output);
print_r($output); print_r($output);
@ -736,6 +791,7 @@ AirtimeInstall::CreateSymlinksToUtils();
/* create cron file for phone home stat */ /* create cron file for phone home stat */
AirtimeInstall::CreateCronFile(); AirtimeInstall::CreateCronFile();
Airtime190Upgrade::backupFileInfoInStorToFile($values);
Airtime190Upgrade::installMediaMonitor($values); Airtime190Upgrade::installMediaMonitor($values);
AirtimeIni::upgradeConfigFiles(); AirtimeIni::upgradeConfigFiles();

View File

@ -91,8 +91,13 @@ class AirtimeMetadata:
for key in m.keys() : for key in m.keys() :
if key in self.airtime2mutagen: if key in self.airtime2mutagen:
value = m[key] value = m[key]
if ((value is not None) and (len(str(value)) > 0)): if (value is not None):
airtime_file[self.airtime2mutagen[key]] = str(value) self.logger.debug("Saving %s to file", key)
self.logger.debug(value)
if isinstance(value, basestring) and (len(value) > 0):
airtime_file[self.airtime2mutagen[key]] = unicode(value, "utf-8")
elif isinstance(value, int):
airtime_file[self.airtime2mutagen[key]] = str(value)
airtime_file.save() airtime_file.save()

View File

@ -189,10 +189,23 @@ class MediaMonitorCommon:
filepath = None filepath = None
#file is recorded by Airtime #file is recorded by Airtime
#/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext #/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext
if(md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')): if(md['MDATA_KEY_CREATOR'] == "Airtime Show Recorder".encode('utf-8')):
#yyyy-mm-dd-hh-MM-ss #yyyy-mm-dd-hh-MM-ss
y = orig_md['MDATA_KEY_YEAR'].split("-") y = orig_md['MDATA_KEY_YEAR'].split("-")
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded".encode('utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded".encode('utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
#"Show-Title-2011-03-28-17:15:00"
title = md['MDATA_KEY_TITLE'].split("-")
show_hour = title[0]
show_min = title[1]
show_sec = title[2]
show_name = '-'.join(title[3:])
new_md = {}
new_md["MDATA_KEY_FILEPATH"] = original_path
new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_YEAR'], show_hour, show_min, show_sec)
self.md_manager.save_md_to_file(new_md)
elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'.encode('utf-8')): elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'.encode('utf-8')):
filepath = '%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) filepath = '%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
else: else:

View File

@ -10,6 +10,7 @@ import ConfigParser
import pwd import pwd
import grp import grp
import subprocess import subprocess
import re
import os.path import os.path
@ -48,6 +49,66 @@ mmc.set_needed_file_permissions(organize_dir, True)
#read list of all files in stor location.....and one-by-one pass this through to #read list of all files in stor location.....and one-by-one pass this through to
#mmc.organize_files. print out json encoding of before and after #mmc.organize_files. print out json encoding of before and after
pairs = [] pairs = []
f = open('storDump.txt','r')
for line in f.readlines():
db_md = line.split("SF_BACKUP_1.9.0")
#remove newlines.
for i in range(0, len(db_md)):
db_md[i] = db_md[i].strip()
logger.debug(db_md)
file_md = {}
old_filepath = db_md[1]
file_md["MDATA_KEY_FILEPATH"] = old_filepath
#file is recorded
#format 1 title year month day hour min
if int(db_md[0]):
file_md["MDATA_KEY_TITLE"] = db_md[2]
match = re.search('^.*(?=\-\d{4}\-\d{2}\-\d{2}\-\d{2}:\d{2}:\d{2}\.(mp3|ogg))', file_md["MDATA_KEY_TITLE"])
#"Show-Title-2011-03-28-17:15:00.mp3"
if match:
file_md["MDATA_KEY_TITLE"] = match.group(0)
file_md["MDATA_KEY_TITLE"] = file_md["MDATA_KEY_TITLE"].replace(" ", "-")
file_md["MDATA_KEY_TITLE"] = db_md[6]+"-"+db_md[7]+"-00-"+file_md["MDATA_KEY_TITLE"]
file_md["MDATA_KEY_YEAR"] = db_md[3]+"-"+db_md[4]+"-"+db_md[5]
file_md["MDATA_KEY_CREATOR"] = "Airtime Show Recorder".encode('utf-8')
#file is regular audio file
#format 0 title artist album track
else:
file_md["MDATA_KEY_TITLE"] = db_md[2]
match = re.search('^.*(?=\.mp3|\.ogg)', file_md["MDATA_KEY_TITLE"])
#"test.mp3" -> "test"
if match:
file_md["MDATA_KEY_TITLE"] = match.group(0)
if len(db_md[3]) > 0:
file_md["MDATA_KEY_CREATOR"] = db_md[3]
if len(db_md[4]) > 0:
file_md["MDATA_KEY_SOURCE"] = db_md[4]
if len(db_md[5]) > 0:
file_md["MDATA_KEY_TRACKNUMBER"] = int(db_md[5])
mmc.md_manager.save_md_to_file(file_md)
#new_filepath = mmc.organize_new_file(old_filepath)
#if new_filepath is not None:
#pair = old_filepath, new_filepath
#pairs.append(pair)
#mmc.set_needed_file_permissions(new_filepath, False)
f.close()
for root, dirs, files in os.walk(mmconfig.storage_directory): for root, dirs, files in os.walk(mmconfig.storage_directory):
for f in files: for f in files:
old_filepath = os.path.join(root, f) old_filepath = os.path.join(root, f)

View File

@ -91,8 +91,13 @@ class AirtimeMetadata:
for key in m.keys() : for key in m.keys() :
if key in self.airtime2mutagen: if key in self.airtime2mutagen:
value = m[key] value = m[key]
if ((value is not None) and (len(str(value)) > 0)): if (value is not None):
airtime_file[self.airtime2mutagen[key]] = str(value) self.logger.debug("Saving %s to file", key)
self.logger.debug(value)
if isinstance(value, basestring) and (len(value) > 0):
airtime_file[self.airtime2mutagen[key]] = unicode(value, "utf-8")
elif isinstance(value, int):
airtime_file[self.airtime2mutagen[key]] = str(value)
airtime_file.save() airtime_file.save()

View File

@ -189,10 +189,23 @@ class MediaMonitorCommon:
filepath = None filepath = None
#file is recorded by Airtime #file is recorded by Airtime
#/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext #/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext
if(md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')): if(md['MDATA_KEY_CREATOR'] == "Airtime Show Recorder".encode('utf-8')):
#yyyy-mm-dd-hh-MM-ss #yyyy-mm-dd-hh-MM-ss
y = orig_md['MDATA_KEY_YEAR'].split("-") y = orig_md['MDATA_KEY_YEAR'].split("-")
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded".encode('utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded".encode('utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
#"Show-Title-2011-03-28-17:15:00"
title = md['MDATA_KEY_TITLE'].split("-")
show_hour = title[0]
show_min = title[1]
show_sec = title[2]
show_name = '-'.join(title[3:])
new_md = {}
new_md["MDATA_KEY_FILEPATH"] = original_path
new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_YEAR'], show_hour, show_min, show_sec)
self.md_manager.save_md_to_file(new_md)
elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'.encode('utf-8')): elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'.encode('utf-8')):
filepath = '%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) filepath = '%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
else: else:

View File

@ -132,7 +132,7 @@ class ShowRecorder(Thread):
name = time+"-"+self.show_name name = time+"-"+self.show_name
name.encode('utf-8') name.encode('utf-8')
artist = "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8') artist = "Airtime Show Recorder".encode('utf-8')
#set some metadata for our file daemon #set some metadata for our file daemon
recorded_file = mutagen.File(filepath, easy=True) recorded_file = mutagen.File(filepath, easy=True)