Guest User

Untitled

a guest
Apr 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. ### Get Lists
  4. ls -1 {episodes,movies}.txt | head -n 1 | while read LIST
  5. do
  6. ### Go Through Lists
  7. cat "${LIST}" | sort | while read FILE
  8. do
  9. ### Get filename
  10. FILENAME=${FILE##*/}
  11. ### Get File Name
  12. NOEXT=${FILENAME%\.*}
  13. ### Define New Filename
  14. NEWFILE=${NOEXT}".m4v"
  15. ### Get file Path
  16. FILEPATH=${FILE%/*}
  17. ### Find subs
  18. rm "${NOEXT}.subs" 2>/dev/null
  19. touch "${NOEXT}.subs"
  20. ls "${FILEPATH}/${NOEXT}"*{srt,sub} 2>/dev/null | while read sub
  21. do
  22. THESUB=${sub##*/}
  23. SUBEXT=$(echo ${THESUB##*\.})
  24. NOEXTSUB=${THESUB%\.*}
  25. LANGSUB=${NOEXTSUB##*\.}
  26. LANGUAGE="eng"
  27. tempfile=$$
  28. ### Find if sub has language. Match against table. Get Language Full Name
  29. if [ ${#LANGSUB} -eq 2 ]
  30. then
  31. LANGUAGE=$(cat apps/langs-3 | tr '\t' '\|' | grep \|${LANGSUB}\| | cut -f1 -d\|)
  32. else
  33. LANGUAGE="eng"
  34. fi
  35. ### If Subtitle is of type "SUB" then convert to SRT
  36. if [ "${SUBEXT}" = "sub" ]
  37. then
  38. if [ ! -e "${FILEPATH}/${NOEXT}".idx ]
  39. then
  40. cp "$sub" ./"${THESUB}"
  41. cp ./"${THESUB}" "$$-${THESUB}"
  42. ### Get bitrate (for Subs)
  43. FPS=$(apps/mplayer -vo null -ao null -frames 0 -identify "${FILE}" 2>/dev/null | grep ID_VIDEO_FPS | cut -f2 -d=)
  44. echo "Converting $$-${THESUB} to ${NOEXTSUB}.srt with fps ${FPS}"
  45. apps/sub2srt -f="${FPS}" "./$$-${THESUB}" > ./"${NOEXTSUB}".srt
  46. echo "${LANGUAGE}|${NOEXTSUB}.srt" >> "${NOEXT}".subs
  47. rm "$$-${THESUB}"
  48. fi
  49. elif [ "${SUBEXT}" = "srt" ]
  50. then
  51. cp "$sub" ./"${THESUB}"
  52. cp ./"${THESUB}" "$$-${THESUB}"
  53. cp ./"$$-${THESUB}" ./"${NOEXTSUB}".srt
  54. echo "${LANGUAGE}|${NOEXTSUB}.srt" >> "${NOEXT}".subs
  55. rm "$$-${THESUB}"
  56. fi
  57. ### Finish Processing Subs
  58. done
  59. TOTALSUBS=$(cat "${NOEXT}.subs" | wc -l)
  60. if [[ "${TOTALSUBS}" -gt 0 ]]
  61. then
  62. THESELANGS=$(cat "${NOEXT}.subs"|cut -d\| -f1| tr '\n' ',')
  63. THESESUBS=$(cat "${NOEXT}.subs"|cut -d\| -f2| tr '\n' ',')
  64. LANGSALL=${THESELANGS%\,}
  65. SUBSALL=${THESESUBS%\,}
  66. ### Uncomment encoding to use
  67. # Small and good quality - Slow coding
  68. # apps/HandBrakeCLI -i "$FILE" -o "$NEWFILE" --preset "iPhone & iPod Touch" < /dev/null
  69. # # echo "apps/HandBrakeCLI -i \"${FILE}\" -o \"${NEWFILE}\" --srt-file ${SUBSALL} --srt-lang ${LANGSALL} -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1 < /dev/null" >> commands
  70. apps/HandBrakeCLI -i "${FILE}" -o "${NEWFILE}" --srt-file "${SUBSALL}" --srt-lang "${LANGSALL}" -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1 < /dev/null
  71. # Not Small and Medium quality - Fast coding
  72. # apps/ffmpeg -i "$FILE" -threads 4 -f mp4 -vcodec mpeg4 -maxrate 2500k -b 700k -r 23.98 -s 480x320 -bufsize 4M -acodec libfaac -qmin 3 -qmax 5 -g 300 -ab 192k "$NEWFILE" < /dev/null
  73. else
  74. # # echo "apps/HandBrakeCLI -i \"${FILE}\" -o \"${NEWFILE}\" -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1 < /dev/null" >> commands
  75. apps/HandBrakeCLI -i "${FILE}" -o "${NEWFILE}" -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1 < /dev/null
  76. fi
  77. ### Define new file name
  78. FILENAME=${NEWFILE%%\.*}
  79. ### Get File List Type
  80. TYPE=${LIST%%\.*}
  81. if [ ${LIST} = "episodes.txt" ]
  82. then
  83. ### This is a TV Episode Listing. Get Episode ID, Season Nbr., Episode Nbr., Short Name, Episode Title
  84. EPISODE=$(echo $FILENAME | sed -e's/.* \([0-9]*x[0-9]*\) .*/\1/g')
  85. SEASON=${EPISODE%%x*}
  86. EPID=${EPISODE##*x}
  87. TVSHOW=${NEWFILE%%$EPISODE*}
  88. EPISODETITLE=${FILENAME##$TVSHOW $EPISODE - }
  89. EPISODETITLE=${FILENAME##*- }
  90. ### Tag Files
  91. if [ -f "${NEWFILE}" ]
  92. then
  93. apps/AtomicParsley "${NEWFILE}" \
  94. --DeepScan iPod-uuid 1200 \
  95. --overWrite \
  96. --stik "TV Show" \
  97. --title "${EPISODETITLE}" \
  98. --TVShowName "${TVSHOW}" \
  99. --TVEpisode "${EPISODE}" \
  100. --TVSeasonNum "${SEASON}" \
  101. --TVEpisodeNum "${EPID}" \
  102. --comment "Converted and Tagged for iPod by Eduo with SolEol" \
  103. --artist "${TVSHOW}" \
  104. --albumArtist "${TVSHOW}" \
  105. --album "${TVSHOW}, Season ${SEASON}" \
  106. --tracknum "${EPID}/${EPID}" \
  107. --disk "${SEASON}"
  108. fi
  109. elif [ ${LIST} = "movies.txt" ]
  110. then
  111. ### File is a movie. Simpler tagging
  112. if [ -f "${NEWFILE}" ]
  113. then
  114. apps/AtomicParsley "${NEWFILE}" \
  115. --DeepScan iPod-uuid 1200 \
  116. --overWrite \
  117. --stik "Movie" \
  118. --title "${FILENAME}" \
  119. --comment "Converted and Tagged for iPod by Eduo with SolEol"
  120.  
  121. fi
  122. fi
  123. ### Metemos el fichero en iTunes
  124. if [ -f "${NEWFILE}" ]
  125. then
  126. apps/addmp4 "${NEWFILE}"
  127. mv "$NEWFILE" movs/.
  128. echo ""
  129. fi
  130. ### Finish Processing File
  131. done
  132. ### Finish Processing Files
  133. echo ""
  134. done
  135.  
  136. rm *.subs 2>/dev/null
  137. rm *.srt 2>/dev/null
  138. rm *.sub 2>/dev/null
Add Comment
Please, Sign In to add comment