Skip to content

Commit

Permalink
Rewrite in an effort to be more readable. Summary:
Browse files Browse the repository at this point in the history
* Reuse getConfig (though it'll always fall back to /etc)
* Seperate filters (sorry for the long lines)
  • Loading branch information
Tom Vincent committed Sep 3, 2010
1 parent 6482f65 commit ed687cd
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions ytmpd
@@ -1,18 +1,24 @@
#!/bin/sh

source /etc/ytmp.conf
. /usr/lib/tlvince/getConfig.sh
. $(getConfig ytmp)

if ! [ -n "$INTERFACE" ]; then echo "INTERFACE not set in /etc/ytmp.conf" >&2; exit 1; fi
[ $INTERFACE ] || {
echo "$0: error: INTERFACE not set in /etc/ytmp.conf" >&2
exit 1
}

rm /tmp/ytmpurls 2> /dev/null

ngrep -W byline -qil 'get|session' tcp dst port 80 -d $INTERFACE | egrep --line-buffered -i "(get\ /watch|GET \/[0-9]* .*|^session_token.*)" | sed --unbuffered -e 's/GET \/ HTTP\/1\.1\.//' -e 's/.*video_id%22%3A%22\([_a-zA-Z0-9-]\{11,11\}\).*/host=youtube\nid=\1/' -e 's/.*\/\([0-9]*\) .*/host=vimeo\nid=\1/g' -e 's/.*=\([_a-zA-Z0-9-]\{11,11\}\)[ &].*/host=youtube\nid=\1/' >> /tmp/ytmpurls &
FILTERS="
s/GET \/ HTTP\/1\.1\.// # Unwanted GET headers
s/.*\/\([0-9]*\) .*/host=vimeo\nid=\1/g # Vimeo video ID
s/.*=\([_a-zA-Z0-9-]\{11,11\}\)[ &].*/host=youtube\nid=\1/ # Youtube video ID
s/.*video_id%22%3A%22\([_a-zA-Z0-9-]\{11,11\}\).*/host=youtube\nid=\1/ # Youtube channel video ID
"

exit 0
ngrep -W byline -qil 'get|session' tcp dst port 80 -d "$INTERFACE" | \
egrep --line-buffered -i "(get\ /watch|GET \/[0-9]* .*|^session_token.*)" | \
sed --unbuffered -e "$FILTERS" >> /tmp/ytmpurls &

#'-e 's/GET \/ HTTP\/1\.1\.//'' -> get rid of unwanted 'GET / HTTP/1.1.' matches
#'-e 's/.*\/\([0-9]*\) .*/host=vimeo\nid=\1/g'' -> filter vimeo video ids
#'-e 's/.*=\([_a-zA-Z0-9-]\{11,11\}\)[ &].*/host=youtube\nid=\1/' -> filter
# youtube video ids
#'-e 's/.*video_id%22%3A%22\([_a-zA-Z0-9-]\{11,11\}\).*/host=youtube\nid=\1/''
# -> filter youtube channel video ids
exit 0

0 comments on commit ed687cd

Please sign in to comment.