Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2011
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.85 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Usage
  4. if [ $# -ne 1 ]
  5. then
  6.   echo Usage : pls2dir FILE
  7.   exit
  8. fi
  9.  
  10. # Make directory
  11. dir=${1/.pls/}
  12.  
  13. if [ ! -d "$dir" ]
  14. then
  15.   echo -n "Make directory : "
  16.   echo $dir
  17.   mkdir "$dir"
  18. else
  19.   echo "Directory already exist"
  20. fi
  21.  
  22. # File for list of musics with some filters
  23. out=$(mktemp)
  24. grep File "$1" | cut -d"=" -f2 | sed 's/file:\/\///' > $out
  25.  
  26. out2=$(mktemp)
  27.  
  28. # Copy each music to the directory
  29. while read line
  30. do
  31.   printf "%b\n" "${line//%/\\x}"
  32. done < $out > $out2
  33.  
  34. while read line
  35. do
  36.   cp "$line" "$dir"
  37. done < $out2
  38.  
  39. #### Semplification ####
  40. #
  41. # You can rid of the temp files by combining the commands like this:
  42. #
  43. #
  44. # while read line; do
  45. #        file=$( printf "%b\n" "${line//%/\\x}" );
  46. #        cp "$file" "$dir";
  47. # done < <( grep File "$1" | cut -d"=" -f2 | sed 's/file:\/\///' )
  48. #
  49. # NOT TESTED :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement