Skip to content

Commit 34de090

Browse files
committed
0.6.2, different refinements and help handle in groups
1 parent fcba4a2 commit 34de090

File tree

6 files changed

+48
-32
lines changed

6 files changed

+48
-32
lines changed

HISTORY.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
History
33
=======
44

5+
0.6.2 (2017-07-04)
6+
------------------
7+
8+
* Help message in groups now redirects to PM
9+
10+
0.6.1 (2017-07-03)
11+
------------------
12+
13+
* Async run of download/send command
14+
* Link command
15+
516
0.6.0 (2017-07-02)
617
------------------
718

README.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ Optional
102102
- ``USE_WEBHOOK``: use webhook for bot updates: ``1``, use polling
103103
(default): ``0``, `more
104104
info <https://core.telegram.org/bots/api#getting-updates>`__
105-
- ``PORT``: Heroku sets this automatically for web dynos if you are
106-
using webhook
107-
- ``APP_URL``: Heroku App URL like
105+
- ``APP_URL``: app URL like
108106
``https://<appname>.herokuapp.com/``, required for webhook
107+
- ``PORT``: port for webhook to listen to; Heroku sets this automatically
108+
for web dynos
109109
- ``BOTAN_TOKEN``: `Botan.io <http://botan.io/>`__
110110
`token <http://appmetrica.yandex.com/>`__
111111
- ``NO_CLUTTER_CHAT_IDS``: Comma-separated chat IDs with no replying
@@ -117,6 +117,8 @@ Optional
117117
(user's home directory)
118118
- ``SYSLOG_ADDRESS``: Syslog server, for example ``logsX.papertrailapp.com:ABCDE``
119119
- ``HOSTNAME``: Hostname to show up in Syslog messages
120+
- ``GOOGL_API_KEY``: `Goo.gl URL shortener <https://goo.gl>`__
121+
`API key <https://developers.google.com/url-shortener/v1/getting_started#APIKey>`__
120122

121123
Telegram Settings
122124
^^^^^^^^^^^^^^^^^

scdlbot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# version as tuple for simple comparisons
3-
VERSION = (0, 6, 0)
3+
VERSION = (0, 6, 2)
44
# string created from tuple to avoid inconsistency
55
__version__ = ".".join([str(x) for x in VERSION])

scdlbot/__main__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
SYSLOG_ADDRESS = os.getenv('SYSLOG_ADDRESS', '')
1313
if SYSLOG_ADDRESS:
1414
syslog_hostname, syslog_udp_port = SYSLOG_ADDRESS.split(":")
15-
syslog_udp_port = int(syslog_udp_port)
16-
syslog_handler = SysLogHandler(address=(syslog_hostname, syslog_udp_port))
15+
syslog_handler = SysLogHandler(address=(syslog_hostname, int(syslog_udp_port)))
1716
logging_handlers.append(syslog_handler)
1817

19-
logging.basicConfig(format='%(asctime)s {} %(name)s: %(message)s'.format(os.getenv("HOSTNAME", "unknown_host")),
18+
logging.basicConfig(format='%(asctime)s {} %(name)s: %(message)s'.format(os.getenv("HOSTNAME", "test-host")),
2019
datefmt='%b %d %H:%M:%S',
21-
level=logging.DEBUG, handlers=logging_handlers)
20+
level=logging.DEBUG,
21+
handlers=logging_handlers)
2222

2323
logger = logging.getLogger(__name__)
2424

@@ -32,14 +32,14 @@ def main():
3232
dl_dir = os.path.expanduser(os.getenv('DL_DIR', '~'))
3333
use_webhook = bool(int(os.getenv('USE_WEBHOOK', '0')))
3434
app_url = os.getenv('APP_URL', '')
35-
app_port = int(os.getenv('PORT', '5000'))
35+
webhook_port = int(os.getenv('PORT', '5000'))
3636
bin_path = os.getenv('BIN_PATH', '')
3737
cert_file = os.getenv('CERT_FILE', '')
3838
google_shortener_api_key = os.getenv('GOOGL_API_KEY', '') # https://developers.google.com/url-shortener/v1/getting_started#APIKey
3939
scdlbot = SCDLBot(tg_bot_token, botan_token, google_shortener_api_key, bin_path,
4040
sc_auth_token, store_chat_id,
4141
no_clutter_chat_ids, dl_dir)
42-
scdlbot.run(use_webhook, app_url, app_port, cert_file)
42+
scdlbot.run(use_webhook, app_url, webhook_port, cert_file)
4343

4444

4545
if __name__ == '__main__':

scdlbot/scdlbot.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from urllib.parse import urljoin
1010
from urllib.request import URLopener
1111
from uuid import uuid4
12-
from time import sleep
12+
1313
import mutagen.id3
1414
import pkg_resources
1515
import youtube_dl
@@ -97,14 +97,14 @@ def __init__(self, tg_bot_token, botan_token, google_shortener_api_key, bin_path
9797

9898
dispatcher.add_error_handler(self.error_callback)
9999

100-
self.bot_username = "@scdlbot" # self.updater.bot.get_me().username
101-
self.RANT_TEXT = "[PLEASE PRESS HERE TO READ HELP IN MY PM](t.me/" + bot_username + "?start=1)"
100+
self.bot_username = self.updater.bot.get_me().username
101+
self.RANT_TEXT = "[PRESS HERE TO READ HELP IN PM](t.me/" + self.bot_username + "?start=1)"
102102

103-
def run(self, use_webhook=False, app_url=None, app_port=None, cert_file=None):
103+
def run(self, use_webhook=False, app_url=None, webhook_port=None, cert_file=None):
104104
if use_webhook:
105105
url_path = self.tg_bot_token.replace(":", "")
106106
self.updater.start_webhook(listen="0.0.0.0",
107-
port=app_port,
107+
port=webhook_port,
108108
url_path=url_path)
109109
self.updater.bot.set_webhook(url=urljoin(app_url, url_path))
110110
# ... certificate=open(cert_file, 'rb')
@@ -164,10 +164,11 @@ def rant_and_cleanup(self, bot, chat_id, rant_text):
164164
self.rant_msg_ids[chat_id].append(rant_msg.message_id)
165165

166166
def help_command_callback(self, bot, update, event_name="help"):
167+
chat_id = update.message.chat_id
167168
logger.debug(event_name)
168169
self.botan.track(update.message, event_name) if self.botan else None
169170
if update.message.chat.type == "private":
170-
bot.send_message(chat_id=update.message.chat_id, text=self.HELP_TEXT,
171+
bot.send_message(chat_id=chat_id, text=self.HELP_TEXT,
171172
parse_mode='Markdown', disable_web_page_preview=True)
172173
else:
173174
self.rant_and_cleanup(bot, chat_id, self.RANT_TEXT)
@@ -178,11 +179,11 @@ def clutter_command_callback(self, bot, update):
178179
self.botan.track(update.message, event_name) if self.botan else None
179180
if update.message.chat_id in self.NO_CLUTTER_CHAT_IDS:
180181
self.NO_CLUTTER_CHAT_IDS.remove(update.message.chat_id)
181-
bot.send_message(chat_id=update.message.chat_id, text="Chat will be cluttered with replies",
182+
bot.send_message(chat_id=update.message.chat_id, text="Chat will now be cluttered with replies",
182183
parse_mode='Markdown', disable_web_page_preview=True)
183184
else:
184185
self.NO_CLUTTER_CHAT_IDS.append(update.message.chat_id)
185-
bot.send_message(chat_id=update.message.chat_id, text="Chat will not be cluttered with replies",
186+
bot.send_message(chat_id=update.message.chat_id, text="Chat will now NOT be cluttered with replies",
186187
parse_mode='Markdown', disable_web_page_preview=True)
187188

188189
def inline_query_callback(self, bot, update):
@@ -280,10 +281,13 @@ def message_callback(self, bot, update):
280281

281282
def youtube_dl_get_direct_urls(self, url):
282283
try:
283-
direct_urls = self.youtube_dl("--get-url", url)
284+
ret_code, direct_urls, std_err = self.youtube_dl["--get-url", url].run()
285+
if "returning it as such" in std_err:
286+
return None
287+
else:
288+
return direct_urls
284289
except:
285-
direct_urls = None
286-
return direct_urls
290+
return None
287291

288292
def prepare_urls(self, text, get_direct_urls=False):
289293
urls = find_all_links(text, default_scheme="http")

scdlbot/texts/help.tg.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
*I download and send audios of videos/tracks/sets/albums in MP3 128 kbps with tags and artwork. Files over 50 MB are split into parts due to bot-sent file size limit. Supported sites:*
1+
I download and send audios of videos/tracks/sets/albums in MP3 128 kbps with tags and artwork. Files over 50 MB are split into parts due to bot-sent file size limit. Supported links:
22
*• SoundCloud*: tracks/playlists/pages with private widgets
3-
*• Bandcamp*: tracks/albums
3+
*• Bandcamp*: tracks/albums/custom links
44
*• YouTube*: videos/playlists
5-
*• Mixcloud, Vimeo and pretty much* [everything from the list](https://rg3.github.io/youtube-dl/supportedsites.html)
5+
*• Mixcloud, Vimeo and* [everything from this list](https://rg3.github.io/youtube-dl/supportedsites.html) (no VK music)
66

77
*Usage:*
88
• Send a message with links to the chat and I will download them instantly in private or ask you in groups. [Privacy mode](https://core.telegram.org/bots#privacy-mode) is _disabled_ so I parse all group messages for links. Forwarded messages work too. For example:
99
`Check it out! https://m.soundcloud.com/richarddjames/umil-25-01 and also https://shitmat.bandcamp.com/track/amen-babylon-2016-mix`
10-
• Use `/dl <link(-s)>` command to download instantly in groups.
11-
• Use `/link <link(-s)>` command to get URL for downloading locally.
10+
• Use `/dl <links>` to download instantly in groups.
11+
• Use `/link <links>` to just get URL for downloading.
1212

13-
🤖 @gpchelkin //[🐝👍.WS](http://xn--lo8h6c.ws/)
14-
🖼️ @lowonbudget //[👩‍🎨🎨️](https://www.behance.net/lowonbudget)
15-
🖤 @electrocircle //[⚡⚫.РФ](http://Электрокружок.РФ)
16-
[🌟GitHub](https://github.com/gpchelkin/scdlbot) // [💻Issues](https://github.com/gpchelkin/scdlbot/issues)
17-
18-
Not mine: @vkm\_bot @scloud\_bot @GetMusicBot
13+
*Credits // Emoji-links:*
14+
[🌟 @GitHub](https://github.com/gpchelkin/scdlbot) // [⌨️⚠](https://github.com/gpchelkin/scdlbot/issues)
15+
👨🏻‍💻 @gpchelkin // [🐝👍](http://xn--lo8h6c.ws/)
16+
👩🏻‍🎨 @lowonbudget // [🎨🖼️](https://www.behance.net/lowonbudget)
17+
🎶 @electrocircle // [⚡⚫](http://Электрокружок.РФ)

0 commit comments

Comments
 (0)