1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# coding=utf8
from __future__ import unicode_literals, absolute_import, print_function
import datetime
import pili
import time
import logging
import traceback
from django.conf import settings
from django.db import models
from django.db import transaction
from django.utils import timezone
from gm_types.gaia import TOPIC_TYPE, LIVE_MSG_TYPE, LIVE_STATUS
from gm_upload import ImgUrlField, IMG_TYPE
from talos.cache.live import live_view_max_cache
from talos.cache.live import live_view_num_cache, live_user_enter_time_cache
from talos.cache.live import live_view_sum_cache, live_fake_vote_cache
from talos.libs.datetime_utils import ts_now_as_score
from talos.libs.image_utils import get_full_path
from talos.models.topic import ProblemTag, Problem
from talos.rpc import CODES
from talos.rpc import gen
from talos.rpc import logging_exception
from talos.services.doctor import DoctorService
from talos.services.goods import GoodsService
from talos.services.hospital import HospitalService
from talos.services.tag import TagService
from talos.services.user import UserService
from utils.tasks import common_push
class ShortvideoBlackList(models.Model):
class Meta:
verbose_name = u'小视频黑名单'
app_label = 'api'
db_table = 'api_shortvideo_black_list'
user_id = models.IntegerField(verbose_name=u'小视频用户名')
is_online = models.BooleanField(verbose_name=u'是否生效')
class LiveChannel(models.Model):
class Meta:
verbose_name = u'直播频道'
app_label = 'talos'
db_table = 'api_live_channel'
person_id = models.CharField(verbose_name=u'用户外键id', max_length=64)
created_time = models.DateTimeField(verbose_name=u'创建时间', default=timezone.now)
updated_time = models.DateTimeField(verbose_name=u'更新时间', default=timezone.now)
title = models.CharField(verbose_name=u'标题', max_length=128, default='')
cover_url = models.CharField(verbose_name=u'封面地址', max_length=128, default='')
status = models.BooleanField(verbose_name='是否直播', default=False)
def data(self, user):
stream = self.now_stream
return stream.data(user)
def empty_data(self, user):
social_info = None
if user:
from social.models import SocialInfo
social_info = SocialInfo(uid=user.id)
self_user = UserService.get_user_by_person_id(self.person_id)
is_following = social_info and social_info.is_following_user(uid=self_user.id) or False
return {
"id": self.id,
"user_portrait": self_user.portrait,
"uname": self_user.nickname,
'title': self_user.nickname + u'的直播间',
'audience_num': 0,
'is_following': is_following,
'url': '',
'cover_url': get_full_path(self.cover_url, '-w'),
'user_id': self_user.id,
'status': self.status,
'm_url': '',
'stream_id': self.id,
'tags': [],
'channel_id': self.id,
'membership_level': self_user.membership_level,
}
@property
def now_stream(self):
return self.streams.order_by('-id').first()
@property
def live_view_num(self):
return self.now_stream.live_view_num
def add_view_num(self):
return self.now_stream.add_view_num()
def sub_view_num(self):
return self.now_stream.sub_view_num()
class LiveStream(models.Model):
class Meta:
verbose_name = u'直播流'
app_label = 'talos'
db_table = 'api_live_stream'
channel = models.ForeignKey(LiveChannel, null=True, related_name=u'streams')
status = models.BooleanField(verbose_name='是否直播', default=False)
created_time = models.DateTimeField(verbose_name=u'创建时间', default=timezone.now)
updated_time = models.DateTimeField(verbose_name=u'更新时间', default=timezone.now)
stream_key = models.CharField(verbose_name=u'直播流的key', max_length=128, default='', db_index=True)
save_replay_url = models.CharField(verbose_name=u'直播流的回放地址', max_length=128, default='', db_index=True)
title = models.CharField(verbose_name=u'标题', max_length=128, default='')
cover_url = models.CharField(verbose_name=u'封面地址', max_length=128, default='')
topic = models.OneToOneField(Problem, related_name=u'stream', null=True)
is_finish = models.BooleanField(verbose_name='是否关闭', default=False)
# 这个字段是给统计使用
max_view_num = models.IntegerField(verbose_name=u'最大在线人数', default=0)
# 弹幕回放
replay_danmu = models.TextField(verbose_name=u'弹幕回放')
# 美购相关
hospital_id = models.CharField(verbose_name=u'医院外建', null=True, max_length=100)
service_id = models.CharField(verbose_name=u'美购外建', null=True, max_length=100)
def get_live_stream_user_id(self):
try:
person_id = list(LiveChannel.objects.filter(id=self.channel.id).values_list("person_id", flat=True))
logging.info("get ----person:%s" % person_id)
return person_id[0]
except:
logging_exception()
return None
@classmethod
def create_stream(cls, user, channel, title, cover_url, tag_id, hospital_id=None, service_id=None):
with transaction.atomic():
stream_key = 'live' + str(int(time.time())) + u'_' + str(user.id)
stream = LiveStream()
stream.channel = channel
stream.status = False
stream.stream_key = stream_key
stream.title = title
stream.cover_url = cover_url
stream.hospital_id = hospital_id
stream.service_id = service_id
stream.save()
LiveStreamTag(live_stream=stream, tag_id=tag_id).save()
live_fake_vote_cache.setex(str(stream.id), 60 * 10, 0)
from live.tasks import calc_sleep_user_for_prepare
calc_sleep_user_for_prepare.delay(stream.id)
return stream
@classmethod
def create_or_update_stream(cls, stream, user, channel, title, cover_url, tag_id, hospital_id=None,
service_id=None):
if stream.check_stream_status_from_qiniu():
gen(CODES.LIVE_IS_CONTINUE)
stream = LiveStream.objects.filter(channel=channel).order_by('-updated_time').first()
timedetla = datetime.datetime.now() - stream.updated_time
if (timedetla.seconds > settings.LIVE_TIME_OUT and not stream.status) or stream.is_finish:
stream = LiveStream.create_stream(user, channel, title, cover_url, tag_id, hospital_id, service_id)
create_live = True
else:
stream.update_stream(title, cover_url, tag_id, hospital_id, service_id)
create_live = False
return stream, create_live
def update_stream(self, title, cover_url, tag_id, hospital_id=None, service_id=None):
with transaction.atomic():
self.updated_time = datetime.datetime.now()
self.title = title
self.cover_url = cover_url
if hospital_id:
self.hospital_id = hospital_id
if service_id:
self.service_id = service_id
streamtag = LiveStreamTag.objects.filter(live_stream=self).first()
if streamtag:
streamtag.tag_id = tag_id
streamtag.save()
self.save()
def check_stream_status_from_qiniu(self):
if not self.status:
return False
mac = pili.Mac(settings.QINIU_ACCESS_KEY, settings.QINIU_SECRET_KEY)
client = pili.Client(mac)
hub = client.hub(settings.QINIU_HUB_NAME)
s = hub.get(self.stream_key)
try:
# qiniu nolive 会抛异常
s.status()
return True
except:
return False
@property
def live_status_stream(self):
if self.is_finish:
return False
timedetla = datetime.datetime.now() - self.updated_time
if timedetla.seconds > settings.LIVE_TIME_OUT and self.status is False:
return False
if timedetla.seconds < settings.LIVE_TIME_OUT and self.status is False:
return True
return self.status
@property
def live_status(self):
if self.live_status_stream:
return LIVE_STATUS.LIVE
else:
return LIVE_STATUS.NOLIVE
def data(self, user):
social_info = None
if user:
from social.models import SocialInfo
social_info = SocialInfo(uid=user.id)
self_user = UserService.get_user_by_person_id(self.channel.person_id)
is_following = social_info and social_info.is_following_user(uid=self_user.id) or False
channel = self.channel
return {
"id": self.id,
"user_portrait": self_user.portrait,
"uname": self_user.nickname,
'title': self.title,
'audience_num': channel.live_view_num,
'is_following': is_following,
'url': self.url,
'cover_url': get_full_path(self.cover_url, '-w'),
'user_id': self_user.id,
'status': self.live_status,
'm_url': self.m_url,
'stream_id': self.id,
'tags': self.get_tags(),
'channel_id': channel.id,
'membership_level': self_user.membership_level,
'user_level': {
'membership_icon': self_user.membership_icon,
'level_icon': self_user.level_icon,
'constellation_icon': self_user.constellation_icon,
},
}
def data_v1(self, user):
'''
新版灰度首页返回的数据格式
:return:
'''
result = self.data(user)
new_info = {
'content': '',
'comment_num': self.livemsg_set.count(),
'vote_num': live_fake_vote_cache.get(str(self.id)).decode() if live_fake_vote_cache.get(str(self.id)) else 0
}
result.update(new_info)
return result
def data_for_redis(self):
return {
'id': self.id,
'title': self.title
}
def replay_data(self, user):
data = self.data_live(user)
data['status'] = self.live_status
data['url'] = settings.QINIU_REPLAY_LIVE_DOMAIN + self.save_replay_url
data['topic_id'] = self.topic.id
view_num = int(self.topic.view_num)
data['audience_num'] = str(view_num + self.live_view_num)
return data
def replay_data_for_list(self, user):
data = self.data(user)
data['status'] = self.live_status
data['url'] = settings.QINIU_REPLAY_LIVE_DOMAIN + self.save_replay_url
data['topic_id'] = self.topic.id
view_num = int(self.topic.view_num)
data['audience_num'] = str(view_num + self.live_view_num)
return data
def get_topic_reply_info(self):
return {
'source': settings.QINIU_REPLAY_LIVE_DOMAIN + self.save_replay_url,
'cover': get_full_path(self.cover_url, '-w'),
'content': self.title
}
@property
def url(self):
return pili.rtmp_play_url(settings.QINIU_LIVE_DOMAIN,
settings.QINIU_HUB_NAME, self.stream_key)
@property
def m_url(self):
return pili.hls_play_url(settings.QINIU_LIVE_DOMAIN,
settings.QINIU_HUB_NAME, self.stream_key)
@property
def live_view_num(self):
try:
num = live_view_num_cache.get(str(self.id))
if num:
num = int(num)
return self.display_num(num)
else:
return 0
except ValueError:
return 0
def display_num(self, num):
if 0 < num <= 10:
result = num
elif 10 < num <= 50:
result = num * 53
elif num > 50:
result = num * 103
else:
result = 0
return int(result + self.get_addition_view_num())
def create_topic(self):
self_user = UserService.get_user_by_person_id(self.channel.person_id)
with transaction.atomic():
topic = Problem()
topic.user_id = self_user.id
topic.topic_type = TOPIC_TYPE.TOPIC
topic.ask = self.title
topic.save()
try:
tag = self.tags[0]
ProblemTag.objects.get_or_create(problem_id=topic.id, tag_id=tag.id)
except IndexError:
pass
self.topic = topic
self.save()
# push to the liver fans
common_push.delay(uname=self_user.nickname, uid=self_user.id, topic_id=self.channel.id, push_type="live")
Problem.set_view_amount_of_id(topic.id, self.live_view_num)
@property
def tags(self):
tag_ids = LiveStreamTag.objects.filter(live_stream_id=self.id).values_list('tag_id', flat=True)
tag_ids = list(tag_ids)
tags = TagService.get_tags_by_tag_ids(tag_ids)
return tags
def get_tags(self):
"""problems's tags."""
ts = []
for tag in self.tags:
data = {'name': tag.name, 'tag_id': tag.id, "tag_type": tag.tag_type}
ts.append(data)
return ts
def set_first_user_enter_time_cache(self):
start_time = ts_now_as_score()
if not live_user_enter_time_cache.get(str(self.id)):
live_user_enter_time_cache.set(str(self.id), start_time)
def clear_redis_info(self):
from live.managers import LiveMsgManager
live_msg_manager = LiveMsgManager()
live_msg_manager.clear_redis(self.id)
# 删除统计相关星系
self.max_view_num = live_view_max_cache.get(str(self.id))
self.save()
live_view_max_cache.delete(str(self.id))
live_view_sum_cache.delete(str(self.id))
def add_view_num(self):
try:
live_view_num_cache.incr(str(self.id), 1)
live_view_sum_cache.incr(str(self.id))
self.set_live_view_max_num()
except:
logging_exception()
def get_addition_view_num(self):
result = 0
start_time = live_user_enter_time_cache.get(str(self.id))
if not start_time:
return 0
now_time = ts_now_as_score()
if start_time:
num = int(now_time) - int(start_time)
if num <= 0:
result = 0
elif 1 <= num <= 300:
result = num * 34
elif 301 <= num <= 600:
result = int(32.78 * num + 333.22)
elif 601 <= num <= 1200:
result = int(8.35 * num + 14982.87)
elif num >= 1200:
result = 25003
return result
def set_live_view_max_num(self):
try:
num = live_view_max_cache.get(str(self.id))
now_num = live_view_num_cache.get(str(self.id))
if num and now_num and int(num) < int(now_num):
live_view_max_cache.set(str(self.id), now_num)
elif int(now_num):
live_view_max_cache.set(str(self.id), now_num)
except ValueError:
logging_exception()
def sub_view_num(self):
try:
num = live_view_num_cache.decr(str(self.id))
if num <= 0:
live_view_num_cache.incr(str(self.id))
except:
logging_exception()
def set_status(self, flag):
now = datetime.datetime.now()
channel = self.channel
with transaction.atomic():
self.status = flag
channel.status = flag
self.updated_time = now
channel.updated_time = now
self.save(update_fields=['status', 'updated_time'])
channel.save(update_fields=['status', 'updated_time'])
def data_live(self, user):
result = self.data(user)
hospital_data = {}
if self.hospital_id:
hospital = HospitalService.get_hospital_info_by_hospital_id(self.hospital_id)
if hospital:
hospital_data = hospital
hospital_data['portrait'] = get_full_path(hospital['portrait'], '-half')
result['hospital'] = hospital_data
result['show_hospital'] = True if hospital_data else False
service_data = {}
if self.service_id:
service = GoodsService.get_live_service_info_by_id(self.service_id)
if service:
service_data = service
result['service'] = service_data
result['show_service'] = True if service_data else False
result['is_doctor'] = DoctorService.if_person_is_doctor(self.channel.person_id)
return result
@classmethod
def batch_data(cls, streams, user):
data = []
social_info = None
if user:
from social.models import SocialInfo
social_info = SocialInfo(uid=user.id)
person_ids = [stream.channel.person_id for stream in streams]
persons = UserService.get_users_by_person_ids(person_ids)
for stream in streams:
pid = stream.channel.person_id
data.append({
"id": stream.id,
"user_portrait": persons[pid].portrait,
"uname": persons[pid].nickname,
'title': stream.title,
'audience_num': stream.channel.live_view_num,
'is_following': social_info and social_info.is_following_user(uid=persons[pid].id) or False,
'url': stream.url,
'cover_url': get_full_path(stream.cover_url, '-w'),
'user_id': persons[pid].id,
'status': stream.live_status,
'm_url': stream.m_url,
'stream_id': stream.id,
'tags': stream.get_tags(),
'channel_id': stream.channel.id,
'hospital_id': stream.hospital_id,
'service_id': stream.service_id,
'person_id': pid,
'membership_level': persons[pid].membership_level,
'user_level': {
'membership_icon': persons[pid].membership_icon,
'level_icon': persons[pid].level_icon,
'constellation_icon': persons[pid].constellation_icon,
},
'topic_id': stream.topic.id if stream.topic else None,
'topic_view_num': int(stream.topic.view_num) if stream.topic else 0,
'save_replay_url': stream.save_replay_url,
})
return data
@classmethod
def batch_replay_data(cls, streams, user):
data = cls.batch_data_live(streams, user)
for stream in data:
stream['url'] = settings.QINIU_REPLAY_LIVE_DOMAIN + stream['save_replay_url']
stream['audience_num'] = str(stream['topic_view_num'] + stream['audience_num'])
return data
@classmethod
def batch_data_live(cls, streams, user):
data = cls.batch_data(streams, user)
hospital_ids = [stream.hospital_id for stream in streams if stream.hospital_id]
hospitals = HospitalService.get_hospital_info_by_ids(hospital_ids)
service_ids = [stream.service_id for stream in streams if stream.service_id]
services = GoodsService.get_live_service_info_by_ids(service_ids)
person_ids = [stream.channel.person_id for stream in streams]
doctors = DoctorService.list_doctors_by_person_ids(person_ids)
for stream in data:
hospital = stream["hospital_id"] and hospitals.get(str(stream["hospital_id"])) or {}
if hospital:
hospital['portrait'] = get_full_path(hospital['portrait'], '-half')
stream['hospital'] = hospital
stream['show_hospital'] = bool(hospital)
service = services[str(stream["service_id"])] if stream["service_id"] else {}
stream['service'] = service
stream['show_service'] = bool(service)
doctor = doctors.get(str(stream["person_id"]), None)
stream['is_doctor'] = True if doctor else False
stream['doctor'] = doctor
return data
def get_topic_is_online(self):
try:
topic_id = list(set(LiveStream.objects.filter(id=self.id).values_list("topic", flat=True)))
if topic_id:
is_online = list(set(Problem.objects.filter(id=topic_id[0]).values_list("is_online", flat=True)))
if is_online:
return is_online[0]
else:
return None
return None
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
class LiveStreamTag(models.Model):
class Meta:
app_label = 'talos'
db_table = 'api_streamtag'
live_stream = models.ForeignKey(LiveStream)
tag_id = models.IntegerField()
def __unicode__(self):
return "%s:%d" % (self.tag_id, self.live_stream_id)
class LiveWhiteList(models.Model):
class Meta:
verbose_name = u'直播白名单'
app_label = 'talos'
db_table = 'api_live_white_list'
user_id = models.IntegerField(verbose_name=u'用户外键id')
is_online = models.BooleanField(verbose_name=u'是否生效')
class LiveMsg(models.Model):
class Meta:
verbose_name = u'弹幕数据'
app_label = 'talos'
db_table = 'api_live_msg'
person_id = models.CharField(verbose_name=u'用户外键id', max_length=64)
stream = models.ForeignKey(LiveStream)
msg = models.CharField(verbose_name=u'标题', max_length=128, default='')
created_time = models.DateTimeField(verbose_name=u'创建时间', default=timezone.now, db_index=True)
type = models.IntegerField(verbose_name=u'消息类型', default=LIVE_MSG_TYPE.TEXT_MSG)
is_vest_send = models.BooleanField(verbose_name=u'是否为马甲用户发送', default=False)
def data(self):
if self.type == int(LIVE_MSG_TYPE.NOTIFI_MSG):
uname = ''
else:
self_user = UserService.get_user_by_person_id(self.person_id)
uname = self_user.nickname
return {
'id': self.id,
'text': self.msg,
'name': uname,
'type': self.type
}
class ZhiboConfig(models.Model):
class Meta:
verbose_name = u'直播配置信息'
verbose_name_plural = u'直播配置信息'
db_table = 'api_zhiboconfig'
app_label = 'talos'
description = models.CharField(max_length=10, verbose_name=u'描述')
foreshowcover_img = ImgUrlField(img_type=IMG_TYPE.ZHIBO, max_length=128, verbose_name=u'预告封面图片')
foreshowpage_img = ImgUrlField(img_type=IMG_TYPE.ZHIBO, max_length=128, verbose_name=u'预告页面图片')
# 首页Feed流所需图片
trailer_image = ImgUrlField(img_type=IMG_TYPE.ZHIBO, max_length=128, verbose_name=u'首页直播预告')
cover_image = ImgUrlField(img_type=IMG_TYPE.ZHIBO, max_length=128, verbose_name=u'首页直播封面')
anchor_user_id = models.IntegerField(verbose_name=u'用户外键id')
start_time = models.DateTimeField(verbose_name=u'开始时间')
end_time = models.DateTimeField(verbose_name=u'结束时间')
zhibo_time = models.DateTimeField(verbose_name=u'直播时间')
is_online = models.BooleanField(default=False, verbose_name=u'是否上线')
is_shouyejingxuan = models.BooleanField(default=False, verbose_name=u'是否在首页-精选显示')
is_shouyezhibo = models.BooleanField(default=False, verbose_name=u'是否在首页-直播显示')
is_zhiboliebiao = models.BooleanField(default=False, verbose_name=u'是否在直播列表页显示')
adorder_id = models.CharField(max_length=12, verbose_name=u'广告订单ID', null=True)
# 完整描述 2017-05-15
full_desc = models.CharField(max_length=500, verbose_name=u'完整描述', default='')
def data_for_backend(self, user, trailer=True):
social_info = None
if user:
from social.models import SocialInfo
social_info = SocialInfo(uid=user.id)
is_following = social_info and social_info.is_following_user(uid=self.anchor_user_id) or False
self_user = UserService.get_user_by_user_id(self.anchor_user_id)
from live.managers import get_or_create_channel_by_user_id
return {
'id': self.id,
'conf_id': self.id,
'user_id': self.anchor_user_id,
'user_portrait': self_user.portrait,
'title': self.full_desc,
'desc': self.description,
'is_following': is_following,
"uname": self_user.nickname,
'cover_url': get_full_path(self.foreshowcover_img, '-w'),
'choice_cover_url': get_full_path(self.trailer_image) if trailer else get_full_path(self.cover_image),
'status': int(LIVE_STATUS.NOTICE),
'membership_level': self_user.membership_level,
'channel_id': get_or_create_channel_by_user_id(self.anchor_user_id).id,
'stream_id': 0, # 无效字段 只是用来占位 方便客户端填充结构
'tags': [], # 无效字段 只是用来占位 方便客户端填充结构
'audience_num': 0, # 无效字段 只是用来占位 方便客户端填充结构
'url': '',
'content': self.full_desc,
"zhibo_time": self.zhibo_time.timestamp(),
"comment_num": 0,
"vote_num": 0,
"user_level": {
'level_icon': self_user.level_icon,
'membership_icon': self_user.membership_icon,
'constellation_icon': self_user.constellation_icon,
},
}
def data_for_ship(self):
from live.managers import get_or_create_channel_by_user_id
channel = get_or_create_channel_by_user_id(self.anchor_user_id)
return {
'desc': self.description,
'background': self.foreshowpage_img,
'channel_id': channel.id,
# 7.0 add share_data
'cover_url': get_full_path(self.foreshowcover_img, '-w'),
'uname': UserService.get_user_by_person_id(channel.person_id).nickname,
'start_time': "{}月{}日 {}: {}".format(
self.zhibo_time.month, self.zhibo_time.day,
"%02d" % self.zhibo_time.hour, "%02d" % self.zhibo_time.minute
),
}