Example #1
0
 def analyze_program_page(code, page):
     try:
         data = Wavve.vod_program_contents_programid(code, page=page)
         return {'url_type': 'program', 'page':page, 'code':code, 'data' : data}
     except Exception as e: 
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())  
Example #2
0
    def analyze(url, quality=None):
        try:
            logger.debug('analyze :%s', url)
            url_type = None
            code = None
            corner_id = None
            vod_type = None
            if url.startswith('http'):
                match = re.compile(
                    r'contentid\=(?P<contentid>.*?)(\&|$|\#)').search(url)
                match2 = re.compile(
                    r'programid\=(?P<programid>.*?)(\&|$|\#)').search(url)
                if match:
                    code = match.group('contentid')
                    url_type = 'episode'
                elif match2:
                    url_type = 'program'
                    code = match2.group('programid')
                else:
                    match = re.compile(
                        r'movieid\=(?P<movieid>.*?)($|\#)').search(url)
                    if match:
                        url_type = 'movie'
                        code = match.group('movieid')
            else:
                if len(url.split('.')) == 2:
                    url_type = 'episode'
                    code = url.strip()
                elif url.startswith('MV_'):
                    url_type = 'movie'
                    code = url.strip()
                elif url.find('_') != -1:
                    url_type = 'program'
                    code = url.strip()
                else:
                    pass
            logger.debug('Analyze %s %s', url_type, code)
            if url_type is None:
                return {'url_type': 'None'}
            elif url_type == 'episode':
                if quality is None:
                    quality = ModelSetting.get('quality')
                data = Wavve.vod_contents_contentid(code)
                contenttype = 'onairvod' if data['type'] == 'onair' else 'vod'
                proxy = None
                data2 = Wavve.streaming(contenttype, code, quality,
                                        ModelSetting.get('credential'))
                try:
                    tmp = data2['playurl']
                except:
                    try:
                        LogicBasic.login()
                        data2 = Wavve.streaming(contenttype, code, quality,
                                                ModelSetting.get('credential'))
                    except:
                        pass

                #logger.debug(data2)
                data3 = {}
                data3['filename'] = Wavve.get_filename(data, quality)
                data3['preview'] = (data2['playurl'].find('preview') != -1)
                data3['current_quality'] = quality
                ModelSetting.set('recent_code', code)
                return {
                    'url_type': url_type,
                    'code': code,
                    'episode': data,
                    'streaming': data2,
                    'available': data3
                }
            elif url_type == 'program':
                data = Wavve.vod_program_contents_programid(code)
                ModelSetting.set('recent_code', code)
                return {
                    'url_type': url_type,
                    'page': '1',
                    'code': code,
                    'data': data
                }
            elif url_type == 'movie':
                if quality is None:
                    quality = ModelSetting.get('quality')
                data = Wavve.movie_contents_movieid(code)
                data2 = Wavve.streaming('movie', code, quality,
                                        ModelSetting.get('credential'))
                try:
                    tmp = data2['playurl']
                except:
                    try:
                        LogicBasic.login()
                        data2 = Wavve.streaming('movie', code, quality,
                                                ModelSetting.get('credential'))
                    except:
                        pass

                data3 = {}
                data3['filename'] = Wavve.get_filename(data, quality)
                data3['preview'] = (data2['playurl'].find('preview') != -1)
                data3['current_quality'] = quality
                ModelSetting.set('recent_code', code)
                return {
                    'url_type': url_type,
                    'code': code,
                    'info': data,
                    'streaming': data2,
                    'available': data3
                }
        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Example #3
0
    def process_ajax(self, sub, req):
        try:
            if sub == 'test':
                keyword = req.form['keyword'].strip()
                call = req.form['call']
                mode = req.form['mode']
                ModelSetting.set('ktv_%s_test_%s' % (call, mode), keyword)

                if call == 'total':
                    manual = (req.form['manual'] == 'manual')
                    if mode == 'search':
                        ret = {}
                        ret['search'] = self.search(keyword, manual=manual)
                        if 'daum' in ret['search']:
                            ret['info'] = self.info(
                                ret['search']['daum']['code'],
                                ret['search']['daum']['title'])
                        elif 'tving' in ret['search']:
                            ret['info'] = self.info(
                                ret['search']['tving'][0]['code'], '')
                        elif 'wavve' in ret['search']:
                            ret['info'] = self.info(
                                ret['search']['wavve'][0]['code'], '')
                elif call == 'daum':
                    if mode == 'search':
                        ret = {}
                        ret['search'] = SiteDaumTv.search(keyword)
                        if ret['search']['ret'] == 'success':
                            ret['info'] = self.info(
                                ret['search']['data']['code'],
                                ret['search']['data']['title'])

                elif call == 'wavve':
                    import framework.wavve.api as Wavve
                    if mode == 'search':
                        ret = Wavve.search_tv(keyword)
                    elif mode == 'info':
                        ret = {}
                        ret['program'] = Wavve.vod_programs_programid(keyword)
                        ret['episodes'] = []
                        page = 1
                        while True:
                            episode_data = Wavve.vod_program_contents_programid(
                                keyword, page=page)
                            ret['episodes'] += episode_data['list']
                            page += 1
                            if episode_data['pagecount'] == episode_data[
                                    'count']:  # or page == 6:
                                break
                elif call == 'tving':
                    import framework.tving.api as Tving
                    if mode == 'search':
                        ret = Tving.search_tv(keyword)
                    elif mode == 'info':
                        ret = {}
                        ret['program'] = Tving.get_program_programid(keyword)
                        ret['episodes'] = []
                        page = 1
                        while True:
                            episode_data = Tving.get_frequency_programid(
                                keyword, page=page)
                            for epi in episode_data['body']['result']:
                                ret['episodes'].append(epi['episode'])
                            page += 1
                            if episode_data['body']['has_more'] == 'N':
                                break
                return jsonify(ret)
        except Exception as e:
            P.logger.error('Exception:%s', e)
            P.logger.error(traceback.format_exc())
            return jsonify({'ret': 'exception', 'log': str(e)})
Example #4
0
    def _apply_tv_by_program(cls, show, program_info):
        try:
            show['extra_info']['wavve_id'] = program_info['programid']

            if True:
                show['plot'] = program_info['programsynopsis'].replace(
                    '<br>', '\r\n')

            if True:
                score = 70
                show['thumb'].append(
                    EntityThumb(aspect='landscape',
                                value='https://' + program_info['image'],
                                site=cls.site_name,
                                score=0).as_dict())
                show['thumb'].append(
                    EntityThumb(aspect='poster',
                                value='https://' + program_info['posterimage'],
                                site=cls.site_name,
                                score=score).as_dict())

            if True:
                page = 1
                epi = None
                while True:
                    episode_data = Wavve.vod_program_contents_programid(
                        program_info['programid'], page=page)
                    for epi in episode_data['list']:
                        try:
                            tmp = epi['episodenumber'].split('-')
                            if len(tmp) == 1:
                                epi_no = int(tmp[0])
                            else:
                                epi_no = int(tmp[1]) / 2
                        except:
                            continue
                        if epi_no not in show['extra_info']['episodes']:
                            show['extra_info']['episodes'][epi_no] = {}

                        show['extra_info']['episodes'][epi_no][
                            cls.site_name] = {
                                'code':
                                cls.module_char + cls.site_char +
                                epi['contentid'],
                                'thumb':
                                'https://' + epi['image'],
                                'plot':
                                epi['synopsis'].replace('<br>', '\r\n'),
                                'premiered':
                                epi['releasedate'],
                                'title':
                                epi['episodetitle'],
                            }
                    page += 1
                    if episode_data['pagecount'] == episode_data[
                            'count'] or page == 10:
                        break
                # 방송정보에 없는 데이터 에피소드에서 빼서 입력
                if epi:
                    show['mpaa'] = mpaa_map[epi['targetage']]

                    if len(show['actor']) == 0:
                        for item in epi['episodeactors'].split(','):
                            actor = EntityActor(item.strip())
                            actor.name = item.strip()
                            show['actor'].append(actor.as_dict())

        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())