Untitled

proton252 tarafından 2 Ay önce Bash dilinde yazıldı.
URL http://www.lpaste.com/view/88033749
Yapıştırmayı İndir ve ya Metin Olarak Göster — Yapıştırmayı tarayıcıya tam genişlet | Görünüm Ayarlarını Değiştir
  1. #!/bin/bash
  2.  
  3. #Script Type: Nautilus Script
  4. #Title: Extract Audio
  5. #Dependencies: ffmpeg, zenity
  6. #Author: jim lewellyn (styyle14)
  7.  
  8. #General Info:
  9. #In naultius scripts, the variable $1 is given to the first file selected, then variable number increases as order of files selected does
  10. #In naultius scripts, the variable $# is given to the number of files selected
  11. #The usage of the action: "shift" decreases $# by 1 makes each variable shift down 1 (e.g. the contents of variable $2 become the contents of variable $1 and so forth)
  12. #zenity is used to create pop-up windows to guide the user through the process (usage is fairly obvious)
  13.  
  14. #this title will be used for all zenity pop-up windows
  15. title="Extract Audio"
  16.  
  17. #this part tests to see if ffmpeg is installed, andif not close the script with an error
  18. test_ffmpeg=`which ffmpeg | grep -c "ffmpeg"`
  19. if [ "$test_ffmpeg" -eq "0" ]; then
  20.         zenity --error --title="::Error::" --text="You do not have ffmpeg installed.
  21.         This package is a dependency of this script.
  22.         Please install ffmpeg and try again."
  23.         exit
  24. fi
  25.  
  26. #this is necessary to handle files with spaces in the name
  27. #default is IFS=$" \t\n" (notice the literal space before "\t")
  28. IFS=$'\t\n'
  29.  
  30. #this variable defines the text to be used for selections in zenity windows where the user will then type in their own input option
  31. option1="Define your own"
  32.  
  33. #these options define the height and width of each zenity window so that the ok button appears in the same place for all windows
  34. #not used on windows where user input his/her own value
  35. height="500"
  36. width="500"
  37.  
  38. #these functions create zenity windows to help define the name, format, bitrate, and number of channels
  39. define_name (){
  40.         filename=${1%.*}
  41.         name=`zenity --height="$height" --width="$width" --title="$title" --text="How would you like to name your file?" --list --radiolist --column="" \
  42.                 --column="Name" \
  43.                 TRUE "$option1" \
  44.                 FALSE "$filename" `
  45.  
  46.         if [ "$name" = "$option1" ]; then
  47.                 name=`zenity --title="$title" --text="Name of new file (without extension):" --entry `
  48.         fi
  49.  
  50.         if [ ! "$name" ]; then
  51.                 zenity --error --title="::Error::" --text="Please choose a name for the new audio file and try again."
  52.                 exit
  53.         fi
  54. }
  55. define_format (){
  56.         format=`zenity --height="$height" --width="$width" --title="$title" --text="Which audio format would you like to convert to?" --list --radiolist --column="" \
  57.                 --column="Name" \
  58.                 TRUE "mp3" \
  59.                 FALSE "ogg" \
  60.                 FALSE "flac" \
  61.                 FALSE "wav" \
  62.                 FALSE "wma" \
  63.                 FALSE "$option1" `
  64.  
  65.         if [ "$format" = "$option1" ]; then
  66.                 format=`zenity --title="$title" --text="Type the extension of the audio format you wish to use:
  67.                 (Must be ffmpeg compatible)" --entry `
  68.         fi
  69.  
  70.         if [ ! "$format" ]; then
  71.                 zenity --error --title="::Error::" --text="Please choose a format for the new audio file and try again."
  72.                 exit
  73.         fi
  74. }
  75. define_bitrate (){
  76.         bitrate=`zenity --height="$height" --width="$width" --title="$title" --text="At what bitrate would you like to encode this file?
  77.         Currently this script only handles mp3 and wma bitrates.
  78.         (The other formats have VBR's)" --list --radiolist --column="" \
  79.         --column="Name" \
  80.         FALSE "64" \
  81.         TRUE "128" \
  82.         FALSE "192" \
  83.         FALSE "240" \
  84.         FALSE "320" \
  85.         FALSE "$option1" `
  86.  
  87.         if [ "$bitrate" = "$option1" ]; then
  88.                 bitrate=`zenity --title="$title" --text="Type the bitrate you wish to use:
  89.         (Must be ffmpeg compatible)" --entry `
  90.         fi
  91.  
  92.         if [ ! "$bitrate" ]; then
  93.                 zenity --error --title="::Error::" --text="Please choose a bitrate for the new audio file and try again."
  94.                 exit
  95.         fi
  96. }
  97. define_channels (){
  98.         channels=`zenity --height="$height" --width="$width" --title="$title" --text="How many channels would you like your file to have?" --list --radiolist --column="" \
  99.         --column="Name" \
  100.         FALSE "1" \
  101.         TRUE "2" \
  102.         FALSE "$option1" `
  103.  
  104.         if [ "$channels" = "$option1" ]; then
  105.                 bitrate=`zenity --title="$title" --text="Type the number of channels you wish to use:
  106.         (Must be ffmpeg compatible)" --entry `
  107.         fi
  108.  
  109.         if [ ! "$channels" ]; then
  110.                 zenity --error --title="::Error::" --text="Please choose a number of channels for the new audio file and try again."
  111.                 exit
  112.         fi
  113. }
  114.  
  115. #this is the primary function used in this script with options for number of channels, bitrate, name, and format
  116. encode_audio (){
  117.         ffmpeg -i "$1" -vn -ac "$channels" -ab "$bitrate" "$name"."$format"
  118. }
  119.  
  120. #this large while loop encompasses the rest of the script to allow for different options to be used on consecutive files if multiple ones are selected
  121. while [ 'true' ]; do
  122.  
  123. #makes sure at least 1 file was selected in the nautilus window
  124. if [ $# -eq 0 ]; then
  125.         zenity --error --title="::Error::" --text="You must select at least 1 file."
  126.         exit 1
  127. fi
  128.  
  129. #these variables define what is meant by default
  130. #if changed here, their values should be updated in the first zenity window
  131. format="mp3"
  132. channels="2"
  133. bitrate="128"
  134.  
  135. #these variables define what text appears in the encoding options window
  136. #encode_type1 makes all selected files pass through the default settings listed above
  137. encode_type1="All: Default Settings: Same Name As Original"
  138. #encode_type2 makes all selected files pass through the default settings listed above while each time allowing the user to choose a name for the new file
  139. encode_type2="All: Default Settings: Choose Custom Name For Each File"
  140. #encode_type3 encodes the first selected file with default settings and then removes it from the list of selected
  141. encode_type3="Single: Default Settings: Same Name As Original"
  142. #encode_type4 allows for specific renaming of the the first selected file, encodes it with default settings, and removes it from the list of selected
  143. encode_type4="Single: Default Settings: Choose Custom Name For File"
  144. #encode_type5 allows the user to select options that will be used for all files selected while automatically naming the newly created files after the original
  145. encode_type5="All: Custom Settings: Same Name As Original"
  146. #encode_type6 allows the user to select options that will be used for all files selected while allowing the user to name each file before it is encoded
  147. encode_type6="All: Custom Settings: Choose Custom Name For File"
  148. #encode_type7 gives the user the ability to configure all options on a single file
  149. encode_type7="Single: Custom Settinges: Choose Custom Name For File"
  150. #this option window allows the user to choose how many and how they want their files converted
  151.  
  152. encode_type=`zenity --height="$height" --width="$width" --title="$title" --text="Would you like to use the default encoding options or choose custom options?
  153. (Default options are: $format format, $bitrate kb/s, $channels channels)
  154. Next File: $1
  155. Files Left To Extract From: $#" --list --radiolist --column="" \
  156. --column="Name" \
  157. TRUE "$encode_type1" \
  158. FALSE "$encode_type2" \
  159. FALSE "$encode_type3" \
  160. FALSE "$encode_type4" \
  161. FALSE "$encode_type5" \
  162. FALSE "$encode_type6" \
  163. FALSE "$encode_type7" `
  164.  
  165. #if cancel in the first window, close script without error message
  166. if [ ! "$encode_type" ]; then
  167.         exit
  168. fi
  169.  
  170. #encode_type1 actions
  171. if [ "$encode_type" = "$encode_type1" ]; then
  172.         while  [ $# -gt 0 ]; do
  173.                 filename=${1%.*}
  174.                 name="$filename"
  175.                 encode_audio $1
  176.                 shift
  177.         done
  178.         exit
  179. fi
  180.  
  181. #encode_type2 actions
  182. if [ "$encode_type" = "$encode_type2" ]; then
  183.         while  [ $# -gt 0 ]; do
  184.                 define_name $1
  185.                 encode_audio $1
  186.                 shift
  187.         done
  188.         exit
  189. fi
  190.  
  191. #encode_type3 actions
  192. if [ "$encode_type" = "$encode_type3" ]; then
  193.         filename=${1%.*}
  194.         name="$filename"
  195.         encode_audio $1
  196.         shift
  197. fi
  198.  
  199. #encode_type4 actions
  200. if [ "$encode_type" = "$encode_type4" ]; then
  201.         define_name $1
  202.         encode_audio $1
  203.         shift
  204. fi
  205.  
  206. #encode_type5 actions
  207. if [ "$encode_type" = "$encode_type5" ]; then
  208.         define_format
  209.         define_bitrate
  210.         define_channels
  211.         while  [ $# -gt 0 ]; do
  212.                 filename=${1%.*}
  213.                 name="$filename"
  214.                 encode_audio $1
  215.                 shift
  216.         done
  217.         exit
  218. fi
  219.  
  220. #encode_type6 actions
  221. if [ "$encode_type" = "$encode_type6" ]; then
  222.         define_format
  223.         define_bitrate
  224.         define_channels
  225.         while  [ $# -gt 0 ]; do
  226.                 define_name $1
  227.                 encode_audio $1
  228.                 shift
  229.         done
  230.         exit
  231. fi
  232. #encode_type7 actions
  233. if [ "$encode_type" = "$encode_type7" ]; then
  234.         define_name $1
  235.         define_format
  236.         define_bitrate
  237.         define_channels
  238.         encode_audio $1
  239.         shift
  240. fi
  241.  
  242. #if the script has encoded all selected files, this will terminate the script
  243. if [ $# -le 0 ]; then
  244.         exit
  245. fi
  246.  
  247. done
  248. exit

"Untitled" Yapıştırmasına Cevap

Yukarıdaki yapıştırmaya buradan cevap yazabilirsiniz

Bir snipurl oluştur

Özel Yap

Akıllı hissediyor musunuz? Bazı gelişmiş ayarları yapın.