Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # skype-record - a wrapper script that allows you to record a skype conversation
- #
- # Copyright (C) 2005 Marilen Corciovei <len@nemesisit.ro>
- # Converted to Perl and expanded by Nathan Poznick <kraken@wang-fu.org>
- #
- # Expanded with the option of encoding to ogg-vorbis, global/absolute files
- # paths, date-based filenaming and forked converting so that files can be
- # converted after hangup while skype is still running.
- # By Benjamin Vestergaard <der_phox@gmx.net>
- #
- # Based on the vsound wrapper script. vsound's copyright:
- # Copyright (C) 2004 Nathan Chantrell <nsc@zorg.org>
- # Copyright (C) 2003 Richard Taylor <r.taylor@bcs.org.uk>
- # Copyright (C) 2000,2001 Erik de Castro Lopo <erikd@zip.com.au>
- # Copyright (C) 1999 James Henstridge <james@daa.com.au>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2.1 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- require $ENV{'HOME'}."/.skype-rec";
- our ($SKYPE_REC, $SKYPE, $SOX, $SOXMIX, $ENC_TYPE, $LAME, $LAME_OPTS,
- $OGGENC, $OGGENC_OPTS, $OUTPUT_DIR, $STEREO_MIX, $SORT_INTO_DIRS,
- $CLEANUP_TEMP, $CLEANUP_ORIG, $CHECK_INTERVAL);
- use strict;
- unless (defined($SKYPE_REC)) {
- print "ERROR: Missing configuration setting: \$SKYPE_REC\n";
- exit 1;
- }
- $ENV{'LD_PRELOAD'}=$SKYPE_REC;
- my $err = `ls 2>&1`;
- delete $ENV{'LD_PRELOAD'};
- if ($err =~ /ERROR: ld\.so: object '.*?' from LD_PRELOAD cannot be preloaded/) {
- print "ERROR: It doesn't appear that we can find libskype-rec.so at ".
- "'$SKYPE_REC'. Please check your configuration and try again.\n";
- exit 1;
- }
- unless (defined($SKYPE)) {
- print "ERROR: Missing configuration setting: \$SKYPE\n";
- exit 1;
- }
- `which $SKYPE`;
- if ($? != 0) {
- print "ERROR: Couldn't locate skype binary at '$SKYPE'";
- exit 1;
- }
- unless (defined($SOX)) {
- print "ERROR: Missing configuration setting: \$SOX\n";
- exit 1;
- }
- `which $SOX`;
- if ($? != 0) {
- print "ERROR: Couldn't locate sox binary at '$SOX'";
- exit 1;
- }
- unless (defined($SOXMIX)) {
- print "ERROR: Missing configuration setting: \$SOXMIX\n";
- exit 1;
- }
- `which $SOXMIX`;
- if ($? != 0) {
- print "ERROR: Couldn't locate soxmix binary at '$SOXMIX'";
- exit 1;
- }
- unless (defined($ENC_TYPE)) {
- print "ERROR: Missing configuration setting: \$ENC_TYPE\n";
- exit 1;
- }
- unless ($ENC_TYPE == 0 || $ENC_TYPE == 1 || $ENC_TYPE == 2) {
- print "ERROR: Invalid value for \$ENC_TYPE\n";
- exit 1;
- }
- unless (defined($LAME)) {
- print "ERROR: Missing configuration setting: \$LAME\n";
- exit 1;
- }
- if ($ENC_TYPE == 2) {
- `which $LAME`;
- if ($? != 0) {
- print "ERROR: Couldn't locate lame binary at '$LAME'";
- exit 1;
- }
- }
- unless (defined($LAME_OPTS)) {
- print "ERROR: Missing configuration setting: \$LAME_OPTS\n";
- exit 1;
- }
- unless (defined($OGGENC)) {
- print "ERROR: Missing configuration setting: \$OGGENC\n";
- exit 1;
- }
- if ($ENC_TYPE == 1) {
- `which $OGGENC`;
- if ($? != 0) {
- print "ERROR: Couldn't locate oggenc binary at '$OGGENC'";
- exit 1;
- }
- }
- unless (defined($OGGENC_OPTS)) {
- print "ERROR: Missing configuration setting: \$OGGENC_OPTS\n";
- exit 1;
- }
- unless (defined($OUTPUT_DIR)) {
- print "ERROR: Missing configuration setting: \$OUTPUT_DIR\n";
- exit 1;
- }
- unless (-d $OUTPUT_DIR) {
- if (-e $OUTPUT_DIR) {
- print "ERROR: Output directory $OUTPUT_DIR exists but is not a directory\n";
- exit 1;
- }
- `mkdir -p $OUTPUT_DIR`;
- if ($? != 0) {
- print "ERROR: Could not create missing output directory $OUTPUT_DIR : $!\n";
- exit 1;
- }
- else {
- print "NOTICE: Created non-existent output directory $OUTPUT_DIR\n";
- }
- unless (-W $OUTPUT_DIR) {
- print "ERROR: $OUTPUT_DIR is not writable by the current user\n";
- exit 1;
- }
- }
- unless (defined($STEREO_MIX)) {
- print "ERROR: Missing configuration setting: \$STEREO_MIX\n";
- exit 1;
- }
- unless (defined($SORT_INTO_DIRS)) {
- print "ERROR: Missing configuration setting: \$SORT_INTO_DIRS\n";
- exit 1;
- }
- unless (defined($CLEANUP_TEMP)) {
- print "ERROR: Missing configuration setting: \$CLEANUP_TEMP\n";
- exit 1;
- }
- unless (defined($CLEANUP_ORIG)) {
- print "ERROR: Missing configuration setting: \$CLEANUP_ORIG\n";
- exit 1;
- }
- unless (defined($CHECK_INTERVAL)) {
- print "ERROR: Missing configuration setting: \$CHECK_INTERVAL\n";
- exit 1;
- }
- my $convert_run = 1;
- my $type;
- if ($ENC_TYPE == 0) {
- $type = "wav";
- }
- elsif ($ENC_TYPE == 1) {
- $type = "ogg";
- }
- elsif ($ENC_TYPE == 2) {
- $type = "mp3";
- }
- print "Starting file conversion process...\n";
- my $pid = fork;
- if (!$pid) {
- $SIG{TERM} = sub { $convert_run = 0; };
- while ($convert_run) {
- sleep $CHECK_INTERVAL;
- &check_for_files;
- }
- exit 0;
- }
- print "Running skype...\n";
- $ENV{'LD_PRELOAD'} = $SKYPE_REC;
- $ENV{'SKYPE_REC_DIR'} = $OUTPUT_DIR;
- system $SKYPE;
- delete $ENV{'SKYPE_REC_DIR'};
- delete $ENV{'LD_PRELOAD'};
- print "Please wait while conversion process finishes...\n";
- kill 'TERM', $pid;
- my $ret_pid = wait;
- if ($ret_pid == -1) {
- print "ERROR: Couldn't find the conversion process, that's weird.\n";
- }
- print "Done\n";
- exit 0;
- sub check_for_files {
- my (@stamps, @files, $now_time);
- $now_time = time;
- opendir(DIR, $OUTPUT_DIR);
- my @files = grep /remote-\d+\.au/, readdir(DIR);
- closedir(DIR);
- foreach (@files) {
- if (-f "$OUTPUT_DIR/$_" && /remote-(\d+)\.au/) {
- push @stamps, $1;
- }
- }
- if (@stamps > 0) {
- &convert_file(@stamps);
- }
- }
- sub convert_file {
- my @stamps = @_;
- foreach my $stamp (@stamps) {
- my $remote = "$OUTPUT_DIR/remote-$stamp.au";
- my $local = "$OUTPUT_DIR/local-$stamp.au";
- my $conv_base = "$OUTPUT_DIR/conversation-$stamp";
- my ($year, $month, $day, $hour, $min, $sec) =
- $stamp =~ /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
- my $pretty = "$year-$month-$day $hour:$min:$sec";
- next if ($SORT_INTO_DIRS && -e "$OUTPUT_DIR/$year/$month/$day/conversation-$stamp.$type");
- next if (!$SORT_INTO_DIRS && -e "$conv_base.$type");
- print "$pretty: Converting conversation\n";
- unless (-e $remote && -e $local) {
- print "$pretty: Couldn't find both $remote and $local to mix together\n";
- next;
- }
- my $tmp = -s $remote;
- unless ($tmp != 0 && $tmp != 24) {
- print "$pretty: Not mixing, $remote appears to be empty\n";
- next;
- }
- $tmp = -s $local;
- unless ($tmp != 0 && $tmp != 24) {
- print "$pretty: Not mixing, $local appears to be empty\n";
- next;
- }
- if ($STEREO_MIX) {
- system "$SOX $remote -c 2 $remote.TMP.au pan -1 >/dev/null 2>&1";
- if ($? != 0) {
- print "$pretty: Error converting $remote to stereo\n";
- next;
- }
- system "$SOX $local -c 2 $local.TMP.au pan 1 >/dev/null 2>&1";
- if ($? != 0) {
- print "$pretty: Error converting $local to stereo\n";
- next;
- }
- system "$SOXMIX -v 1 $remote.TMP.au -v 1 $local.TMP.au -v 1 $conv_base.au >/dev/null 2>&1";
- if ($? != 0) {
- print "$pretty: Error mixing $remote and $local into $conv_base.au\n";
- next;
- }
- unlink "$remote.TMP.au", "$local.TMP.au" if ($CLEANUP_TEMP);
- }
- else {
- system "$SOXMIX $remote $local $conv_base.au >/dev/null 2>&1";
- if ($? != 0) {
- print "$pretty: Error mixing $remote and $local into $conv_base.au\n";
- next;
- }
- }
- system "$SOX $conv_base.au $conv_base.wav >/dev/null 2>&1";
- if ($? != 0) {
- print "$pretty: Error converting $conv_base.au into $conv_base.wav\n";
- next;
- }
- unlink "$conv_base.au" if ($CLEANUP_TEMP);
- if ($ENC_TYPE == 1) {
- system("$OGGENC $OGGENC_OPTS -o $conv_base.$type $conv_base.wav >/dev/null 2>&1");
- unlink "$conv_base.wav" if ($CLEANUP_TEMP);
- }
- elsif ($ENC_TYPE == 2) {
- system("$LAME $LAME_OPTS $conv_base.wav $conv_base.$type >/dev/null 2>&1");
- unlink "$conv_base.wav" if ($CLEANUP_TEMP);
- }
- print "$pretty: Created $conv_base.$type\n";
- unlink "$remote", "$local" if ($CLEANUP_ORIG);
- if ($SORT_INTO_DIRS) {
- if (-e "$OUTPUT_DIR/$year/$month/$day") {
- if (-d "$OUTPUT_DIR/$year/$month/$day") {
- `mv $conv_base.$type $OUTPUT_DIR/$year/$month/$day`;
- if ($? != 0) {
- print "$pretty: Couldn't move $conv_base.$type to $OUTPUT_DIR/$year/$month/$day\n";
- next;
- }
- }
- else {
- print "$pretty: $OUTPUT_DIR/$year/$month/$day exists but is not a".
- "directory, have you been screwing with things?\n";
- next;
- }
- }
- else {
- `mkdir -p $OUTPUT_DIR/$year/$month/$day`;
- if ($? != 0) {
- print "$pretty: Couldn't create directory $OUTPUT_DIR/$year/$month/$day\n";
- next;
- }
- `mv $conv_base.$type $OUTPUT_DIR/$year/$month/$day`;
- if ($? != 0) {
- print "$pretty: Couldn't move $conv_base.$type to $OUTPUT_DIR/$year/$month/$day\n";
- next;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement