commit 0777c29ab963af8576d020e87cd9fcf4a9c90a2a Author: casjay Date: Fri Oct 7 15:56:48 2022 -0400 🦈🏠🐜❗ Initial Commit ❗🐜🦈🏠 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a147c4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +# Files to ignore +.gitkeep +.gitignore +.node_modules/** diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0a22d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,93 @@ +# gitignore created on 10/07/22 at 15:56 +# Disable reminder in prompt +ignoredirmessage + +# OS generated files +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Other +**/.installed + +# ignore commit message +**/.gitcommit + +#ignore .failed +**/.build_failed + +# ignore .bak files +**/*.bak + +# ignore .no_push files +**/.no_push + +# ignore .no_git files +**/.no_git + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a40a79 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +FROM casjaysdevdocker/alpine:latest as build + +ARG LICENSE=WTFPL \ + IMAGE_NAME=youtube-dl \ + TIMEZONE=America/New_York \ + PORT= + +ENV SHELL=/bin/bash \ + TERM=xterm-256color \ + HOSTNAME=${HOSTNAME:-casjaysdev-$IMAGE_NAME} \ + TZ=$TIMEZONE + +RUN mkdir -p /bin/ /config/ /data/ && \ + rm -Rf /bin/.gitkeep /config/.gitkeep /data/.gitkeep && \ + apk update -U --no-cache && \ + apk add --no-cache \ + ffmpeg \ + py3-pip && \ + curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl && \ + curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp && \ + chmod a+rx /usr/local/bin/yt-dlp /usr/local/bin/youtube-dl + +COPY ./bin/. /usr/local/bin/ +COPY ./config/. /config/ +COPY ./data/. /data/ + +FROM scratch +ARG BUILD_DATE="$(date +'%Y-%m-%d %H:%M')" + +LABEL org.label-schema.name="youtube-dl" \ + org.label-schema.description="Containerized version of youtube-dl" \ + org.label-schema.url="https://hub.docker.com/r/casjaysdevdocker/youtube-dl" \ + org.label-schema.vcs-url="https://github.com/casjaysdevdocker/youtube-dl" \ + org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.version=$BUILD_DATE \ + org.label-schema.vcs-ref=$BUILD_DATE \ + org.label-schema.license="$LICENSE" \ + org.label-schema.vcs-type="Git" \ + org.label-schema.schema-version="latest" \ + org.label-schema.vendor="CasjaysDev" \ + maintainer="CasjaysDev " + +ENV SHELL="/bin/bash" \ + TERM="xterm-256color" \ + HOSTNAME="casjaysdev-youtube-dl" \ + TZ="${TZ:-America/New_York}" + +WORKDIR /root + +VOLUME ["/config","/data"] + +EXPOSE $PORT + +COPY --from=build /. / + +ENTRYPOINT [ "tini", "--" ] +HEALTHCHECK CMD [ "/usr/local/bin/entrypoint-youtube-dl.sh", "healthcheck" ] +CMD [ "/usr/local/bin/entrypoint-youtube-dl.sh" ] + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..d5b7ec5 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2022 casjay + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 1. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6631340 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +## 👋 Welcome to youtube-dl 🚀 + +youtube-dl README + + +## Run container + +```shell +dockermgr update youtube-dl +``` + +### via command line + +```shell +docker pull casjaysdevdocker/youtube-dl:latest && \ +docker run -d \ +--restart always \ +--name casjaysdevdocker-youtube-dl \ +--hostname casjaysdev-youtube-dl \ +-e TZ=${TIMEZONE:-America/New_York} \ +-v $HOME/Videos/ytdl:/data/video:z \ +-v $HOME/Music/ytdl:/data/audio:z \ +-v $HOME/.local/share/srv/docker/youtube-dl/files/config:/config:z \ +-p 80:80 \ +casjaysdevdocker/youtube-dl:latest +``` + +### via docker-compose + +```yaml +version: "2" +services: + youtube-dl: + image: casjaysdevdocker/youtube-dl + container_name: youtube-dl + environment: + - TZ=America/New_York + - HOSTNAME=casjaysdev-youtube-dl + volumes: + - $HOME/Videos/ytdl:/data/video:z + - $HOME/Music/ytdl:/data/audio:z + - $HOME/.local/share/srv/docker/youtube-dl/files/config:/config:z + ports: + - 80:80 + restart: always +``` + +## Authors + +🤖 casjay: [Github](https://github.com/casjay) [Docker](https://hub.docker.com/r/casjay) 🤖 +⛵ CasjaysDevDocker: [Github](https://github.com/casjaysdevdocker) [Docker](https://hub.docker.com/r/casjaysdevdocker) ⛵ diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bin/entrypoint-youtube-dl.sh b/bin/entrypoint-youtube-dl.sh new file mode 100755 index 0000000..ed6f5ff --- /dev/null +++ b/bin/entrypoint-youtube-dl.sh @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202210071527-git +# @@Author : Jason Hempstead +# @@Contact : jason@casjaysdev.com +# @@License : WTFPL +# @@ReadME : entrypoint-youtube-dl.sh --help +# @@Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments +# @@Created : Friday, Oct 07, 2022 15:27 EDT +# @@File : entrypoint-youtube-dl.sh +# @@Description : +# @@Changelog : New script +# @@TODO : Better documentation +# @@Other : +# @@Resource : +# @@Terminal App : no +# @@sudo/root : no +# @@Template : other/docker-entrypoint +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +APPNAME="$(basename "$0" 2>/dev/null)" +VERSION="202210071527-git" +HOME="${USER_HOME:-$HOME}" +USER="${SUDO_USER:-$USER}" +RUN_USER="${SUDO_USER:-$USER}" +SCRIPT_SRC_DIR="${BASH_SOURCE%/*}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set bash options +[ "$1" == "--debug" ] && set -xo pipefail && export SCRIPT_OPTS="--debug" && export _DEBUG="on" +[ "$1" == "--raw" ] && export SHOW_RAW="true" +set -o pipefail + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set functions +__version() { echo -e ${GREEN:-}"$VERSION"${NC:-}; } +__find() { ls -A "$*" 2>/dev/null; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# colorization +[ -n "$SHOW_RAW" ] || printf_color() { echo -e '\t\t'${2:-}"${1:-}${NC}"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__exec_bash() { + local cmd="${*:-/bin/bash}" + local exitCode=0 + echo "Executing command: $cmd" + $cmd || exitCode=10 + return ${exitCode:-$?} +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Define default variables +TZ="${TZ:-America/New_York}" +HOSTNAME="${HOSTNAME:-casjaysdev-bin}" +BIN_DIR="${BIN_DIR:-/usr/local/bin}" +DATA_DIR="${DATA_DIR:-$(__find /data/ 2>/dev/null | grep '^' || false)}" +CONFIG_DIR="${CONFIG_DIR:-$(__find /config/ 2>/dev/null | grep '^' || false)}" +CONFIG_COPY="${CONFIG_COPY:-false}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional variables + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Export variables +export TZ HOSTNAME +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# import variables from file +[ -f "/root/env.sh" ] && . "/root/env.sh" +[ -f "/config/.env.sh" ] && . "/config/.env.sh" +[ -f "/root/env.sh" ] && [ ! -f "/config/.env.sh" ] && cp -Rf "/root/env.sh" "/config/.env.sh" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set timezone +[ -n "${TZ}" ] && echo "${TZ}" >/etc/timezone +[ -f "/usr/share/zoneinfo/${TZ}" ] && ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set hostname +if [ -n "${HOSTNAME}" ]; then + echo "${HOSTNAME}" >/etc/hostname + echo "127.0.0.1 ${HOSTNAME} localhost ${HOSTNAME}.local" >/etc/hosts +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Delete any gitkeep files +[ -n "${CONFIG_DIR}" ] && { [ -d "${CONFIG_DIR}" ] && rm -Rf "${CONFIG_DIR}/.gitkeep" || mkdir -p "/config/"; } +[ -n "${DATA_DIR}" ] && { [ -d "${DATA_DIR}" ] && rm -Rf "${DATA_DIR}/.gitkeep" || mkdir -p "/data/"; } +[ -n "${BIN_DIR}" ] && { [ -d "${BIN_DIR}" ] && rm -Rf "${BIN_DIR}/.gitkeep" || mkdir -p "/bin/"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Copy config files to /etc +if [ -n "${CONFIG_DIR}" ] && [ "${CONFIG_COPY}" = "true" ]; then + for config in ${CONFIG_DIR}; do + if [ -d "/config/$config" ]; then + [ -d "/etc/$config" ] || mkdir -p "/etc/$config" + cp -Rf "/config/$config/." "/etc/$config/" + elif [ -f "/config/$config" ]; then + cp -Rf "/config/$config" "/etc/$config" + fi + done +fi +[ -f "/etc/.env.sh" ] && rm -Rf "/etc/.env.sh" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional commands +[ -d "$HOME/.config/youtube-dl" ] || mkdir -p "$HOME/.config/youtube-dl" +[ -f "/config/youtube-dl.conf" ] && cp -Rf "/config/youtube-dl.conf" "$HOME/.config/youtube-dl/config" +[ -d "/config" ] && cp -Rf "/config/." "$HOME/.config/youtube-dl/" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +case "$1" in +--help) # Help message + echo 'Docker container for '$APPNAME'' + echo "Usage: $APPNAME [healthcheck, bash, command]" + echo "Failed command will have exit code 10" + echo + exitCode=$? + ;; + +healthcheck) # Docker healthcheck + echo "$(uname -s) $(uname -m) is running" + echo _other_commands here + exitCode=$? + ;; + +*/bin/sh | */bin/bash | bash | shell | sh) # Launch shell + shift 1 + __exec_bash "${@:-/bin/bash}" + exitCode=$? + ;; + +*) # Execute primary command + if [ $# -eq 0 ]; then + __exec_bash "/bin/bash" + else + __exec_bash "/bin/bash" + fi + exitCode=$? + ;; +esac +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# end of entrypoint +exit ${exitCode:-$?} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bin/ytda b/bin/ytda new file mode 100644 index 0000000..f0a8baf --- /dev/null +++ b/bin/ytda @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +youtube-dl -f bestaudio --extract-audio --audio-format mp3 --config-location "$HOME/.config/youtube-dl/music" "$@" +exit $? + diff --git a/bin/ytdv b/bin/ytdv new file mode 100644 index 0000000..719d4df --- /dev/null +++ b/bin/ytdv @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +youtube-dl -f bestvideo+bestaudio --config-location "$HOME/.config/youtube-dl/video" "$@" +exit $? + diff --git a/config/.gitkeep b/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/audio.conf b/config/audio.conf new file mode 100644 index 0000000..9facfb7 --- /dev/null +++ b/config/audio.conf @@ -0,0 +1,7 @@ +# Save all music under Music directory in your home directory +-o ~/data/audio/%(title)s.%(ext)s +--metadata-from-title "(?P.+?) - (?P.+)" +--add-metadata +--embed-thumbnail +--no-warnings +--ignore-errors diff --git a/config/video.conf b/config/video.conf new file mode 100644 index 0000000..40ac5e0 --- /dev/null +++ b/config/video.conf @@ -0,0 +1,5 @@ +# Save all videos under Videos directory in your home directory +-o ~/data/video/%(title)s.%(ext)s +--metadata-from-title "(?P<artist>.+?) - (?P<title>.+)" +--add-metadata +-ic diff --git a/config/youtube-dl.conf b/config/youtube-dl.conf new file mode 100644 index 0000000..116ae4f --- /dev/null +++ b/config/youtube-dl.conf @@ -0,0 +1,5 @@ +# Save all videos under Videos directory in your home directory +-o ~/data/%(title)s.%(ext)s +--metadata-from-title "(?P<artist>.+?) - (?P<title>.+)" +--add-metadata +-ic diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29