Пример #1
0
    def create_video_from_json(self, _video):
        video = BaseVideo()
        video.id = u'%s' % _video['id']
        video.backend = u'%s' % _video['id'].split('@')[-1]

        if 'url' in _video.keys():
            video.url = u'%s' % _video['url']

        if 'thumbnail' in _video.keys() and _video['thumbnail'] and 'url' in _video['thumbnail'].keys():
            video.thumbnail = BaseImage()
            video.thumbnail.url = u'%s' % _video['thumbnail']['url']
        else:
            video.thumbnail.url = u''
        video.title = u'%s' % _video['title']

        if _video['date']:
            _date = re.search('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*', _video['date'])

            try:
                datetime.strptime(_date.group(1), '%Y-%m-%d %H:%M:%S')
            except TypeError:
                datetime(*(time.strptime(_date.group(1), '%Y-%m-%d %H:%M:%S')[0:6]))

        video.description = u'%s' % _video['description']
        video.author = u'%s' % _video['author']

        if _video['duration']:
            _duration = _video['duration'].split(':')
            video.duration = timedelta(hours=int(_duration[0]), minutes=int(_duration[1]), seconds=int(_duration[2]))

        return video
Пример #2
0
 def separate_collections_and_videos(self, objs):
     videos = []
     categories = []
     for obj in objs:
         if self.is_category(obj):
             categories.append(self.create_category_from_json(obj))
         else:
             video = BaseVideo()
             video.id = obj['id'].split('@')[0]
             video.backend = obj['id'].split('@')[-1]
             videos.append(video)
     return categories, videos