Skip to content

Commit

Permalink
Merge pull request #116 from VasilisTako/spotify_login
Browse files Browse the repository at this point in the history
Added new login with spotify
  • Loading branch information
TheJoin95 authored Mar 14, 2024
2 parents 1bcbca8 + b7adbb7 commit b02b82f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ANCHOR_EMAIL=user@domain
ANCHOR_PASSWORD=password
SPOTIFY_EMAIL=user@domain
SPOTIFY_PASSWORD=password
2 changes: 2 additions & 0 deletions .github/workflows/upload-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ jobs:
env:
ANCHOR_EMAIL: ${{ secrets.ANCHOR_EMAIL }}
ANCHOR_PASSWORD: ${{ secrets.ANCHOR_PASSWORD }}
SPOTIFY_EMAIL: ${{ secrets.SPOTIFY_EMAIL }}
SPOTIFY_PASSWORD: ${{ secrets.SPOTIFY_PASSWORD }}
EPISODE_PATH: /github/workspace
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,31 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Upload Episode from YouTube To Anchor.Fm
uses: Schrodinger-Hat/youtube-to-anchorfm@v2.0.0
uses: Schrodinger-Hat/youtube-to-anchorfm@v2.3.0
env:
ANCHOR_EMAIL: ${{ secrets.ANCHOR_EMAIL }}
ANCHOR_PASSWORD: ${{ secrets.ANCHOR_PASSWORD }}
SPOTIFY_EMAIL: ${{ secrets.SPOTIFY_EMAIL }}
SPOTIFY_PASSWORD: ${{ secrets.SPOTIFY_PASSWORD }}
EPISODE_PATH: /github/workspace
```
**NOTE**: you need to [set up the secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository) for _ANCHOR_EMAIL_ and _ANCHOR_PASSWORD_. This environment variables are mandatory as they specify the sign in account.
**NOTE**: you need to [set up the secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository) for _ANCHOR_EMAIL_ and _ANCHOR_PASSWORD_. This environment variables are mandatory as they specify the sign in account.
Instead the _SPOTIFY_EMAIL_ and _SPOTIFY_PASSWORD_ are not mandatory but can still be set, if needed, and will be used for the new login form if the env variable _ANCHOR_LOGIN_ is set to false.
## Environment variables
### Login Type
Setting the `ANCHOR_LOGIN` to true makes the script login with the old anchor login type. Instead setting it to false makes the script login with the spotify account. By default the value is true.

```yaml
env:
ANCHOR_LOGIN: true
```

### Draft Mode

By setting the `SAVE_AS_DRAFT`, the new episode will be published as a draft. This can be useful if you need someone else's
Expand Down Expand Up @@ -203,6 +216,8 @@ jobs:
env:
ANCHOR_EMAIL: ${{ secrets.ANCHOR_EMAIL_GREATNEWS}} # OR secrets.ANCHOR_EMAIL_SADNEWS
ANCHOR_PASSWORD: ${{ secrets.ANCHOR_PASSWORD_GREATNEWS }} # OR secrets.ANCHOR_PASSWORD_SADNEWS
SPOTIFY_EMAIL: ${{ secrets.SPOTIFY_EMAIL_GREATNEWS }} # OR secrets.SPOTIFY_EMAIL_SADNEWS
SPOTIFY_PASSWORD: ${{ secrets.SPOTIFY_PASSWORD_GREATNEWS }} # OR secrets.SPOTIFY_PASSWORD_SADNEWS
EPISODE_PATH: /github/workspace/
EPISODE_FILE: great-news.json
# (…) Other configs as needed
Expand All @@ -225,6 +240,8 @@ To do that, you can copy `.env.sample` into a file with name `.env`.
Make sure to specify the mandatory environment variables for logging in to Anchor.fm,
`ANCHOR_EMAIL` and `ANCHOR_PASSWORD`.

If needed we can set the `SPOTIFY_EMAIL` and `SPOTIFY_PASSWORD` too, so they will be used to login with the new login type after changing `ANCHOR_LOGIN` to false.

Finally, you can do `npm start` to execute the script.

## How to upload a YouTube playlist to Anchor.fm using this script?
Expand Down
23 changes: 23 additions & 0 deletions src/anchorfm-pupeteer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ async function postEpisode(youtubeVideoInfo) {
}

async function login() {
if (env.ANCHOR_LOGIN) {
await anchorLogin();
} else {
await spotifyLogin();
}
}

async function anchorLogin() {
console.log('-- Accessing Spotify for Podcasters login page');
await clickXpath(page, '//button[contains(text(), "Continue")]');

Expand All @@ -127,6 +135,21 @@ async function postEpisode(youtubeVideoInfo) {
console.log('-- Logged in');
}

async function spotifyLogin() {
console.log('-- Accessing new Spotify login page for podcasts');
await clickXpath(page, '//span[contains(text(), "Continue with Spotify")]/parent::button');
console.log('-- Logging in');

await page.waitForSelector('#login-username');
await page.type('#login-username', env.SPOTIFY_EMAIL);
await page.type('#login-password', env.SPOTIFY_PASSWORD);
await sleepSeconds(1);
await clickSelector(page, 'button[id="login-button"]');
await clickSelector(page, 'button[data-testid="auth-accept"]');
await page.waitForNavigation();
console.log('-- In the app');
}

async function waitForNewEpisodeWizard() {
await sleepSeconds(1);
console.log('-- Waiting for episode wizard to open');
Expand Down
6 changes: 6 additions & 0 deletions src/environment-variables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ const dotenv = require('dotenv');
const defaultValues = {
EPISODE_PATH: '.',
EPISODE_FILE: 'episode.json',
ANCHOR_LOGIN: true,
ANCHOR_EMAIL: '',
ANCHOR_PASSWORD: '',
SPOTIFY_EMAIL: '',
SPOTIFY_PASSWORD: '',
UPLOAD_TIMEOUT: 60 * 5 * 1000,
SAVE_AS_DRAFT: false,
LOAD_THUMBNAIL: false,
Expand Down Expand Up @@ -63,8 +66,11 @@ function getCompleteEpisodePath() {

module.exports = {
EPISODE_PATH: getCompleteEpisodePath(),
ANCHOR_LOGIN: getBoolean(getEnvironmentVariable('ANCHOR_LOGIN')),
ANCHOR_EMAIL: getEnvironmentVariable('ANCHOR_EMAIL'),
ANCHOR_PASSWORD: getEnvironmentVariable('ANCHOR_PASSWORD'),
SPOTIFY_EMAIL: getEnvironmentVariable('SPOTIFY_EMAIL'),
SPOTIFY_PASSWORD: getEnvironmentVariable('SPOTIFY_PASSWORD'),
UPLOAD_TIMEOUT: getEnvironmentVariable('UPLOAD_TIMEOUT'),
SAVE_AS_DRAFT: getBoolean(getEnvironmentVariable('SAVE_AS_DRAFT')),
LOAD_THUMBNAIL: getBoolean(getEnvironmentVariable('LOAD_THUMBNAIL')),
Expand Down

0 comments on commit b02b82f

Please sign in to comment.