Help me editing unrar script for qBitt

MAC OS X specific questions, problems.
Post Reply
pyed

Help me editing unrar script for qBitt

Post by pyed »

Hi, I used to be Transmission user, but today I tried qBittorrent and i really liked it, and i'm willing to use it as my main bittorrent client, in fact i deleted Transmission  ;D

But I've this really useful script that I make Transmission call when download complete and it will unrar the files i just downloaded using Mac app called 'Stuffit Expander',  i tried that script with qBittorrent but it doesn't work  :'( i think it just need little editing but because of my lack of knowledge in this field i couldn't do it my self, I googled for scripts for qBittorrent that would do the same job, but no luck  :(

can someone help with this ? here's the script

Code: Select all

#!/bin/sh

exec osascript <<END

on reformat(theName)
   set newName to ""
   repeat with i from 1 to length of theName
      if ((character i of theName) is "/") then
         set newName to newName & ":"
      else
         set newName to newName & character i of theName
      end if
   end repeat
   return newName
end reformat

tell application "Finder"
   set found_rar to false
   set str to "$TR_TORRENT_DIR" & ":" & "$TR_TORRENT_NAME"
   set str to my reformat(str)
   set source_folder to "OSX" & str & ":"
   
   set item_list to source_folder
   set src_folder to item_list
   set the the_items to list folder item_list without invisibles
   set item_list to item_list as string
   repeat with i from 1 to number of items in the the_items
      set the_item to item i of the the_items
      set the_item to (item_list & the_item) as alias
      set this_info to info for the_item
      if name extension of this_info is "rar" then
         try
            tell application "StuffIt Expander"
               expand the_item
               quit
            end tell
            set found_rar to true
         end try
      end if
   end repeat
   if found_rar then 
      repeat with i from 1 to number of items in the the_items
         set the_item to item i of the the_items
         set the_item to (item_list & the_item) as alias
         
         --Permanently remove it
         set posPath to POSIX path of the_item
         do shell script "rm -rf \"" & posPath & "\""
         
         --Or send to trash
         --delete file the_item
      end repeat
   end if
   
end tell
END
thanks
Last edited by pyed on Thu Nov 01, 2012 4:55 am, edited 1 time in total.
pyed

Re: Help me editing unrar script for qBitt

Post by pyed »

Well, I tried to do this but no luck

on qBittorrent i'll have this as my external program link

Code: Select all

/Users/USERNAME/unrar.sh "%n" "%f"
and i edited my code to this

Code: Select all

#!/bin/sh

exec osascript <<END

tname=$1
tdir=$2


on reformat(theName)
   set newName to ""
   repeat with i from 1 to length of theName
      if ((character i of theName) is "/") then
         set newName to newName & ":"
      else
         set newName to newName & character i of theName
      end if
   end repeat
   return newName
end reformat

tell application "Finder"
   set found_rar to false
   set str to "$tdir" & ":" & "$tname"
   set str to my reformat(str)
   set source_folder to "OSX" & str & ":"
   
   set item_list to source_folder
   set src_folder to item_list
   set the the_items to list folder item_list without invisibles
   set item_list to item_list as string
   repeat with i from 1 to number of items in the the_items
      set the_item to item i of the the_items
      set the_item to (item_list & the_item) as alias
      set this_info to info for the_item
      if name extension of this_info is "rar" then
         try
            tell application "StuffIt Expander"
               expand the_item
               quit
            end tell
            set found_rar to true
         end try
      end if
   end repeat
   if found_rar then 
      repeat with i from 1 to number of items in the the_items
         set the_item to item i of the the_items
         set the_item to (item_list & the_item) as alias
         
         --Permanently remove it
         set posPath to POSIX path of the_item
         do shell script "rm -rf \"" & posPath & "\""
         
         --Or send to trash
         --delete file the_item
      end repeat
   end if
   
end tell
END

Last edited by pyed on Thu Nov 01, 2012 6:05 am, edited 1 time in total.
dinjo

Re: Help me editing unrar script for qBitt

Post by dinjo »

Bump can use this code but the problem is when sub directories are there in the torrent it does not extracts files correctly, if anyone has working code then please share

Code: Select all

#!/bin/bash

LOG_FILE=/var/log/unrar.log
TORRENT_DIR=$1
TR_TORRENT_NAME=$2

NOW=$(date +%Y-%m-%d\ %H:%M:%S)

SRC_DIR="${TORRENT_DIR}/${TR_TORRENT_NAME}"
DEST_DIR="${TORRENT_DIR}/${TR_TORRENT_NAME}"

cd $SRC_DIR

IFS=$'\n'

unset RAR_FILES i

for RAR_FILE in $( find "$SRC_DIR" -iname "*.rar" ); do

if [[ $RAR_FILE =~ .*part.*.rar ]]; then

  if [[ $RAR_FILE =~ .*part0*1.rar ]]; then

    RAR_FILES[i++]=$RAR_FILE

  fi

done

unset IFS

if [ ${#RAR_FILES} -gt 0 ]; then

for RAR_FILE in "${RAR_FILES[@]}"; do
  unrar x -inul "$RAR_FILE" "$DEST_DIR"
done
echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE

fi

fi
Post Reply