Skip to content

Telegram Bot to share music with Odesli (former Songlink) service.

License

Notifications You must be signed in to change notification settings

9dogs/tg-odesli-bot

Repository files navigation

Telegram Odesli Bot

Send a song link in any (supported) music streaming service and get back a message with links in other services.

Add in Telegram: @odesli_bot

It's useful but still work in progress. Some turbulence is expected.

PyPI Azure build status Code coverage Supported versions License: GPL v3 Codestyle: Black

What is it for?

You love to share music with your friends (or be shared with), but you settled in different streaming services? With the help of this bot you can share any song link to the Bot and get all other links back in reply.

Powered by the great Odesli (former Songlink) service.

You can message the bot directly, invite it to group chats or use an inline mode (type @odesli_bot <URL>). In group chats the bot will react only to messages with music streaming links (it will also skip messages marked with special token !skip). You can promote the bot to a group admin and it will remove original message so that the chat remains tidy.

Original message Bot's replay
Original message Bot's reply

Features

  • Inline mode
  • Inline search mode
  • Private chat mode
  • Group chat mode

Supported services

Currently, the following services are supported:

  • Deezer
  • Google Music
  • SoundCloud
  • Yandex Music
  • Spotify
  • YouTube Music
  • YouTube
  • Apple Music
  • Tidal

Note that bot doesn't react to YouTube links in group chats. Reasons are here.

Privacy considerations

The bot have to have access to messages in group chats to operate (that is, it operates with disabled privacy mode). It does not store nor transfer messages anywhere. However, the only way to be completely private is to read through source code in this repository and run your copy of the bot (see section below). Or simply create a special group only for music sharing and where no sensitive information will be posted.

Running your own copy

Prerequisites

You need a Telegram bot token to run your copy of the bot. Don't worry, it can be obtained easily. Follow the instructions to create a new bot (you can set a name and a username to whatever you want). All you need is a string like 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw - this is your new bot token.

Additionally, disable privacy mode for your bot in a dialog with @BotFather: "Group Privacy" - "Turn off" (that is for the bot to be able to read group messages).

Bot from this repository will looks for TG_ODESLI_BOT_TG_API_TOKEN environment variable on start, thus you must set it either in shell or via .env file:

$ echo "<your_token>" > .env
$ # OR
$ TG_ODESLI_BOT_TG_API_TOKEN=<your_token> <bot_run_command (see below)>

Ones you obtain a Telegram bot token, you can run bot using either Python (3.10 or 3.11) or Docker.

Run PyPI version

Create virtual environment, install tg-odesli-bot package and run the bot with tg-odesli-bot command:

$ python -m venv botenv
$ source botenv/bin/activate
$ pip install tg-odesli-bot
$ TG_ODESLI_BOT_TG_API_TOKEN=<your_token> tg-odesli-bot

Run with Docker

Set TG_ODESLI_BOT_TG_API_TOKEN environment variable and run the image 9dogs/tg-odesli-bot (in order to use the .env file, mount it to /opt/tg-odesli-bot/.env):

$ docker run --rm -it -v /path/to/.env:/opt/tg-odesli-bot/.env 9dogs/tg-odesli-bot
# OR
$ TG_ODESLI_BOT_TG_API_TOKEN=<your_token> docker run -it --rm 9dogs/tg-odesli-bot

Run version from the repository

Clone this repository, install poetry, copy .env file into the project's root directory and run the bot:

$ git clone https://github.com/9dogs/tg-odesli-bot.git && cd tg-odesli-bot
# Install dependencies
$ poetry install
# If you have token in .env file
$ cp /path/to/.env ./
$ poetry run tg-odesli-bot
# If you specify token via shell env var
$ TG_ODESLI_BOT_TG_API_TOKEN=<your_token> poetry run tg-odesli-bot

Contributing

Contributions are welcome via GitHub pull requests. The easiest way to bootstrap development environment is to build builder target of Docker image:

$ git clone https://github.com/9dogs/tg-odesli-bot.git && cd tg-odesli-bot
$ docker build -t 9dogs/tg-odesli-bot:dev --target=builder --build-arg poetry_args= .

Then you can run a shell inside the container:

$ docker run -it --rm -v %cd%:/opt/tg-odesli-bot -v /opt/tg-odesli-bot/.venv 9dogs/tg-odesli-bot:dev bash
(container)$ make lint test