Le dimanche 21 mars 2010 17:47:01, Romain Beauxis a écrit :
> The bad thing is that we loose track of the intermediate request
>  resolution  log. A possible solution is to add an extra parameter for the
>  protocol registration, which allows to pass a log along with the new
>  indicators..

In fact it is more tricky.. We will also loose the intermediate stuff, like 
annotate.. A possible solution is then to return the remaining part, 
substituting the last part with our temporary file. This gives:

request.trace 0
[2010/03/21 17:56:20] Pushed 
["cut_file:cut_start=2,cut_stop=45:annotate:bli=\"bla\":/tmp/bla.ogg";...].
[2010/03/21 17:56:20] Resolving 
"cut_file:cut_start=2,cut_stop=45:annotate:bli=\"bla\":/tmp/bla.ogg" (timeout 
20s)...
[2010/03/21 17:56:20] Pushed ["annotate:bli=\"bla\":/tmp/liq8D7O.osb";...].
[2010/03/21 17:56:20] Resolving "annotate:bli=\"bla\":/tmp/liq8D7O.osb" 
(timeout 20s)...
[2010/03/21 17:56:20] Pushed ["/tmp/liq8D7O.osb";...].
[2010/03/21 17:56:20] Currently on air.

However, in this case, the temporary file will not be removed because 
liquidsoap thinks it is "annotate:bli=\"bla\":/tmp/liq8D7O.osb"...

And it becomes a bit too hacky.. :-)

The attached patch updates the previous one with this idea..

Romain
Index: scripts/utils.liq
===================================================================
--- scripts/utils.liq	(révision 7225)
+++ scripts/utils.liq	(copie de travail)
@@ -494,6 +494,53 @@
 end
 add_protocol("replay_gain", replaygain_protocol)
 
+# Register the cut protocol
+def cut_protocol(arg,delay)
+ # The extraction program
+ cut_file = "#{configure.libdir}/cut-file"
+ # Parse args 
+ ret = string.extract(pattern="cut_start=(\d+)",arg)
+ start = 
+   if list.length(ret) == 0 then 
+     "0"
+   else
+     ret["1"]
+   end
+ ret = string.extract(pattern="cut_stop=(\d+)",arg)
+ stop =
+   if list.length(ret) == 0 then
+     "0"
+   else
+     ret["1"]
+   end
+ ret = string.extract(pattern=":([^:]*)$",arg)
+ uri = 
+   if list.length(ret) == 0 then
+     ""
+   else
+     ret["1"]
+   end
+ # Create a request and resolve it
+ r = request.create(uri)
+ if request.resolve(r) then
+   file = request.filename(r)
+   x = get_process_lines("#{cut_file} #{quote(file)} #{start} #{stop}")
+   request.destroy(r)
+   if list.hd(x) != "" then
+    # Put back the initial arg without the 
+    # cut_file: part
+    ret = string.extract(pattern="[^:]:(.*)$",arg)
+    [string.replace(pattern=uri,(fun (_) -> list.hd(x)),ret["1"])] 
+   else
+    [arg]
+   end
+ else
+  request.destroy(r)
+  [arg]
+ end
+end
+add_protocol("cut_file", temporary=true, cut_protocol)
+
 # Enable replay gain metadata resolver. This resolver will
 # process any file decoded by liquidsoap and add a @replay_gain@
 # metadata when this value could be computed. For a finer-grained
Index: scripts/cut-file
===================================================================
--- scripts/cut-file	(révision 0)
+++ scripts/cut-file	(révision 0)
@@ -0,0 +1,86 @@
+#!/usr/bin/perl -w
+
+use strict ;
+
+my $file = $ARGV[0] || die ;
+
+my $start = $ARGV[1] || "0" ;
+
+my $stop = $ARGV[2] || "0" ;
+
+sub mktemp {
+  my $file = `mktemp --tmpdir --suffix=".osb" "liqXXXX"`;
+  $file =~ s/\n//;
+  $file;
+}
+
+my $out_file = mktemp(); 
+
+sub test_mime {
+  my $file = shift ;
+  if (`which file`) {
+    return `file -b --mime-type "$file"`;
+  }
+}
+
+if (($file =~ /\.mp3$/i) || (test_mime($file) =~ /audio\/mpeg/))  {
+
+  if (`which cutmp3`) {
+
+    my $start_option = "00:00";
+    my $stop_option = "99999:0";
+
+    if ($start ne "0") {
+       $start_option = "00:$start"
+    } 
+  
+    if ($stop ne "0") {
+       $stop_option = "00:$stop"
+    }
+ 
+    system("nice -n 20 cutmp3 -c -q -a $start_option -b $stop_option -O \"$out_file\" -i \"$file\" >/dev/null 2>\&1");
+
+  } else {
+
+    print STDERR "Cannot find cutmp3 binary!\n";
+    system("cp \"$file\" \"$out_file\"");
+
+  }
+
+} elsif (($file =~ /\.ogg$/i) || (test_mime($file) =~ /application\/ogg/)) {
+
+  if (`which vcut`) {
+
+    my $start_file = $file;
+
+    # Cut beginning
+    if ($start ne "0") {
+       $start_file = mktemp();
+       system("nice -n 20 vcut \"$file\" /dev/null \"$start_file\" +$start  >/dev/null 2>\&1"); 
+    }
+
+    # Cut end
+    if ($stop ne "0") {
+       system("nice -n 20 vcut \"$start_file\" \"$out_file\" /dev/null +$stop >/dev/null 2>\&1"); 
+    } else {
+      if ("$start_file" ne "$file") {
+        system("mv $start_file $out_file");
+      }
+    }
+
+  } else {
+
+    print STDERR "Cannot find vcut binary!\n";
+    system("cp \"$file\" \"$out_file\"");
+
+  }
+
+} else {
+
+  print STDERR "File format not supported...\n";
+  system("cp \"$file\" \"$out_file\"");
+
+}
+
+print "$out_file\n";
+

Modification de propriétés sur scripts/cut-file
___________________________________________________________________
Ajouté : svn:executable
   + *

Index: scripts/Makefile
===================================================================
--- scripts/Makefile	(révision 7221)
+++ scripts/Makefile	(copie de travail)
@@ -1,6 +1,6 @@
 
 DISTFILES = $(wildcard *.in) Makefile ask-liquidsoap.rb ask-liquidsoap.pl \
-	    $(wildcard *.liq) extract-replaygain
+	    $(wildcard *.liq) extract-replaygain cut-file
 
 top_srcdir = ..
 include $(top_srcdir)/Makefile.rules
Index: Makefile
===================================================================
--- Makefile	(révision 7221)
+++ Makefile	(copie de travail)
@@ -76,6 +76,7 @@
 	$(INSTALL_DIRECTORY) $(libdir)/liquidsoap/$(libs_dir_version)
 	$(INSTALL_PROGRAM) scripts/liquidtts $(libdir)/liquidsoap/$(libs_dir_version)
 	$(INSTALL_PROGRAM) scripts/extract-replaygain $(libdir)/liquidsoap/$(libs_dir_version)
+	$(INSTALL_PROGRAM) scripts/cut-file $(libdir)/liquidsoap/$(libs_dir_version)
 	$(INSTALL_DATA) scripts/utils.liq $(libdir)/liquidsoap/$(libs_dir_version)
 	$(INSTALL_DIRECTORY) ${sysconfdir}/liquidsoap
 	$(INSTALL_DATA) examples/radio.liq \
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Savonet-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-devl

Répondre à