Merge branch 'master' of dev.sourcefabric.org:campcaster

This commit is contained in:
naomiaro 2010-12-30 17:27:19 -05:00
commit c24a152eba
2 changed files with 78 additions and 49 deletions

View File

@ -5,20 +5,26 @@
""" """
cue script that gets called by liquidsoap if a file in the playlist cue script that gets called by liquidsoap if a file in the playlist
gives orders to cue (in/out). eg: gives orders to cue (in/out). eg:
cue_file:cue_in=120.0,cue_out=110.0:annotate:*** cue_file:cue_in=90.0,cue_out=110.0:annotate:***
params: path_to_file, cue_in [float, seconds], cue_out [float, sseconds] cue_in is number of seconds from the beginning of the file.
cue_out is number of seconds from the end of the file.
params: path_to_file, cue_in [float, seconds], cue_out [float, seconds]
returns: path to the cued temp-file returns: path to the cued temp-file
examples: examples:
calling: ./cue_file.py /storage/pypo/cache/2010-06-25-15-05-00/35.mp3 10 120.095 calling: ./cue_file.py /storage/pypo/cache/2010-06-25-15-05-00/35.mp3 10 120.095
returns: /tmp/lstf_UwDKcEngvF returns: /tmp/lstf_UwDKcEngvF
In this example, the first 10 seconds and last 120.095 seconds are cut off. The
middle part of the file is returned.
One thing to mention here: One thing to mention here:
The way pypo (ab)uses liquidsoap can bring in some unwanted effects. liquidsoap The way pypo (ab)uses liquidsoap can bring in some unwanted effects. liquidsoap
is built in a way that it tries to collect the needed files to playout in advance. is built in a way that it tries to collect the needed files to playout in advance.
we 'force' liquidsoap to immediately start playing a newly loaded list, so ls has we 'force' liquidsoap to immediately start playing a newly loaded list, so ls has
no time to prepare the files. If a file is played without cues, this does not afect no time to prepare the files. If a file is played without cues, this does not affect
the playout too much. My testing on a lame VM added a delay of +/- 10ms. the playout too much. My testing on a lame VM added a delay of +/- 10ms.
If the first file in a playlist is cued, the "mp3cut" command takes time to execute. If the first file in a playlist is cued, the "mp3cut" command takes time to execute.
@ -43,16 +49,16 @@ from datetime import timedelta
import os import os
from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
import mad from mutagen.oggvorbis import OggVorbis
TEMP_DIR = '/tmp/'; TEMP_DIR = '/tmp/';
sys.stderr.write('\n** starting mp3 cutter **\n\n') sys.stderr.write('\n** starting mp3/ogg cutter **\n\n')
try: src = sys.argv[1] try: src = sys.argv[1]
except Exception, e: except Exception, e:
sys.stderr.write('No file givien. sorry.\n') sys.stderr.write('No file given. Exiting...\n')
sys.exit() sys.exit()
try: cue_in = float(sys.argv[2]) try: cue_in = float(sys.argv[2])
@ -67,23 +73,16 @@ except Exception, e:
sys.stderr.write('in: %s - out: %s file: %s \n' % (cue_in, cue_out, src)) sys.stderr.write('in: %s - out: %s file: %s \n' % (cue_in, cue_out, src))
dst = TEMP_DIR + 'lstf_' + "".join( [random.choice(string.letters) for i in xrange(10)] ) dst = TEMP_DIR + 'lstf_' + "".join( [random.choice(string.letters) for i in xrange(10)] )
#TODO, there is no checking whether this randomly generated file name already exists!
# get length of track
"""
madlib is not accurate enough to get the duration. (only goes to seconds, no ms)
so it is not suitable for relative offsets (eg "play until 10s before the end")
it anyway wuld be better to provide this script with absolute times, like
play from 23.234 to 323.321
"""
# madlib
#mf = mad.MadFile(src)
#dur = float(float(mf.total_time())/1000)
# mutagen # get length of track using mutagen.
#audio
#command
if src.endswith('.mp3'):
audio = MP3(src) audio = MP3(src)
dur = round(audio.info.length, 3) dur = round(audio.info.length, 3)
sys.stderr.write('duration: ' + str(dur) + '\n') sys.stderr.write('duration: ' + str(dur) + '\n')
cue_out = round(float(dur) - cue_out, 3) cue_out = round(float(dur) - cue_out, 3)
@ -112,14 +111,31 @@ try:
except Exception, e: except Exception, e:
pass pass
#sys.stderr.write(str(timedelta(seconds=cue_in)).replace(".", "+") + '\n\n')
sys.stderr.write('in: ' + str_cue_in + '\n') sys.stderr.write('in: ' + str_cue_in + '\n')
sys.stderr.write('abs: ' + str(str_cue_out) + '\n\n') sys.stderr.write('abs: ' + str(str_cue_out) + '\n\n')
command = 'mp3cut -o %s -t %s-%s %s' % (dst, str_cue_in, str_cue_out, src); command = 'mp3cut -o %s -t %s-%s %s' % (dst, str_cue_in, str_cue_out, src)
elif src.endswith('.ogg'):
audio = OggVorbis(src)
dur = audio.info.length
sys.stderr.write('duration: ' + str(dur) + '\n')
cue_out = float(dur) - cue_out
#convert input format of ss.mmm to milliseconds and to string<
str_cue_in = str(int(round(cue_in*1000)))
#convert input format of ss.mmm to milliseconds and to string
str_cue_out = str(int(round(cue_out*1000)))
command = 'oggCut -s %s -e %s %s %s' % (str_cue_in, str_cue_out, src, dst)
else:
sys.stderr.write('File name with invalid extension. Exiting...\n')
sys.exit()
sys.stderr.write(command + '\n\n\n') sys.stderr.write(command + '\n\n\n')
os.system(command + ' >/dev/null') os.system(command + ' > /dev/null 2>&1')
#shutil.copy2(src, dst)
print dst + "\n"; print dst + "\n";

View File

@ -42,6 +42,18 @@ $pl = new Playlist();
$pl->create($playlistName); $pl->create($playlistName);
// Add a media clip // Add a media clip
$mediaFile = StoredFile::findByOriginalName("ACDC_-_Back_In_Black-sample.ogg");
if (is_null($mediaFile)) {
echo "Adding test audio clip to the database.\n";
$v = array("filepath" => __DIR__."/../../audio_samples/OpSound/ACDC_-_Back_In_Black-sample.ogg");
$mediaFile = StoredFile::Insert($v);
if (PEAR::isError($mediaFile)) {
var_dump($mediaFile);
exit();
}
}
$pl->addAudioClip($mediaFile->getId());
$mediaFile = StoredFile::findByOriginalName("Manolo Camp - Morning Coffee.mp3"); $mediaFile = StoredFile::findByOriginalName("Manolo Camp - Morning Coffee.mp3");
if (is_null($mediaFile)) { if (is_null($mediaFile)) {
echo "Adding test audio clip to the database.\n"; echo "Adding test audio clip to the database.\n";
@ -53,6 +65,7 @@ if (is_null($mediaFile)) {
} }
} }
$pl->addAudioClip($mediaFile->getId()); $pl->addAudioClip($mediaFile->getId());
$mediaFile = StoredFile::findByOriginalName("Peter Rudenko - Opening.mp3"); $mediaFile = StoredFile::findByOriginalName("Peter Rudenko - Opening.mp3");
if (is_null($mediaFile)) { if (is_null($mediaFile)) {
echo "Adding test audio clip to the database.\n"; echo "Adding test audio clip to the database.\n";