Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions Linux/parse_srt.pl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/usr/bin/perl
#!/usr/bin/perl
#
# parse_srt.pl
# XBMC Language Filter
# XBMC Language Filter
#
# Created by Brock Haymond 9/6/12.
# Created by Brock Haymond 9/6/12.
# Copyright (c) 2012 Brock Haymond <http://brockhaymond.com>. All rights reserved.
#
# Perl script to search a subtitle.srt file for profanity and create an XBMC-compatible EDL file from the results found.
# You can call the perl script as follows:
#
# perl parse_srt.pl "subtitle_file.srt"
#
# Perl script to search a subtitle.srt file for profanity and create an XBMC-compatible EDL file from the results found.
# You can call the perl script as follows:
#
# perl parse_srt.pl "subtitle_file.srt"
#
# The "subtitle_file.edl" file will be output into the same directory as the original subtitle.srt file.
#

use Time::Seconds;

if($ARGV[$0] eq "") {
print "Usage: perl parse_srt.pl [subtitle.srt]\n";
print "Usage: perl parse_srt.pl --offset=seconds --pad=seconds [subtitle.srt]\n";
print "Output: subtitle.edl\n";
exit 1;
}
Expand All @@ -25,28 +27,37 @@
if(!open PROFM, "pmatch.txt") {print "Couldn't open profanities match file: $!.\r\n"; exit 1;}
@pmatch = <PROFM>;
chomp(@pmatch);
our %pmatchhash = map { $_ => 1 } @pmatch;
our %pmatchhash = map { $_ => 1 } @pmatch;
close(PROFM);

if(!open PROFC, "pcontains.txt") {print "Couldn't open profanities contains file: $!.\r\n"; exit 1;}
@pcontains = <PROFC>;
chomp(@pcontains);
chomp(@pcontains);
close(PROFC);

$edl = $ARGV[$0];

$offset = $ARGV[0];
$offset =~ s/--offset=//;
$offset = int($offset);

$pad = $ARGV[1];
$pad =~ s/--pad=//;
$pad = int($pad);

$file = $ARGV[2];
$edl = $file;
$edl =~ s/srt/edl/;

if(!open TXT, "$ARGV[$0]") {print "Couldn't open file '$ARGV[$0]:' $!.\r\n"; exit 1;}
if(!open TXT, "$file") {print "Couldn't open file '$file:' $!.\r\n"; exit 1;}
if(!open EDL, ">$edl") {print "$!\r\n"; exit 1;}

if($verbose) {print "Processing $ARGV[$0]\nWriting to $edl\n";}
if($verbose) {print "Processing $file\nWriting to $edl\n";}

undef $/;
$file = <TXT>;
$file = <TXT>;
$file =~ s/\r\n/\n/g;

my @block = split('\n\n', $file);
foreach $block (@block) {
foreach $block (@block) {
my @lines = split('\n', $block);
$block =~ s/^(?:.*\n){1,2}//;
$block =~ s/,|\.|\?|\!|"|#|:|\<.*?\>|\[(.*|.*\n.*)\]//g;
Expand All @@ -60,24 +71,28 @@
$found |= exists $pmatchhash{lc($_)} foreach (@words);

if($found) {
#print "$lines[1]\n$block\n\n";
$lines[1] =~ s/,/\./g;
my @times = split(' --> ', $lines[1]);
$start = parsetime($times[0]);
$end = parsetime($times[1]);
print EDL "$start \t$end \t1\n";
#print "$lines[1]\n$block\n\n";
$lines[1] =~ s/,/\./g;
my @times = split(' --> ', $lines[1]);
$start = parsetime($times[0], $offset - $pad);
$end = parsetime($times[1], $offset + $pad);
print EDL "$start\t$end\t1\r\n";
}
}

if($verbose) {print "Finished parsing $ARGV[$0]\n";}

sub parsetime {
my @time = split(':', $_[0]);
$time = $time[0]*3600 + $time[1]*60 + $time[2];
return sprintf "%.2f", $time;
my $offset = $_[1];
my @time = split(':', $_[0]);
$time = $time[0]*3600 + $time[1]*60 + $time[2] + $offset;
my $hours = int($time / 3600); $time = $time % 3600;
my $minutes = int($time / 60); $time = $time % 60;
my $seconds = $time;
return sprintf "%02d:%02d:%02d", $hours, $minutes, $seconds;
}
close(TXT);

close(TXT);
close(EDL);

if($verbose) {print "Closed $ARGV[$0]\nClosed $edl\n";}
29 changes: 18 additions & 11 deletions Linux/xbmclf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ then
echo "XBMC Language Filter by Brock Haymond (v1.0)"
echo ""
echo "Usage:"
echo " ./xbmclf [subtitle.srt] or [subtitles folder]"
echo " ./xbmclf [--offset=seconds] [--pad=seconds] [subtitle.srt] or [subtitles folder]"
echo ""
echo "Press enter to close."
read pause
Expand All @@ -34,29 +34,36 @@ echo "-------------------------------------"
NOW=$(date +"%r %m-%d-%Y")
echo "Logfile was generated by XBMC Language Filter at $NOW">~/"XBMC Language Filter.log"

PAD=0
OFFSET=0
INDEX=0
function RECURSE {
for FILE in "$@"
for ARG in "$@"
do
if [ -d "$FILE" ]
then
for F in "$FILE/"*
if [[ ${ARG:0:9} == '--offset=' ]]
then
OFFSET=`echo $ARG | sed 's/--offset=//'`
elif [[ ${ARG:0:6} == '--pad=' ]]
then
PAD=`echo $ARG | sed 's/--pad=//'`
elif [ -d "$ARG" ]
then
for F in "$ARG/"*
do
RECURSE "$F"

done
else
if [[ ${FILE: -4} == ".srt" ]]
elif [ -f "$ARG" ]
then
if [[ ${ARG: -4} == ".srt" ]]
then
echo "Processing "$FILE"..." | tee -a ~/"XBMC Language Filter.log"
NEW=$RESULT`perl parse_srt.pl "$FILE"`
echo "Processing "$ARG"..." | tee -a ~/"XBMC Language Filter.log"
NEW=$RESULT`perl parse_srt.pl --offset=$OFFSET --pad=$PAD "$ARG"`
if [ -z "$NEW" ]
then
INDEX=`expr $INDEX + 1`
else
RESULT="$NEW"
fi

fi
fi
done
Expand Down
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
XBMC Language Filter
====================

v1.0 release, by Brock Haymond

Welcome to XBMC Language Filter v1.0 public release! This version is compatible with the
current version of XBMC, Eden 11.0. It should continue to be compatible moving forward
with any revision of XBMC, but is not backwards compatible with older versions.

Visit [brockhaymond.com](http://brockhaymond.com) for more info about me and my software.

Description
-----------

XBMC Language Filter is a simple perl script creates an edit decision list, or EDL file,
from a subtitles file. The script can accept any given subtitle (SRT) file or a directory
of SRT files. The output is an EDL file (or files) that matches the name of the original
subtitle supplied, placed in the same location as the original subtitle file.

The XBMC "MPlayer" EDL file structure that this script outputs is:

```
[starting time] [ending time] [action]
00:07:23 00:07:28 1
```

The action to take is "1" for mute. The "MPlayer" file structure is further explained
[here](http://wiki.xbmc.org/index.php?title=Edit_decision_list#MPlayer_EDL),
along with other supported actions (such as removing a scene completely).

Download
--------

I have provided pre-compiled versions for each operating system on my website.
The code provided on Github is meant for development purposes only.

[http://brockhaymond.com/Software.html](http://brockhaymond.com/Software.html)

How to Use
----------

1. Make sure your subtitle file and your movie are exactly IN SYNC. This means that when
your subtitles show text, that text is being spoken at the exact same time. If this is not
the case, XBMC will not be in sync to mute profanity at the right times during the movie.

2. Run XBMC Language Filter and supply the subtitle file for the movie you desire to edit.
For Linux, this is by command line only. An EDL file will be produced in the same location
as the supplied subtitle file.

3. Move the EDL file that XBMC Language Filter produced into the same directory as the movie.

4. The EDL file and movie have to have the exact same name. If they do not have the SAME NAME
and are located in the SAME DIRECTORY, XBMC will not find the EDL file when the movie is
played and the movie will not be edited.

5. Enjoy your movie edited!

Caution
-------

This project is aimed at editing profanity from movies. For this purpose lists of profane
words have been enumerated in files in order to define search criteria. Viewer discretion is
advised to these lists and should be limited to "must see" only.

Problems?
---------

If you run into any profanities that XBMC Language Filter isn't detecting, or for any other
problems please email me or submit a bug report on Github!

[slowfoxtrotdesign@gmail.com](mailto:slowfoxtrotdesign@gmail.com)
[https://github.com/Slowfoxtrot/XBMC-Language-Filter](https://github.com/Slowfoxtrot/XBMC-Language-Filter)

One known issue is if the subtitle is in UTF-16 encoding the EDL file will be empty when created.
You will need to open the subtitle file and save it as UTF-8 and then resubmit it to the filter.

Enjoy!

Brock Haymond
Slowfoxtrot Design
91 changes: 0 additions & 91 deletions README.txt

This file was deleted.