Skip to content

Commit

Permalink
2.1.1 (#6)
Browse files Browse the repository at this point in the history
* Convert TELEGRAM_CHANNEL to int if possible

* Update TELEGRAM_CHANNEL possible values in README and app.json

* Change Spotify invalid token error message to be clearer

* Add missing await for sending invalid Spotify token error message

* Improve Spotify error message for invalid token

* Close DeezLoader client after it's been used

* Improve the instructions for getting Spotify refresh token in README

* improve CHECK_TELEGRAM log

* Added missing await in update_playlist

* Bump Heroku runtime Python to 3.8.10

* Bump requirements

Co-authored-by: allerter <[email protected]>
  • Loading branch information
allerter and allerter authored May 15, 2021
1 parent e03f987 commit 6aa14f9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ Before continuing, install the packages in the
pip install -r requirements.txt

Now run `spotify_refresh_token.py` in the `setup` folder get your
refresh token. The script will ask for your Spotify app ID, app secret, and
then the link of the webpage after you click *Agree* (the link will be
someting like `https://example.com/callback?code=...`) You can run the script
from the command line:
refresh token. The script will ask for your Spotify app ID, app secret.
After your browser opens up and you click *Agree*, you will be redirected
to your redirected (the link will be
something like `https://example.com/callback?code=...`). Copy the full URL and
paste it in the console. Then the script will print out your refresh token.
You can run the script from the command line:

python spotify_refresh_token.py

Expand Down Expand Up @@ -109,7 +111,7 @@ driver installed. For example if you'll be using Postgres, you should have
The string session you generated using `string_session.py`

- **TELEGRAM\_CHANNEL**
The username of your Telegram channel
The username of your Telegram channel. It can also be the channel ID or an invite link.

- **DEEZER\_ARL\_TOKEN**
Your Deezer ARL token
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"required": true
},
"TELEGRAM_CHANNEL": {
"description": "The username of your Telegram channel",
"description": "The username of your Telegram channel. It can also be the channel ID or an invite link.",
"required": true
},
"DEEZER_ARL_TOKEN": {
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tekore>=3.7.0,<4.0.0
tekore>=3.7.1,<4.0.0
telethon>=1.21.1,<1.22.0
httpx[http2]>=0.17.1,<0.18.0
httpx[http2]>=0.18.1,<0.19.0
mutagen>=1.45.1,<1.46.0
sqlalchemy>=1.4.7,<1.5.0
sqlalchemy>=1.4.15,<1.5.0
pycryptodome>=3.10.1,<3.11.0
cryptg==0.2.post2
cryptg==0.2.post4
hachoir>=3.1.2,<3.2.0
fastapi>=0.63.0,<0.64.0
fastapi>=0.65.1,<0.66.0
uvicorn>=0.13.4,<0.14.0
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.8.9
python-3.8.10
12 changes: 7 additions & 5 deletions spotify_telegram_sync/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ async def update_playlist(
"Your Deezer ARL token is expired/invalid. "
"Replaced it with a new one."
)
telegram.send_message("me", msg)
await telegram.send_message("me", msg)
raise e
except Exception as e:
logger.error(
Expand All @@ -504,6 +504,7 @@ async def update_playlist(
else:
msg_id = None
upload_to_db_tracks.append((track[0], msg_id))
await deezer.close()

# add new tracks to database
await database.add_tracks(upload_to_db_tracks)
Expand Down Expand Up @@ -587,11 +588,12 @@ async def prepare_clients(
except tk.BadRequest as e:
if "invalid_grant" in str(e):
msg = (
"Your Spotify refresh token is expired. "
f"Replace it with a new one. Original error message: '{str(e)}'"
"Your Spotify refresh token is either expired or invalid. "
f"Original error message: '{str(e)}'"
)
telegram.send_message("me", msg)
await telegram.send_message("me", msg)
sys.exit(msg)
raise e
spotify = tk.Spotify(token, asynchronous=True)
clients["spotify"] = spotify
logger.debug("Spotify is ready.")
Expand Down Expand Up @@ -672,7 +674,7 @@ async def exception_handler(loop: asyncio.AbstractEventLoop, context: dict) -> N
logger.info("Update playlist: ✔️ | Update bio: ❌")
tasks.append(loop.create_task(update_playlist_loop()))
if constants.CHECK_TELEGRAM:
logger.info("Check Telegram: ✔️")
logger.info("Check Telegram for added/deleted tracks: ✔️")
tasks.append(loop.create_task(check_deleted()))
client.on(events.NewMessage(chats=(telegram_channel)))(new_message_handler)
else:
Expand Down
4 changes: 4 additions & 0 deletions spotify_telegram_sync/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
SPOTIFY_REFRESH_TOKEN = os.environ["SPOTIFY_REFRESH_TOKEN"]
SPOTIFY_PLAYLIST_ID = os.environ["SPOTIFY_PLAYLIST_ID"]
TELEGRAM_CHANNEL = os.environ["TELEGRAM_CHANNEL"]
try:
TELEGRAM_CHANNEL = int(TELEGRAM_CHANNEL)
except ValueError:
pass
DATABASE_URL = os.environ["DATABASE_URL"]
TELETHON_API_ID = os.environ["TELETHON_API_ID"]
TELETHON_API_HASH = os.environ["TELETHON_API_HASH"]
Expand Down

0 comments on commit 6aa14f9

Please sign in to comment.