Author Topic: Help me editing unrar script for qBitt  (Read 2485 times)

pyed

  • Newbie
  • *
  • Posts: 14
  • Karma: +3/-0
    • View Profile
Help me editing unrar script for qBitt
« on: November 01, 2012, 05:52:54 AM »
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]
#!/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 Edit: November 01, 2012, 05:55:00 AM by pyed »

pyed

  • Newbie
  • *
  • Posts: 14
  • Karma: +3/-0
    • View Profile
Re: Help me editing unrar script for qBitt
« Reply #1 on: November 01, 2012, 07:01:29 AM »
Well, I tried to do this but no luck

on qBittorrent i'll have this as my external program link
Code: [Select]
/Users/USERNAME/unrar.sh "%n" "%f"
and i edited my code to this

Code: [Select]
#!/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 Edit: November 01, 2012, 07:05:21 AM by pyed »

dinjo

  • Veteran
  • ***
  • Posts: 88
  • Karma: +2/-0
    • View Profile
Re: Help me editing unrar script for qBitt
« Reply #2 on: November 15, 2013, 04:37:35 AM »
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]
#!/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