Skip to content

Commit

Permalink
feat(douyin): replace using event_time for danmaku generation
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Aug 9, 2023
1 parent adaccf8 commit 74311f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
6 changes: 3 additions & 3 deletions recorder/danmaku/caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def timer(self):
class Caption:
"""
iterator = [
{"content": "danmaku_content", "generation_time": "generation_time_from_mongodb_object_id"},
{"content": "danmaku_content", "generation_time": "generation_time_from_mongodb_object_id"},
{"content": "danmaku_content", "generation_time": "generation_time_from_mongodb_object_id"},
{"content": "danmaku_content", "generation_time": "danmaku_time"},
{"content": "danmaku_content", "generation_time": "danmaku_time"},
{"content": "danmaku_content", "generation_time": "danmaku_time"},
...
]
"""
Expand Down
25 changes: 9 additions & 16 deletions recorder/danmaku/douyin/douyin_danmaku_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
import time

import arrow
import bson

import recorder
from recorder import config, mongo_collection_douyin_danmaku as mongo_collection
from recorder import config, mongo_collection_douyin_danmaku as mongo_collection, TZ_INFO
from recorder.danmaku import parse_datetime, get_info_from_path, Caption
from recorder.destination.youtube import Youtube


def find_danmaku(room_id, start=None, end=None):
where_clause = {
'room_id': room_id,
'_id': {}
'event_time': {}
}

if start:
where_clause['_id']['$gt'] = bson.objectid.ObjectId.from_datetime(parse_datetime(start).datetime)
where_clause['event_time']['$gt'] = parse_datetime(start).int_timestamp
if end:
where_clause['_id']['$lt'] = bson.objectid.ObjectId.from_datetime(parse_datetime(end).datetime)
where_clause['event_time']['$lt'] = parse_datetime(end).int_timestamp

if not where_clause['_id']:
del where_clause['_id']
if not where_clause['event_time']:
del where_clause['event_time']

if not mongo_collection.count_documents(where_clause):
logging.critical(f'Mongo_collection empty, room_id: {room_id}, start: {start}, end: {end}')
Expand All @@ -35,7 +34,7 @@ def find_danmaku(room_id, start=None, end=None):
def prepare_iterator_for_caption(danmaku):
return (
{
'generation_time': each['_id'].generation_time,
'generation_time': each['event_time'],
'content': each['content'],
}
for each in danmaku
Expand Down Expand Up @@ -68,11 +67,9 @@ def add_caption_and_highlights_for_video(caption_path, highlights, video_id, sou


def watch(room_ids=None):
start_id = bson.objectid.ObjectId.from_datetime(arrow.now().datetime)

while True:
where_clause = {
'_id': {'$gt': start_id}
'event_time': {'$gt': arrow.now().int_timestamp}
}

if room_ids:
Expand All @@ -82,11 +79,7 @@ def watch(room_ids=None):

while cursor.alive:
for doc in cursor:
start_id = doc.get('_id')

generation_time = arrow.get(doc.get('_id').generation_time) \
.to('Asia/Hong_Kong') \
.format('YYYY-MM-DD HH:mm:ss')
generation_time = arrow.get(doc.get('event_time')).to(TZ_INFO).format('YYYY-MM-DD HH:mm:ss')
room_id = doc.get('room_id')
sender_nick = doc.get('nickname')
content = doc.get('content')
Expand Down

0 comments on commit 74311f4

Please sign in to comment.