It is currently Tue Sep 19, 2017 10:57 am

Newbie Log torrents to sql table

All times are UTC - 6 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Mon Nov 10, 2008 12:51 am   

Joined: Mon Nov 10, 2008 12:12 am
Posts: 1
I am seriously new to bash scripting but here is a rundown of what it does its still in the works but works great!

-checks if my usb is hooked up
-deletes the location from sql table it is marked with local or work as it refinds the file
-with the -w it will goto my friends pc through ssh run a similiar script download that to my computer and process it
-mplayer will take a screenshot of each video this goes with a php script I have to view what movies I have seen where they are etc(WOULD KILL TO BE ABLE TO RUN FROM MY WEBSITE! PHP WILL NOT ALLOW IT

-Second script
I have a script that works with midnight commander my wife hits f4 I hit f3 and it logs the movie as watched for us. This is because we always got confused what shows we had watched.

I was thinking of gutting this and writting it properly so more people could use it. It's actually extremely useful but as you can see very very ugly. You can adjust as needed and who knows maybe someone will want to run with this script.

# bash check if directory exists
if [ -d $directory ]; then
echo "Found bond"
echo "Bond is gone!"
exit 1
touch /tmp/query
rm /tmp/query
echo "DELETE FROM catalog WHERE file_name like '%/incomplete/%';" > /tmp/query
QUERY=`mysql -u root movies < /tmp/query`
touch /tmp/query
touch /tmp/file_list
touch /tmp/dir_list
rm /tmp/query
rm /tmp/file_list
rm /tmp/dir_list
cd ~/downloads/torrents/
#grab all movie files now
find -L . -name *.avi >> /tmp/file_list
find -L . -name *.mpg >> /tmp/file_list
find -L . -name *.vob >> /tmp/file_list
find -L . -name *.flv >> /tmp/file_list
find -L . -name *.r00 >> /tmp/file_list
find -L . -name *.wmv >> /tmp/file_list
find -L . -name *.AVI >> /tmp/file_list
find -L . -name *.MPG >> /tmp/file_list
find -L . -name *.VOB >> /tmp/file_list
find -L . -name *.FLV >> /tmp/file_list
find -L . -name *.WMV >> /tmp/file_list
find -L . -name *.MKV >> /tmp/file_list
find -L . -name *.mkv >> /tmp/file_list
# strip unsafe ' from file_list to prepare for sql
sed "s/'/ /g" -i /tmp/file_list
# strip local from all entries
echo "UPDATE catalog SET location='' WHERE location='local';" > /tmp/query
QUERY=`mysql -u root movies < /tmp/query`
rm /tmp/query
# re-add local to existing files
cat /tmp/file_list |while read line3; do
echo "UPDATE catalog SET location='local' WHERE file_name='${line3}';" >> /tmp/query
QUERY=`mysql -u root movies < /tmp/query`
rm /tmp/query
# add new entries to table
cat /tmp/file_list |while read line2; do
echo "INSERT INTO catalog (code ,friendly_name ,torrent_name,e_watched ,a_watched ,location ,file_name) VALUES (NULL , '', '', '0', '0', 'local', '${line2}');" > /tmp/query
QUERY=`mysql -u root movies < /tmp/query`
# add thumb to existing files
#if [ "$2" != "-s" ]; then
# cat /tmp/file_list |while read line8; do
# mplayer -ao null -really-quiet -brightness 10 -contrast 10 -ss 55 -vo jpeg -frames 1 "${line8}" < /dev/null > /dev/null 2>&1 &
# sleep 1
# parsed_line8="${line8/\'/ }"
# stripped_parsed_line8=${parsed_line8##*/}
# cp 0*.jpg "/var/www/mediamanager/thumbs/${stripped_parsed_line8}.jpg"
# rm 0*.jpg
# echo "UPDATE catalog SET thumb='${stripped_parsed_line8}.jpg' WHERE file_name='${parsed_line8}';" >> /tmp/query
# done
#QUERY=`mysql -u root movies < /tmp/query`
rm /tmp/query
# grab files from work
if [ "$1" = "-w" ]; then
# start out by deleting previous files
echo "DELETE FROM catalog where location='friend';" > /tmp/query
QUERY=`mysql -u root movies < /tmp/query`
rm /tmp/query
# go there and run this script now
ssh [email protected] friend_movie_indexer
# strip unsafe ' character
sed "s/\.\//WORK\/\/\//g" -i /tmp/friend_file_list
cat /tmp/work_file_list |while read line3; do
echo "INSERT INTO catalog (code ,friendly_name ,torrent_name,e_watched ,a_watched ,location ,file_name) VALUES (NULL , '', '', '0', '0', 'friend', '${line3}');" > /tmp/query
QUERY=`mysql -u root movies < /tmp/query`
rm /tmp/query


echo "select $FIELD from movies.catalog where file_name like '%$FILE_NAME%' and location = 'local';" > /tmp/query
RESULT=`mysql -u root movies < /tmp/query > /tmp/result`
cat /tmp/result |while read line; do
if [ "${line}" != "$FIELD" ] ; then
if [ "$EXACT_RESULT" = "0" ] ; then
echo "UPDATE movies.catalog SET $FIELD= '1' WHERE file_name like '%$FILE_NAME';" > /tmp/query_2
echo "now logging and playing movie"
RESULT_2=`mysql -u root movies < /tmp/query_2 > /tmp/result_2`
rm /tmp/query*
rm /tmp/result*
DISPLAY=:0.1 mplayer -fstype fullscreen -fs "$UNMODIFIED_FILE_NAME" < /dev/null > /dev/null 2>&1 &
exit 1
gxmessage -center -borderless -default okay "$FIELD is true exiting now"
rm /tmp/query*
rm /tmp/result*

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: No registered users and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group