Advertisement
Guest User

Bash Script to Stream line downloading Stuff

a guest
Jan 13th, 2025
736
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | Source Code | 1 0
  1. #!/usr/bin/env bash
  2. # by austin staton 2024
  3. # downloadthings script
  4.  
  5. # Function to install a single dependency using common package managers
  6. install_dependency() {
  7. local dep="$1"
  8. echo -e "\e[94m$dep is not installed. Installing...\e[0m"
  9.  
  10. if command -v apt &>/dev/null; then
  11. sudo apt update && sudo apt install -y "$dep"
  12. elif command -v dnf &>/dev/null; then
  13. sudo dnf install -y "$dep"
  14. elif command -v yum &>/dev/null; then
  15. sudo yum install -y "$dep"
  16. elif command -v pacman &>/dev/null; then
  17. sudo pacman -Sy --noconfirm "$dep"
  18. elif command -v zypper &>/dev/null; then
  19. sudo zypper install -y "$dep"
  20. elif command -v brew &>/dev/null; then
  21. brew install "$dep"
  22. else
  23. echo -e "\e[91mPackage manager not recognized. Please install $dep manually.\e[0m"
  24. exit 1
  25. fi
  26. }
  27.  
  28. # Function to check and install dependencies
  29. check_dependencies() {
  30. echo -e "\e[94mChecking for required dependencies...\e[0m"
  31.  
  32. # List all dependencies here
  33. for dep in yt-dlp wget wkhtmltopdf aria2 httrack; do
  34. if ! command -v "$dep" &>/dev/null; then
  35. install_dependency "$dep"
  36. fi
  37. done
  38.  
  39. echo -e "\e[94mAll dependencies are installed! Getting things ready...\e[0m"
  40. }
  41.  
  42. # Functions for various tasks
  43. grabvideoBest() {
  44. yt-dlp --console-title --geo-bypass --no-check-certificates -v \
  45. -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' "$1"
  46. }
  47.  
  48. grabAudioBest() {
  49. yt-dlp --console-title --geo-bypass --no-check-certificates -v -x \
  50. --audio-format best --audio-quality 0 "$1"
  51. }
  52.  
  53. PlaylistgrabvideoBest() {
  54. yt-dlp --console-title --geo-bypass --no-check-certificates -v \
  55. -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' --yes-playlist "$1"
  56. }
  57.  
  58. PlaylistgrabAudioBest() {
  59. yt-dlp --console-title --geo-bypass --no-check-certificates -v -x \
  60. --audio-format best --audio-quality 0 --yes-playlist "$1"
  61. }
  62.  
  63. grabwebpage() {
  64. wget -p -r --html-extension --convert-links -E -k -l 1 -np "$1"
  65. }
  66.  
  67. grabwebpagePlus() {
  68. local url="$1"
  69. # Remove trailing slash
  70. url="${url%/}"
  71.  
  72. # Derive a folder name from the URL
  73. local folderName
  74. folderName=$(basename "$url")
  75.  
  76. # If empty, use fallback
  77. if [ -z "$folderName" ]; then
  78. folderName="downloaded_site"
  79. fi
  80.  
  81. wget -p -r --html-extension --convert-links -E -k -l 1 -np \
  82. -P "./$folderName" "$url" && \
  83. wkhtmltopdf "$url" "./$folderName/${folderName}.pdf"
  84. }
  85.  
  86. grabWithAria2() {
  87. aria2c -x 16 "$1"
  88. }
  89.  
  90. grabWebsiteHTTrack() {
  91. httrack "$1" -O ./downloaded_sites
  92. }
  93.  
  94. # New function for simply downloading an image
  95. grabImageWithWget() {
  96. local url="$1"
  97. echo -e "\e[94mDownloading image from URL: $url\e[0m"
  98. wget -O downloaded_image.jpg "$url"
  99. echo -e "\e[94mImage downloaded as downloaded_image.jpg\e[0m"
  100. }
  101.  
  102. # Updated 'explain_options' with color codes and new option #9
  103. explain_options() {
  104. echo -e "\e[94mExplanation of Options:\e[0m"
  105. echo -e "\e[94m1. Download a single video: Download the best quality video using yt-dlp.\e[0m"
  106. echo -e "\e[94m2. Download a single audio file: Extract and download the best audio format using yt-dlp.\e[0m"
  107. echo -e "\e[94m3. Download a playlist of videos: Download a playlist of videos using yt-dlp.\e[0m"
  108. echo -e "\e[94m4. Download a playlist of audio files: Extract audio from a playlist using yt-dlp.\e[0m"
  109. echo -e "\e[94m5. Download a webpage (basic): Save a webpage using wget.\e[0m"
  110. echo -e "\e[94m6. Download a webpage and convert it to PDF: Use wget and wkhtmltopdf.\e[0m"
  111. echo -e "\e[94m7. Download using aria2: Download files with high-speed segmentation.\e[0m"
  112. echo -e "\e[94m8. Mirror a website with HTTrack: Download an entire website for offline browsing.\e[0m"
  113. echo -e "\e[94m9. Download an image using wget: Retrieve a remote image URL and save it locally.\e[0m"
  114. echo -e "\e[31m10. Exit: Exit the script.\e[0m"
  115.  
  116. echo -e "\n\e[33m---- List of Functions Used in This Script ----\e[0m"
  117. echo -e "\e[92m- check_dependencies # Checks and installs dependencies\n\
  118. - grabvideoBest # Downloads best-quality video using yt-dlp\n\
  119. - grabAudioBest # Downloads best-quality audio using yt-dlp\n\
  120. - PlaylistgrabvideoBest # Downloads a playlist of best-quality videos\n\
  121. - PlaylistgrabAudioBest # Downloads a playlist of best-quality audio\n\
  122. - grabwebpage # Downloads a webpage using wget\n\
  123. - grabwebpagePlus # Downloads a webpage + converts it to PDF\n\
  124. - grabWithAria2 # Downloads a file using aria2 with segmentation\n\
  125. - grabWebsiteHTTrack # Mirrors a website with HTTrack\n\
  126. - grabImageWithWget # Downloads an image from a URL\n\
  127. - explain_options # Shows this explanation of options\n\
  128. - main_menu # Displays the main menu options\e[0m"
  129. }
  130.  
  131. main_menu() {
  132. echo -e "\e[32mWelcome to Media Downloader slash Download Things Script lol\e[0m"
  133. echo -e "\e[33mNOTE: For some downloads, you might need to use a VPN. Ensure your VPN is active if necessary.\e[0m"
  134. echo -e "\e[94mPlease select an option:\e[0m"
  135. echo -e "\e[94m1. Download a single video\e[0m"
  136. echo -e "\e[94m2. Download a single audio file\e[0m"
  137. echo -e "\e[94m3. Download a playlist of videos\e[0m"
  138. echo -e "\e[94m4. Download a playlist of audio files\e[0m"
  139. echo -e "\e[94m5. Download a webpage (basic)\e[0m"
  140. echo -e "\e[94m6. Download a webpage and convert that webpage to PDF as well\e[0m"
  141. echo -e "\e[94m7. Download using aria2\e[0m"
  142. echo -e "\e[94m8. Mirror a website with HTTrack\e[0m"
  143. echo -e "\e[94m9. Download an image using wget\e[0m"
  144. echo -e "\e[94m10. Explain each option\e[0m"
  145. echo -e "\e[31m11. Exit\e[0m"
  146. read -rp "Enter your choice (1-11): " choice
  147.  
  148. case $choice in
  149. 1)
  150. read -rp "Enter video URL: " url
  151. grabvideoBest "$url"
  152. ;;
  153. 2)
  154. read -rp "Enter audio URL: " url
  155. grabAudioBest "$url"
  156. ;;
  157. 3)
  158. read -rp "Enter playlist URL: " url
  159. PlaylistgrabvideoBest "$url"
  160. ;;
  161. 4)
  162. read -rp "Enter playlist URL: " url
  163. PlaylistgrabAudioBest "$url"
  164. ;;
  165. 5)
  166. read -rp "Enter webpage URL: " url
  167. grabwebpage "$url"
  168. ;;
  169. 6)
  170. read -rp "Enter webpage URL: " url
  171. grabwebpagePlus "$url"
  172. ;;
  173. 7)
  174. read -rp "Enter file URL: " url
  175. grabWithAria2 "$url"
  176. ;;
  177. 8)
  178. read -rp "Enter website URL to mirror: " url
  179. grabWebsiteHTTrack "$url"
  180. ;;
  181. 9)
  182. echo -e "\e[94mEnter image file URL:\e[0m"
  183. read -rp "" imgURL
  184. grabImageWithWget "$imgURL"
  185. ;;
  186. 10)
  187. explain_options
  188. ;;
  189. 11)
  190. echo -e "\e[92mExiting. Goodbye!\e[0m"
  191. exit 0
  192. ;;
  193. *)
  194. echo -e "\e[91mInvalid choice. Please try again.\e[0m"
  195. main_menu
  196. ;;
  197. esac
  198. }
  199.  
  200. # Start script
  201. check_dependencies
  202. main_menu
  203.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement