Skip to content

Commit 80a6af2

Browse files
committed
improve naming, add podcasts, adapt to cron container v0.2.0
1 parent e63f6ca commit 80a6af2

File tree

6 files changed

+34
-23
lines changed

6 files changed

+34
-23
lines changed

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ FROM madebytimo/cron
33
RUN install-autonomous.sh install Basics FFmpeg Fileorganizer Java Scripts YtDlp \
44
&& rm -rf /var/lib/apt/lists/*
55

6-
RUN mv /entrypoint.sh /entrypoint-cron.sh
76
COPY files/downloader.sh files/entrypoint.sh /usr/local/bin/
87

98
ENV DOWNLOADER_CRON="30 20 * * *"
109
ENV DOWNLOADER_LIST=""
1110
ENV POST_EXECUTION_COMMAND=""
1211

1312
ENTRYPOINT [ "entrypoint.sh" ]
14-
CMD [ "sleep", "infinity" ]
13+
CMD [ "run-cron.sh" ]

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It downloads all new files from the given urls at the given cron schedule.
1717
- The time to run the downloader. The default is `30 20 * * *`
1818
- `DOWNLOADER_LIST`
1919
- List of urls to download. One per line. No spaces in url allowed.
20-
List is in the format `[[movie|music|musicvideo|series]] URL ((NOTE))`.
20+
List is in the format `[[movie|music|musicvideo|podcast|series]] URL ((NOTE))`.
2121
- `POST_EXECUTION_COMMAND`
2222
- Command to run when the downloads are finished and new files are downloaded.
2323

Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.2.0
1+
v0.3.0

docker-compose-dev.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ services:
1414
music https://www.youtube.com/watch?v=HJpDlGvY6YE
1515
musicvideo https://www.youtube.com/watch?v=HJpDlGvY6YE
1616
news https://www.youtube.com/watch?v=HJpDlGvY6YE
17+
podcast https://www.youtube.com/watch?v=HJpDlGvY6YE
1718
series https://www.youtube.com/watch?v=HJpDlGvY6YE
1819
xyz https://www.youtube.com/watch?v=HJpDlGvY6YE
1920
- POST_EXECUTION_COMMAND=echo 'Here is post execution command.'
2021
# - DOWNLOADER_CRON=* * * * *
22+
read_only: true
2123
tmpfs:
24+
- /media/cron
2225
- /media/workdir
26+
- /run
27+
- /tmp:exec
2328
volumes:
2429
- "./data-local:/media/downloader"

files/downloader.sh

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -e -o pipefail
33

44
CONFIG_DIR="/media/downloader/config"
55
FAIL_DIR="/media/downloader/fail"
6-
LOCK_FILE="/run/lock/$(basename "$0").lock"
6+
LOCK_FILE="/dev/shm/$(basename "$0").lock"
77
NEW_DOWNLOAD=false
88
OUTPUT_DIR="/media/downloader/output"
99
WORKDIR="/media/workdir"
1010

1111
# Aquire lock
1212
if [ -e "$LOCK_FILE" ]; then
13-
echo "Error: $(basename "$0") is already running. Exiting."
14-
exit 1
13+
echo "Error: Already running." >&2
14+
exit 11
1515
fi
1616
touch "$LOCK_FILE"
1717

18+
function cleanup {
19+
rm "$LOCK_FILE"
20+
}
21+
trap cleanup EXIT
22+
1823
echo "Start downloader"
1924

2025
mapfile -t DOWNLOADER_ITEMS_FILE </media/downloader/downloader-list.txt
2126
mapfile -t DOWNLOADER_ITEMS_ENVIRONMENT_VARIABLE \
2227
</media/downloader/downloader-list-from-environment-variable.txt
2328
DOWNLOADER_ITEMS=("${DOWNLOADER_ITEMS_ENVIRONMENT_VARIABLE[@]}" "${DOWNLOADER_ITEMS_FILE[@]}")
2429

30+
AUDIO_DEFAULT_ARGUMENTS=(--extract-audio --audio-format "opus" --format "bestaudio/best" \
31+
--format-sort "acodec:opus,acodec:mp3,acodec:aac" )
2532
VIDEO_DEFAULT_ARGUMENTS=(--format "bestvideo[language=?deu]+(bestaudio[language~=?'deu?'],\
2633
bestaudio[language~=?'deu?'][format_note*=Audiodeskription],bestaudio[language~='eng?'])/best" \
2734
--format-sort "res,vcodec:av01,acodec:opus,vcodec:vp9,vcodec:h264" \
@@ -44,11 +51,12 @@ for ITEM in "${DOWNLOADER_ITEMS[@]}"; do
4451
YT_DLP_ARGUMENTS=()
4552
if [[ "$TYPE" == movie ]]; then
4653
YT_DLP_ARGUMENTS=("${VIDEO_DEFAULT_ARGUMENTS[@]}" --output \
47-
"${WORKDIR}/%(title)s (%(release_date>%Y,upload_date>%Y)s) [%(language).2s].%(ext)s")
54+
"${WORKDIR}/%(title)s (%(release_date>%Y,upload_date>%Y)s)\
55+
%(format_note& - {}|)s [%(language).2s].%(ext)s")
4856
elif [[ "$TYPE" == music ]]; then
4957
RUN_FILENAME_SANITIZE=true
5058
RUN_FILEORGANIZER=true
51-
YT_DLP_ARGUMENTS=(--extract-audio --audio-format "opus" \
59+
YT_DLP_ARGUMENTS=("${AUDIO_DEFAULT_ARGUMENTS[@]}" \
5260
--postprocessor-args "ThumbnailsConvertor+ffmpeg_o:-c:v \
5361
mjpeg -vf crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\"" \
5462
--output "${WORKDIR}/%(creator).80s - %(title)s.%(ext)s")
@@ -60,11 +68,15 @@ for ITEM in "${DOWNLOADER_ITEMS[@]}"; do
6068
YT_DLP_ARGUMENTS=("${VIDEO_DEFAULT_ARGUMENTS[@]}" --output \
6169
"${WORKDIR}/%(release_date>%Y.%m.%d,upload_date>%Y.%m.%d)s \
6270
%(playlist_title,channel)s - %(title)s \\[%(language).2s\\].%(ext)s")
71+
elif [[ "$TYPE" == podcast ]]; then
72+
YT_DLP_ARGUMENTS=("${AUDIO_DEFAULT_ARGUMENTS[@]}" --output \
73+
"${WORKDIR}/%(release_date>%Y.%m.%d,upload_date>%Y.%m.%d)s \
74+
%(series,playlist_title,channel)s%(title& - {}|)s [%(language).2s].%(ext)s")
6375
elif [[ "$TYPE" == series ]]; then
6476
YT_DLP_ARGUMENTS=("${VIDEO_DEFAULT_ARGUMENTS[@]}" --output \
65-
"${WORKDIR}/%(series,playlist_title)s S%(season_number|XX)02dE\
66-
%(episode_number,playlist_index|XX)02d%(title& |)s%(title|)s (%(release_date>%Y,upload_date>%Y)s) [\
67-
%(language).2s].%(ext)s")
77+
"${WORKDIR}/%(series,playlist_title,channel)s S%(season_number|XX)02d\
78+
E%(episode_number,playlist_index|XX)02d%(title& {}|)s (%(release_date>%Y,upload_date>%Y)s)\
79+
%(format_note& - {}|)s [%(language).2s].%(ext)s")
6880
else
6981
echo "Type \"${TYPE}\" not supported."
7082
continue
@@ -122,10 +134,7 @@ tok.*)\)//gi" \
122134
done
123135
done
124136

125-
POST_EXECUTION_COMMAND="$(cat /tmp/post-execution-command)"
137+
POST_EXECUTION_COMMAND="$(cat /dev/shm/downloader-post-execution-command)"
126138
if [[ "$NEW_DOWNLOAD" == true ]] && [[ -n "$POST_EXECUTION_COMMAND" ]]; then
127139
eval "$POST_EXECUTION_COMMAND"
128140
fi
129-
130-
# Release lock
131-
rm "$LOCK_FILE"

files/entrypoint.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -e -o pipefail
33

4-
DOWNLOAD_TYPES=(movie music musicvideo news series)
4+
DOWNLOAD_TYPES=(movie music musicvideo news podcast series)
55

66
mkdir --parents /media/downloader/fail
77
mkdir --parents /media/workdir
@@ -10,12 +10,10 @@ for DOWNLOAD_TYPE in "${DOWNLOAD_TYPES[@]}"; do
1010
mkdir --parents "/media/downloader/config/$DOWNLOAD_TYPE"
1111
done
1212

13-
rm -f /run/lock/downloader.sh.lock
14-
1513
echo "$DOWNLOADER_LIST" > /media/downloader/downloader-list-from-environment-variable.txt
1614
chmod a-w /media/downloader/downloader-list-from-environment-variable.txt
1715

18-
echo "${POST_EXECUTION_COMMAND}" > /tmp/post-execution-command
16+
echo "${POST_EXECUTION_COMMAND}" > /dev/shm/downloader-post-execution-command
1917

2018
echo "$DOWNLOADER_CRON root bash --login -c 'downloader.sh > /proc/1/fd/1 2>&1'" \
2119
> /media/cron/downloader
@@ -26,4 +24,4 @@ if [[ ! -e /media/downloader/downloader-list.txt ]]; then
2624
> /media/downloader/downloader-list.txt
2725
fi
2826

29-
exec /entrypoint-cron.sh "$@"
27+
"$@"

0 commit comments

Comments
 (0)