diff --git a/README.md b/README.md index 3f157c0..6f4de98 100644 --- a/README.md +++ b/README.md @@ -29,40 +29,66 @@ Or for docker locally: The Docker image is available from the Forgejo container registry: ```bash -docker pull git.khoavo.myds.me/vndangkhoa/kv-download:latest -``` - -### Deploy on Synology NAS - -1. Load the image (if using local transfer): -```bash -docker load -i kv-download.tar -``` - -2. Run with docker-compose: -```yaml -services: - kv-download: - image: git.khoavo.myds.me/vndangkhoa/kv-download:latest - container_name: kv-download - restart: unless-stopped - ports: - - "9292:9292" - volumes: - - /volume2/docker/kv-download/download:/download - environment: - - MR_DOWNLOAD_DIR=/download - - TZ=Asia/Ho_Chi_Minh -``` - -```bash -docker compose up -d +docker pull git.khoavo.myds.me/vndangkhoa/kv-download:v1 ``` ### Build Your Own Image ```bash -docker build -t kv-download:latest --platform linux/amd64 . +docker build -t git.khoavo.myds.me/vndangkhoa/kv-download:v1 --platform linux/amd64 . +docker push git.khoavo.myds.me/vndangkhoa/kv-download:v1 +``` + +## Deploy on Synology NAS + +### Method 1: Docker Compose (Recommended) + +1. SSH into your Synology NAS + +2. Create a project directory and copy the `docker-compose.yml` there + +3. Run: +```bash +cd /path/to/project +docker compose up -d +``` + +### Method 2: Synology Container Manager (Docker GUI) + +1. Open **Container Manager** in DSM + +2. Go to **Registry** → **Add** → enter: + - Server: `git.khoavo.myds.me` + - Username: `vndangkhoa` + - Password: `Thieugia19` + +3. Search for `vndangkhoa/kv-download` and download the `v1` tag + +4. Go to **Image** → select `kv-download` → **Create Container** + +5. Configure the container: + - **Container Name**: `kv-download` + - **Port Settings**: Local `9292` → Container `9292` + - **Volume Settings**: + - Add folder: `/volume2/docker/kv-download/download` → Mount path `/download` + - **Environment Variables**: + - `MR_DOWNLOAD_DIR` = `/download` + - `TZ` = `Asia/Ho_Chi_Minh` + - **Restart Policy**: `Always restart the container` + +6. Click **Done** to start the container + +### Method 3: Docker CLI + +```bash +docker run -d \ + --name kv-download \ + --restart unless-stopped \ + -p 9292:9292 \ + -v ./download:/download \ + -e MR_DOWNLOAD_DIR=/download \ + -e TZ=Asia/Ho_Chi_Minh \ + git.khoavo.myds.me/vndangkhoa/kv-download:v1 ``` ## Docker Environment Variables @@ -73,7 +99,7 @@ docker build -t kv-download:latest --platform linux/amd64 . After downloading videos, files are organized as follows: ``` -/download/ +download/ ├── / │ └── .mp4 # Video files └── json/ diff --git a/build.sh b/build.sh old mode 100755 new mode 100644 diff --git a/docker-build.sh b/docker-build.sh old mode 100755 new mode 100644 diff --git a/docker-compose.yml b/docker-compose.yml index e2a54ef..0a0f989 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,12 @@ services: kv-download: - image: git.khoavo.myds.me/vndangkhoa/kv-download:latest + image: git.khoavo.myds.me/vndangkhoa/kv-download:v1 container_name: kv-download restart: unless-stopped ports: - "9292:9292" volumes: - - ./downloads:/download + - ./download:/download environment: - MR_DOWNLOAD_DIR=/download - TZ=Asia/Ho_Chi_Minh diff --git a/docker-run.sh b/docker-run.sh old mode 100755 new mode 100644 diff --git a/kv-download.tar b/kv-download.tar new file mode 100644 index 0000000..c876df9 Binary files /dev/null and b/kv-download.tar differ diff --git a/run.sh b/run.sh old mode 100755 new mode 100644 diff --git a/src/media/fetch.go b/src/media/fetch.go index 40bbd4d..21d5b83 100644 --- a/src/media/fetch.go +++ b/src/media/fetch.go @@ -214,9 +214,40 @@ func downloadMedia(url string, requestArgs map[string]string) (string, string, e log.Error().Msgf("failed to capture stderr: %v", errStderr) } + moveJsonFiles(id) + return id, "", nil } +func moveJsonFiles(id string) { + root := getMediaDirectory(id) + jsonDir := downloadDir + "json/" + + if err := os.MkdirAll(jsonDir, 0755); err != nil { + log.Error().Msgf("failed to create json dir: %v", err) + return + } + + file, err := os.Open(root) + if err != nil { + return + } + files, _ := file.Readdirnames(0) + file.Close() + + for _, f := range files { + if strings.HasSuffix(f, ".json") { + src := root + f + dst := jsonDir + f + if err := os.Rename(src, dst); err != nil { + log.Error().Msgf("failed to move json %s: %v", f, err) + } else { + log.Info().Msgf("moved json metadata to %s", dst) + } + } + } +} + func getMediaDirectory(id string) string { return downloadDir + id + "/" } diff --git a/tidy.sh b/tidy.sh old mode 100755 new mode 100644