From a5ef6efd4d848959cd2ee3d5551aa60e73583056 Mon Sep 17 00:00:00 2001 From: Youe Graillot Date: Fri, 15 Jul 2022 01:04:14 +0200 Subject: [PATCH] init --- .gitignore | 3 + .gitmodules | 3 + docker-compose.yml | 19 ++++++ dockerfile | 21 ++++++ lidarr-flac2mp3 | 1 + root/etc/services.d/deemix/config.json | 82 ++++++++++++++++++++++++ root/etc/services.d/deemix/run | 33 ++++++++++ root/etc/services.d/setup/finish | 10 +++ root/etc/services.d/setup/run | 89 ++++++++++++++++++++++++++ 9 files changed, 261 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 docker-compose.yml create mode 100644 dockerfile create mode 160000 lidarr-flac2mp3 create mode 100644 root/etc/services.d/deemix/config.json create mode 100644 root/etc/services.d/deemix/run create mode 100644 root/etc/services.d/setup/finish create mode 100644 root/etc/services.d/setup/run diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a0aa6fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +config/ +config_deemix/ +downloads/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cf68160 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lidarr-flac2mp3"] + path = lidarr-flac2mp3 + url = https://github.com/youegraillot/lidarr-flac2mp3.git diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..76a3887 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3.4' + +services: + lidarr-onsteroids: + image: lidarr-onsteroids + build: + context: . + environment: + - PUID=1000 + - PGID=100 + - AUTOCONFIG=true + ports: + - "8686:8686" + - "6595:6595" + volumes: + - ./config:/config + - ./config_deemix:/config_deemix + - ./downloads:/downloads + restart: unless-stopped diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..3f8f96f --- /dev/null +++ b/dockerfile @@ -0,0 +1,21 @@ +FROM cr.hotio.dev/hotio/lidarr:pr-plugins + +LABEL maintainer="youegraillot" + +ENV DEEMIX_SINGLE_USER=true +ENV AUTOCONFIG=true + +# flac2mp3 +COPY lidarr-flac2mp3/root/usr /usr +RUN apk add --no-cache ffmpeg && \ + rm -rf /var/lib/apt/lists/* + +# deemix +COPY --from=registry.gitlab.com/bockiii/deemix-docker:latest /deemix-server /deemix-server +RUN chmod +x /deemix-server +VOLUME [ "/config_deemix" "/downloads" ] +EXPOSE 6595 + +COPY root / +VOLUME "/config" +EXPOSE 6595 8686 diff --git a/lidarr-flac2mp3 b/lidarr-flac2mp3 new file mode 160000 index 0000000..48aced2 --- /dev/null +++ b/lidarr-flac2mp3 @@ -0,0 +1 @@ +Subproject commit 48aced2c6e02d0fffcbba5f2d50cc2eb0fcc57f8 diff --git a/root/etc/services.d/deemix/config.json b/root/etc/services.d/deemix/config.json new file mode 100644 index 0000000..3e1f636 --- /dev/null +++ b/root/etc/services.d/deemix/config.json @@ -0,0 +1,82 @@ +{ + "downloadLocation": "/downloads/", + "tracknameTemplate": "%artist% - %title%", + "albumTracknameTemplate": "%tracknumber% - %title%", + "playlistTracknameTemplate": "%position% - %artist% - %title%", + "createPlaylistFolder": true, + "playlistNameTemplate": "%playlist%", + "createArtistFolder": true, + "artistNameTemplate": "%artist%", + "createAlbumFolder": true, + "albumNameTemplate": "%artist% - %album%", + "createCDFolder": true, + "createStructurePlaylist": true, + "createSingleFolder": true, + "padTracks": true, + "paddingSize": "0", + "illegalCharacterReplacer": "_", + "queueConcurrency": 3, + "maxBitrate": "9", + "feelingLucky": true, + "fallbackBitrate": true, + "fallbackSearch": false, + "fallbackISRC": false, + "logErrors": true, + "logSearched": false, + "overwriteFile": "n", + "createM3U8File": false, + "playlistFilenameTemplate": "playlist", + "syncedLyrics": false, + "embeddedArtworkSize": 800, + "embeddedArtworkPNG": false, + "localArtworkSize": 1200, + "localArtworkFormat": "jpg", + "saveArtwork": true, + "coverImageTemplate": "cover", + "saveArtworkArtist": false, + "artistImageTemplate": "folder", + "jpegImageQuality": 90, + "dateFormat": "Y-M-D", + "albumVariousArtists": true, + "removeAlbumVersion": false, + "removeDuplicateArtists": true, + "featuredToTitle": "0", + "titleCasing": "nothing", + "artistCasing": "nothing", + "executeCommand": "", + "tags": { + "title": true, + "artist": true, + "artists": true, + "album": true, + "cover": true, + "trackNumber": true, + "trackTotal": true, + "discNumber": true, + "discTotal": true, + "albumArtist": true, + "genre": true, + "year": true, + "date": true, + "explicit": true, + "isrc": true, + "length": true, + "barcode": true, + "bpm": true, + "replayGain": true, + "label": true, + "lyrics": true, + "syncedLyrics": true, + "copyright": true, + "composer": true, + "involvedPeople": true, + "source": true, + "rating": false, + "savePlaylistAsCompilation": false, + "useNullSeparator": false, + "saveID3v1": true, + "multiArtistSeparator": "default", + "singleAlbumArtist": false, + "coverDescriptionUTF8": false + } +} \ No newline at end of file diff --git a/root/etc/services.d/deemix/run b/root/etc/services.d/deemix/run new file mode 100644 index 0000000..7eedd7b --- /dev/null +++ b/root/etc/services.d/deemix/run @@ -0,0 +1,33 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +UMASK_SET=${UMASK_SET:-022} +umask "$UMASK_SET" + +cd / + +# Check if an alternative port was defined, set it to it or default +if [ -n "${INTPORT}" ]; then + port=$INTPORT +else + port=6595 +fi + +# Check if the ARL environment var is set to anything. This enables legacy behavior +if [ -n "${ARL}" ]; then + export DEEMIX_SINGLE_USER=true +fi + +export DEEMIX_DATA_DIR=/config_deemix/ +export DEEMIX_MUSIC_DIR=/downloads/ +export DEEMIX_SERVER_PORT=$port +export DEEMIX_HOST=0.0.0.0 + +if [ ! -f $DEEMIX_DATA_DIR/config.json ] && [ "$AUTOCONFIG" = "true" ]; then + echo "[services.d] Copying deemix configuration" + cp -f /etc/services.d/deemix/config.json $DEEMIX_DATA_DIR/config.json +fi +chown -R "$PUID:$PGID" /config_deemix + +echo "[services.d] Starting Deemix" +s6-setuidgid "$PUID:$PGID" /deemix-server diff --git a/root/etc/services.d/setup/finish b/root/etc/services.d/setup/finish new file mode 100644 index 0000000..42c2142 --- /dev/null +++ b/root/etc/services.d/setup/finish @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv sh +# shellcheck shell=sh + +SUPERVISED_DIR=/var/run/s6/services + +# hack: this is run-once service +# stop the s6-supervise process and ensure that its not started again +s6-svc -x ${SUPERVISED_DIR}/setup +rm -rf ${SUPERVISED_DIR}/setup +s6-svscanctl -a ${SUPERVISED_DIR} diff --git a/root/etc/services.d/setup/run b/root/etc/services.d/setup/run new file mode 100644 index 0000000..c1232af --- /dev/null +++ b/root/etc/services.d/setup/run @@ -0,0 +1,89 @@ +#!/usr/bin/with-contenv sh +# shellcheck shell=sh + +echo " +---------------------------------------------------------------------- +Flac2MP3 SETUP +---------------------------------------------------------------------- +PUID=$PUID +PGID=$PGID +---------------------------------------------------------------------- +" + +if [ "$(stat -c '%g' /usr/local/bin/flac2mp3.sh)" != "$PGUID" ]; then + echo "Changing ownership on scripts." + chown "$PUID:$PGID" /usr/local/bin/flac2*.sh +fi + +if [ ! -x /usr/local/bin/flac2mp3.sh ]; then + echo "Making scripts executable." + chmod +x /usr/local/bin/flac2*.sh +fi + +echo " +---------------------------------------------------------------------- +LIDARR SETUP +---------------------------------------------------------------------- +Source=$urlPlugin +---------------------------------------------------------------------- +" + +url="http://localhost:8686" +urlPlugin="https://github.com/ta264/Lidarr.Plugin.Deemix" + +# string, route +isPresent() { + apiCall "GET" "$2" | grep -q "$1" +} + +# method, route, payload +apiCall() { + curl \ + -sS \ + -X "$1" \ + -H "Content-Type: application/json" \ + -H "X-Api-Key: $apiKey" \ + -d "$3" \ + $url/api/v1/"$2" + return 0 +} + +apiKey="$(curl \ + -sS \ + --retry-all-errors \ + --retry 10 \ + $url/initialize.js | + sed -n "s/apiKey: '\(.*\)'.*/\1/p")" + +if isPresent $urlPlugin "system/plugins"; then + echo "Plugin already installed" +else + echo "Installing plugin" + apiCall "POST" "command" '{"name":"InstallPlugin","githubUrl":"'$urlPlugin'"}' +fi + +if [ "$AUTOCONFIG" = "true" ]; then + loginPath="/config_deemix/login.json" + echo "Waiting for $loginPath to be filled..." + while [ -z "$arl" ]; do + sleep 1 + arl=$(sed -n 's/.*arl.*"\(.*\)"/\1/p' "$loginPath" 2>/dev/null) + done + if [ "$(apiCall "GET" "delayprofile" | jq .[0].items[2].allowed)" = "false" ]; then + echo "Allowing Deemix in default delay profile" + apiCall "PUT" "delayprofile/1" \ + '{"name":"Default","items":[{"name":"Usenet","protocol":"UsenetDownloadProtocol","allowed":true,"delay":0},{"name":"Torrent","protocol":"TorrentDownloadProtocol","allowed":true,"delay":0},{"name":"Deemix","protocol":"DeemixDownloadProtocol","allowed":true,"delay":0}],"tags":[],"id":1}' + fi + if ! isPresent "Deemix" "indexer"; then + loginPath="/config_deemix/login.json" + echo "Updating indexer" + apiCall "POST" "indexer" \ + '{"enableRss":true,"enableAutomaticSearch":true,"enableInteractiveSearch":true,"supportsRss":true,"supportsSearch":true,"protocol":"DeemixDownloadProtocol","priority":25,"downloadClientId":0,"name":"Deemix","fields":[{"name":"baseUrl","value":"http://localhost:6595"},{"name":"arl","value":"'"$arl"'"},{"name":"earlyReleaseLimit"}],"implementationName":"Deemix","implementation":"Deemix","configContract":"DeemixIndexerSettings","infoLink":"https://wiki.servarr.com/lidarr/supported#deemix","tags":[]}' + fi + if ! isPresent "Deemix" "downloadclient"; then + echo "Updating download client" + apiCall "POST" "downloadclient" \ + '{"enable":true,"protocol":"DeemixDownloadProtocol","priority":1,"removeCompletedDownloads":true,"removeFailedDownloads":true,"name":"Deemix","fields":[{"name":"host","value":"localhost"},{"name":"port","value":6595},{"name":"urlBase"},{"name":"useSsl","value":false},{"name":"arl","value":"'"$arl"'"}],"implementationName":"Deemix","implementation":"Deemix","configContract":"DeemixSettings","infoLink":"https://wiki.servarr.com/lidarr/supported#deemix","tags":[]}' + fi + echo "Configuration is up to date" +fi