Various compilation scripts & patches for Linux programs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/bin/env bash
  2. # Download multiple Youtube videos and convert them
  3. # Copyright (C) 2019 Pekka Helenius
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ##############################################################################
  18. # Requirements: youtube-dl, ffmpeg (with appropriate codec support)
  19. # Usage: youtubedl <video_1_url> <video_2_url> ... <video_n_url>
  20. ########################################################
  21. DOWNLOAD_DIR=$HOME/Videos
  22. ########################################################
  23. echo -e "\nNumber of videos:\t$#"
  24. echo -e "Download destination:\t$DOWNLOAD_DIR"
  25. CNT=0
  26. for p in ${@}; do
  27. VIDEOARRAY[$CNT]=$p
  28. for video_url in "${VIDEOARRAY[$CNT]}"; do
  29. echo -e "\n[$((1 + $CNT))] Video download URL:\t$video_url"
  30. read INPUT_FILENAME <<< $(youtube-dl --get-filename --no-warnings --restrict-filenames -o "%(title)s.%(ext)s" $video_url | sed 's/\.[^.]*$//')
  31. if [[ ! -z $INPUT_FILENAME ]]; then
  32. echo -e "[$((1 + $CNT))] Video name:\t\t$(echo $INPUT_FILENAME)"
  33. youtube-dl --restrict-filenames -o "$DOWNLOAD_DIR/%(title)s.%(ext)s" $video_url
  34. #Sometimes we get invalid suffix for a file with youtube-dl name command (for example mkv file is stated as mp4 by youtube-dl). To circumvent this problem, find the real file with correct suffix and add it to an array for ffmpeg to process
  35. TRUNAME=$(ls $DOWNLOAD_DIR | grep "$INPUT_FILENAME")
  36. VIDEONAMES[$CNT]=$TRUNAME
  37. fi
  38. done
  39. let CNT++
  40. done
  41. for converted in $(echo "${VIDEONAMES[*]}"); do
  42. echo -e "Converting $converted"
  43. OUTPUT_FILEFORMAT='mp4'
  44. OUTPUT_FILE=$(echo "$converted" | sed "s/\.\w*$/-converted.$OUTPUT_FILEFORMAT/")
  45. #This makes sure we use mp4 suffix
  46. OUTPUT_FILE_AFTER=$(echo "$converted" | sed "s/\.\w*$/.$OUTPUT_FILEFORMAT/")
  47. ffmpeg -i "$DOWNLOAD_DIR/$converted" -acodec libopus -strict -2 -vcodec libx265 -pix_fmt yuv420p -x265-params crf=28:keyint=240:min-keyint=20 -preset:v veryslow -y "$DOWNLOAD_DIR/$OUTPUT_FILE"
  48. rm $DOWNLOAD_DIR/$converted
  49. echo -e "\n[$CNT] Conversion done."
  50. mv $DOWNLOAD_DIR/$OUTPUT_FILE $DOWNLOAD_DIR/$OUTPUT_FILE_AFTER
  51. done