Skip to main content

Downloads MP3 rips of tracks/sets from SoundCloud, Bandcamp, YouTube with tags and artwork.

Project description

# [Music Downloader Telegram Bot](https://t.me/scdlbot)

[![Updates](https://pyup.io/repos/github/gpchelkin/scdlbot/shield.svg?token=376ffde2-5188-4912-bf3c-5f316e52d43f)](https://pyup.io/repos/github/gpchelkin/scdlbot/)
[![Python 3](https://pyup.io/repos/github/gpchelkin/scdlbot/python-3-shield.svg?token=376ffde2-5188-4912-bf3c-5f316e52d43f)](https://pyup.io/repos/github/gpchelkin/scdlbot/)
[![Telegram Bot](https://img.shields.io/badge/telegram-bot-blue.svg)](https://t.me/scdlbot)


## Bot Usage

Send `/start` or `/help` command to [bot](https://t.me/scdlbot) or refer directly to the [help message](scdlbot/messages/help.tg.md).

## Development

### TODO
- [Dokku webhooks support](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#using-haproxy-with-one-subdomain-per-bot)
- YouTube playlists support
- Split audio by 50 MB size for sending
- Disable privacy mode and check a subset of patterns
- Async download and send
- Something cool with Botan

### Supported sites and used packages

- [**Telegram Bot API**](https://core.telegram.org/bots/api): [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot)
- [**SoundCloud**](https://soundcloud.com): [scdl](https://github.com/flyingrub/scdl)
- [**Bandcamp**](https://bandcamp.com): [bandcamp-dl](https://github.com/iheanyi/bandcamp-dl)
- [**YouTube**](https://www.youtube.com/), [**Mixcloud**](https://www.mixcloud.com/), etc.: [youtube-dl](https://rg3.github.io/youtube-dl)
- Use [SoundScrape](https://github.com/Miserlou/SoundScrape) in the future?


### Installation

#### Requirements
Those should be available in your `PATH`:
- [**Python 3.6**](https://www.python.org/) ([pyenv](https://github.com/pyenv/pyenv) recommended)
- [**FFmpeg**](https://ffmpeg.org/download.html) for running locally (fresh builds for [Windows](https://ffmpeg.zeranoe.com/builds/) and [Linux](https://johnvansickle.com/ffmpeg/) recommended)
- [**Heroku CLI**](https://cli.heroku.com/) is recommended

#### Install from PyPI (preferred)
```
pip3 install scdlbot
```

#### Install from Git source
```
git clone https://github.com/gpchelkin/scdlbot.git
cd scdlbot
pip3 install --requirement requirements.txt

# If you want to install system-wide, not necessary:
python3 setup.py install
```

### Configuration

Copy config file sample and set up config environment variables in it:
```
cp .env.sample .env
nano .env
```

##### Required
- `TG_BOT_TOKEN`: Telegram Bot API Token, [obtain here](https://t.me/BotFather)
- `STORE_CHAT_ID`: Chat ID for storing audios for inline mode
- `SC_AUTH_TOKEN`: SoundCloud Auth Token, [obtain here](https://flyingrub.github.io/scdl/)

##### Optional
- `USE_WEBHOOK`: use polling for bot updates (default): `0`, use webhook: `1`, [more info](https://core.telegram.org/bots/api#getting-updates)
- `PORT`: Heroku sets this automatically for web dynos if you are using webhook
- `APP_URL`: Heroku App URL like `https://<appname>.herokuapp.com/`, required for webhook
- `BOTAN_TOKEN`: [Botan.io](http://botan.io/) [token](http://appmetrica.yandex.com/)
- `NO_CLUTTER_CHAT_IDS` — Comma-separated chat IDs with no replying and caption hashtags
- `BIN_PATH` — Custom directory with `scdl` and `bandcamp-dl` binaries are available, e.g. `~/.pyenv/shims/` if you use pyenv, default: empty
- `DL_DIR` — Parent directory for MP3 download directory, default: ~ (user's home directory)


### Running Locally

#### Using [Heroku Local](https://devcenter.heroku.com/articles/heroku-local#run-your-app-locally-using-the-heroku-local-command-line-tool) (preferred)
You need [Heroku CLI](https://cli.heroku.com/).
```
# for long polling:
heroku local worker
# for webhooks (you will also need to set up some NGINX with SSL):
heroku local web
```

#### Using just Python
```
export $(cat .env | xargs)
python3 -m scdlbot
# or just:
env $(cat .env | xargs) python3 -m scdlbot
```


### Deploying to [Heroku](https://heroku.com/)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

When app is deployed you **must** set only one dyno working on "Resources" tab in your app settings depending on [which way of getting updates](https://core.telegram.org/bots/api#getting-updates) you have chosen and set in config variables.


#### Manually
You can do the same as the button above but using [Heroku CLI](https://cli.heroku.com/), not much of a fun. Assuming you are in `scdbot` directory:

```
heroku login
# Create app with Python3 buildpack and set it for upcoming builds:
heroku create --buildpack heroku/python
heroku buildpacks:set heroku/python
# Add FFmpeg buildpack needed for youtube-dl:
heroku buildpacks:add --index 1 https://github.com/laddhadhiraj/heroku-buildpack-ffmpeg.git --app scdlbot
# Deploy app to Heroku:
git push heroku master
# Set config vars automatically from your .env file
heroku plugins:install heroku-config
heroku config:push

# Or set them one by one:
heroku config:set TG_BOT_TOKEN="<TG_BOT_TOKEN>" STORE_CHAT_ID="<STORE_CHAT_ID>" ...
```

If you use webhook:
```
# Start 1 web dyno:
heroku ps:scale web=1
# Stop worker dyno:
heroku ps:stop worker
```

If you use polling:
```
# Start 1 worker dyno:
heroku ps:scale worker=1
# Stop web dyno:
heroku ps:stop web
```

Some useful commands:
```
# Attach to logs:
heroku logs -t
# Test run ffprobe
heroku run "ffprobe -version"
```

### Deploying to [Dokku](https://github.com/dokku/dokku)

Use Dokku and their docs on your own server. App is tested and fully ready for deployment with polling (no webhooks yet).


# History

0.2.0 (2017-06-06)
------------------

* Webhooks and async

0.1.0 (2017-06-04)
------------------

* First usable and stable version.


Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scdlbot-0.2.0.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

scdlbot-0.2.0-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page