From 941696ad75b8b896bb3f32a4e9ce174144705bbc Mon Sep 17 00:00:00 2001 From: Nemo Date: Mon, 18 Apr 2022 18:18:01 +0530 Subject: [PATCH] Switch to environment variables, finish Docker --- .env.sample | 2 ++ .github/workflows/docker.yml | 41 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 +- Dockerfile | 6 +++--- README.md | 34 ++++++++++++++++++++++-------- config.sample.php | 4 ---- run.php | 20 ++++++++++++------ 7 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 .env.sample create mode 100644 .github/workflows/docker.yml delete mode 100644 config.sample.php mode change 100644 => 100755 run.php diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..948aee7 --- /dev/null +++ b/.env.sample @@ -0,0 +1,2 @@ +FORTELLER_EMAIL=email@example.com +FORTELLER_PASSWORD=password \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..943c0f1 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,41 @@ +name: Create and publish a Docker image + +on: + push: + branches: ['main'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@f2a13332ac1ce8c0a71aeac48a150dbb1838ab67 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 96dc56f..6cce51a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ Gloomhaven/ Jaws of the Lion/ -config.php \ No newline at end of file +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 593738c..3c9ea3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -FROM php:8-slim +FROM php:8-alpine -COPY *.php / +COPY *.php /src/ -ENTRYPOINT ["/usr/bin/php", "/src/run.php"] \ No newline at end of file +ENTRYPOINT ["/src/run.php"] \ No newline at end of file diff --git a/README.md b/README.md index 4334b75..547082d 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,46 @@ -# foreteller-dl +# forteller-dl -Download media from the https://www.foretellergames.com/ store without installing the application. The script behaves the same way as the application, and it can only download media that you will have access to, so please purchase the media from [fortellergames.com](https://www.fortellergames.com) before you run this script. +Download media from the https://www.fortellergames.com/ store without installing the application. The script behaves the same way as the application, and it can only download media that you will have access to, so please purchase the media from [fortellergames.com](https://www.fortellergames.com) before you run this script. Tested mainly against "Gloomhaven: Jaws of the Lion". ## Why? -I didn't like the application UX, so wrote this script instead to download the files. The app stretches the play/pause button on my iPhone SE and it looked very ugly. Plus, I can uninstall the app now and [play the files anywhere](www.defectivebydesign.org). Kudos for Foreteller for having a clean API and no DRM. +I didn't like the application UX, so wrote this script instead to download the files. The app stretches the play/pause button on my iPhone SE and it looked very ugly. Plus, I can uninstall the app now and [play the files anywhere](www.defectivebydesign.org). Kudos for Forteller for having a clean API and no DRM. ## How to use +First configure your credentials in the `.env` file. + +`cp .env.sample .env` + +Edit the .env file with your correct credentials. + +### Running using Docker + +```sh +# Set SKU to one of `ceph_gh`,`ceph_jaws`,`suc_mid1`,`ceph_fh`,`skg_iso` +docker run -it --init --volume "$HOME/Downloads:/downloads" --env-file .env ghcr.io/captn3m0/forteller-dl [SKU] /downloads +``` + +### Running using local PHP + You'll need php, php-curl installed, and replace {SKU} with a valid SKU (One of `ceph_gh`,`ceph_jaws`,`suc_mid1`,`ceph_fh`,`skg_iso`, but not all are available right now). ``` -git clone https://github.com/captn3m0/foreteller-dl.git -cd foreteller-dl -cp config.sample.php config.php -// Edit the config.php file to put your credentials -php run.php {SKU} +git clone https://github.com/captn3m0/forteller-dl.git +cd forteller-dl +set -a +source .env +set +a +php run.php {SKU} [/optional/path/to/output/dir] ``` ## TODO The script is functional enough for me, so this will likely never get done. But ideas: -- [ ] Run with Docker +- [x] Run with Docker - [ ] Cleanup code - [ ] API Documentation? - [ ] Tag the MP3 files as they are saved diff --git a/config.sample.php b/config.sample.php deleted file mode 100644 index e4ea61c..0000000 --- a/config.sample.php +++ /dev/null @@ -1,4 +0,0 @@ -EMAIL,"returnSecureToken"=>true,"password"=>PASSWORD]); + $body = json_encode(["email"=>$_ENV['FORTELLER_EMAIL'],"returnSecureToken"=>true,"password"=>$_ENV['FORTELLER_PASSWORD']]); curl_setopt_array($curl, [ CURLOPT_URL => "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=" . APP_KEY, @@ -97,6 +96,13 @@ if (!in_array($argv[1], ['ceph_gh','ceph_jaws','suc_mid1','ceph_fh','skg_iso'])) die("Invalid SKU"); } +$basedir = getcwd(); +if (isset($argv[2])) { + @mkdir($argv[2]); + $basedir = $argv[2]; + echo("Saving files in $basedir\n"); +} + $jwt = login(); $sku = $argv[1]; $game = null; @@ -109,7 +115,7 @@ foreach (json_decode(request(GAME_BASE_URL), true) as $game) { $gameName = $game['name']; -@mkdir($gameName); +@mkdir("$basedir/$gameName"); $containerUrl = GAME_BASE_URL . "/" . $game['id'] . "/containers"; $containers = request($containerUrl); @@ -123,7 +129,7 @@ foreach (json_decode($containers, true) as $c) { $trackName = $track['name']; $streamUrlParts = explode('/', $track['streamUri']); $trackUrl = AUDIO_BASE_URL . $streamUrlParts[2] . '/' . $streamUrlParts[3] . '/' . $streamUrlParts[4]; - $filename = "$gameName/$scenarioName - $trackName.mp3"; + $filename = "$basedir/$gameName/$scenarioName - $trackName.mp3"; echo "$filename\n"; if (!file_exists($filename)) { $track_data = request($trackUrl, 'audio/mpeg');