Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/umputun/rt-bot into optim…
Browse files Browse the repository at this point in the history
…ize_docker_images
  • Loading branch information
selevit committed Nov 20, 2016
2 parents f3d7ca7 + cb70af9 commit bdafeed
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -36,7 +36,7 @@ script:
- echo "Waiting 30 seconds to ensure if all bots are ready..."; sleep 30
- BOT_BASE_URL="https://localhost" python ci/run_bot_tests.py .
- |
if [ "$TRAVIS_BRANCH" = "master" ]; then
if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker login \
--username "$DOCKER_REGISTRY_LOGIN" \
--password "$DOCKER_REGISTRY_PASSWORD" \
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -38,6 +38,7 @@
- сделать PR со своим ботом в отдельном каталоге. Это хозяйство должно собираться и подниматься локально, через compose build + up
- в этом PR не забыть изменить `etc/nginx.conf` и `docker-compose.yml` для вашего бота
- Приложить README.md для своего бота
- Не забыть определить конфиг [`bot-spec.yml`](ci/README.md).

### Как проверить бот в реальной жизни?
- Ваш бот будет установлен на https://bot.radio-t.com
Expand Down
25 changes: 6 additions & 19 deletions ksenks-bot/audio.py
Expand Up @@ -10,7 +10,7 @@
import audioread


def get_frames_from_flv_or_mp3(chunk, tail=b''):
def get_frames_from_mp3(chunk, tail=b''):
def unpack_uint24_be(x):
if len(x) != 3:
return 0
Expand All @@ -32,25 +32,12 @@ def unpack_uint24_be(x):
current_frame_offset = next_frame_offset
tail = chunk[current_frame_offset:]
return mp3_frames, tail

# trying detect flv-container
signature = struct.unpack('3s', chunk[0:3])[0]
# skip flv header
if signature == b'FLV':
start_pos = 9
else:
start_pos = 0
while len(chunk) - start_pos > 15:
packet_type = chunk[start_pos + 4]
payload_size = unpack_uint24_be(chunk[start_pos + 5: start_pos + 8])
if len(chunk) <= start_pos + 15 + payload_size:
break
if packet_type == 8:
frame = chunk[start_pos + 16: start_pos + 15 + payload_size]
mp3_frames.append(frame)
start_pos = start_pos + 15 + payload_size
tail = chunk[start_pos:]
return mp3_frames, tail
# skipping part before mp3 frame marker
for i in range(len(chunk)-1):
if chunk[i] == 0xff and chunk[i + 1] >= 0xe0:
return mp3_frames, chunk[i:]
return mp3_frames, b''


def get_pcm_from_frames(all_frames):
Expand Down
4 changes: 3 additions & 1 deletion ksenks-bot/main.py
Expand Up @@ -188,7 +188,9 @@ async def process_stream(resp):
log.warn("Can't read audio stream")
break

frames, tail = audio.get_frames_from_flv_or_mp3(stream_chunk, tail)
frames, tail = audio.get_frames_from_mp3(stream_chunk, tail)
if not len(frames):
log.warn("Can't extract mp3 frames from mp3")
not_processed_frames += frames

if len(not_processed_frames) > 100:
Expand Down
6 changes: 5 additions & 1 deletion rtnumber-bot/main.py
Expand Up @@ -147,13 +147,17 @@ def is_one_of_cmds_in_input(cmds, input):
'темы пользователей!', '!темы пользователей'], input_text)
if command:
def gen_user_themes_text(posts_list, max_posts=0):
max_allowed_len = 4000
text_out = '**Темы слушателей:**\\n\\n'
if max_posts <= 0:
max_posts = len(posts_list)
for post in posts_list[:max_posts]:
likes = post['likes']
msg = post['raw_message'].replace('\n', ' ')
text_out += '* **[%+i]** %s\\n' % (likes, msg)
new_line = '* **[%+i]** %s\\n' % (likes, msg)
if len(text_out) + len(new_line) >= max_allowed_len:
break
text_out += new_line
return text_out

max_len = 0
Expand Down

0 comments on commit bdafeed

Please sign in to comment.