Beispiel #1
0
def vod_allprograms(page=1, limit=20, contenttype='program', genre='all', subgenre=None, orderby='new', is_cf=False):
    try:
        page = int(page) if type(page) != int else page
        param = get_baseparameter()
        param['genre'] = genre
        param['contenttype'] = contenttype

        param['type'] = 'all'
        param['weekday'] = 'all'
        param['offset'] = (page-1)*limit
        param['limit'] = limit
        param['orderby'] = orderby # 최신순 = new 과거순 = old
        if subgenre is not None:
            param['subgenre'] = subgenre
        if is_cf:
            url = "%s/cf/vod/allprograms?%s" % (config['base_url'], py_urllib.urlencode(param))
        else:
            url = "%s/vod/allprograms?%s" % (config['base_url'], py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])
        data = response.json()
        #logger.debug(url)
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #2
0
    def wavve_get_cfdeeplink_json(type='all'):
        try:
            param = wavve_get_baseparameter()
            if type == 'dra':
                uicode = 'VN4'
            elif type == 'ent':
                uicode = 'VN3'
            elif type == 'doc':
                uicode = 'VN5'
            else:
                uicode = 'VN500'  # 핫 (가로)
                # uicode = 'VN2' # 인기 (가로)
                # uicode = 'VN1' # 최신 (세로)

            url = '%s/cf/deeplink/%s?%s' % (wavve_config['base_url'], uicode,
                                            py_urllib.urlencode(param))
            res = requests.get(url)
            data = res.json()
            url = 'https://%s' % (data['url'].replace('limit=20', 'limit=30'))
            res = requests.get(url)
            data = res.json()
            return data
        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Beispiel #3
0
    def tving_get_popular_json(type='all', order='viewDay'):
        try:
            auto_tving_order = ModelSetting.get('auto_tving_order')

            param = {}
            if type == 'dra':
                param['multiCategoryCode'] = 'PCA'
            elif type == 'ent':
                param['multiCategoryCode'] = 'PCD'
            elif type == 'doc':
                param['multiCategoryCode'] = 'PCK'
            else:
                param['multiCategoryCode'] = ''
            # order : viewDay, viewWeek
            param['order'] = auto_tving_order
            default_param = 'pageNo=1&pageSize=30&adult=all&free=all&guest=all&scope=all&lastFrequency=y&personal=N&screenCode=CSSD0100&networkCode=CSND0900&osCode=CSOD0900&teleCode=CSCD0900&apiKey=1e7952d0917d6aab1f0293a063697610'
            url = '%s/v2/media/episodes?%s&%s' % ('https://api.tving.com',
                                                  default_param,
                                                  py_urllib.urlencode(param))
            res = requests.get(url)
            data = res.json()
            return data
        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Beispiel #4
0
 def wavve_get_popularcontents_json(type='all'):
     try:
         param = wavve_get_baseparameter()
         if type == 'dra':
             param['genre'] = '01'
         elif type == 'ent':
             param['genre'] = '02'
         elif type == 'doc':
             param['genre'] = '03'
         else:
             param[
                 'genre'] = 'all'  # 01 드라마, 02 예능, 03 시사교양, 09 해외시리즈, 08 애니메이션, 06 키즈, 05 스포츠
         param['subgenre'] = 'all'
         param['channel'] = 'all'
         param['type'] = 'all'  # general, onair, all
         param['offset'] = '0'
         param['limit'] = '30'
         # params['onair'] = 'y' # all 전체, y 방영중, n 종영 ## valid in popularprograms
         # url = '%s/vod/popularprograms?%s' % (wavve_config['base_url'], py_urllib.urlencode(param))
         url = '%s/vod/popularcontents?%s' % (wavve_config['base_url'],
                                              py_urllib.urlencode(param))
         res = requests.get(url)
         data = res.json()
         return data
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #5
0
def get_live_json(source_id, quality, credential):
    try:
        quality = get_quality_to_pooq(quality)
        quality_list = get_live_quality_list(source_id)
        if not quality in quality_list:
            quality = quality_list[0]
        url = 'https://wapie.pooq.co.kr/v1/lives30/%s/url' % source_id
        params = DEFAULT_PARAM.copy()
        params['deviceModelId'] = 'Macintosh'
        params['authType'] = 'cookie'
        params['guid'] = get_guid()
        params['lastPlayId'] = 'none'
        params['quality'] = quality
        params['credential'] = credential

        url = '%s?%s' % (url, py_urllib.urlencode(params))
        request = py_urllib2.Request(url)
        response = py_urllib2.urlopen(request)
        if sys.version_info[0] == 2:
            data = json.load(response, encoding='utf8')
        else:
            data = json.load(response)
        return data

    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #6
0
 def add_remote(key, feed, remote_options_id):
     try:
         result = {}
         url = 'https://offcloud.com/api/remote'
         params = {
             'key': key,
             'url': feed.link,
             'remoteOptionId': remote_options_id,
             'folderId': feed.oc_folderid,
         }
         postdata = py_urllib.urlencode(params).encode('utf-8')
         request = py_urllib2.Request(url, postdata)
         response = py_urllib2.urlopen(request)
         data = response.read()
         result = json.loads(data)
         logger.debug('ADD REMOTE ret: %s', result)
         if 'error' in result and result['error'].startswith(
                 "You have more than 100"):
             return 'over'
         feed.oc_requestId = result[
             'requestId'] if 'requestId' in result else ''
         feed.oc_status = result['status'] if 'status' in result else ''
         feed.oc_createdOn = result[
             'createdOn'] if 'createdOn' in result else ''
         feed.oc_error = result['error'] if 'error' in result else ''
         feed.oc_json = result
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #7
0
def do_login(id, pw, json_return=False):
    try:
        body = {
            "type": "general",
            "id": id,
            "pushid": "",
            "password": pw,
            "profile": "0",
            "networktype": "",
            "carrier": "",
            "mcc": "",
            "mnc": "",
            "markettype": "unknown",
            "adid": "",
            "simoperator": "",
            "installerpackagename": ""
        }
        url = "%s/login?%s" % (config['base_url'],
                               py_urllib.urlencode(config['base_parameter']))
        response = session.post(url, json=body, headers=config['headers'])
        data = response.json()
        if 'credential' in data:
            if json_return:
                return data
            else:
                return data['credential']
        else:
            logger.debug('login fail!!')
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
    return
Beispiel #8
0
    def make_magnet_from_file(file):
        #torrent to magnet
        import hashlib
        import base64
        if app.config['config']['is_py2']:
            try:
                import bencode
            except:
                os.system("{} install bencode".format(
                    app.config['config']['pip']))
                import bencode
            #torrent = open(file, 'r').read()
            with open(file, 'rb') as f:
                torrent = f.read()

            metadata = bencode.bdecode(torrent)
            hashcontents = bencode.bencode(metadata['info'])
            digest = hashlib.sha1(hashcontents).digest()
            b32hash = base64.b32encode(digest)

            params = {
                'xt': 'urn:btih:%s' % b32hash,
                'dn': metadata['info']['name'],
                'tr': metadata['announce'],
                'xl': metadata['info']['length']
            }

            announcestr = ''
            for announce in metadata['announce-list']:
                announcestr += '&' + py_urllib.urlencode({'tr': announce[0]})

            paramstr = py_urllib.urlencode(params) + announcestr
            magneturi = 'magnet:?%s' % paramstr
            magneturi = magneturi.replace('xt=urn%3Abtih%3A', u'xt=urn:btih:',
                                          1)
            logger.debug('magneturi : %s', magneturi)
            return magneturi
        else:
            try:
                import magneturi
            except:
                os.system('pip install magneturi')
                import magneturi
            magnet_uri = magneturi.from_torrent_file(file)
            logger.debug('magneturi : %s', magnet_uri)
            return magnet_uri
Beispiel #9
0
 def get_meta_extra(cls, code):
     try:
         from framework import py_urllib
         url = f"{app.config['DEFINE']['WEB_DIRECT_URL']}/meta/get_meta.php?"
         url += py_urllib.urlencode({'type': 'extra', 'code': code})
         data = requests.get(url).json()
         if data['ret'] == 'success':
             return data['data']
     except Exception as exception:
         logger.error('metaserver connection fail.. get_meta_extra')
Beispiel #10
0
    def get_url(cls, source_id, quality, mode):
        #logger.debug('EVERYON get_url:%s %s', source_id, quality)
        try:
            url = 'http://www.hcnmobile.tv/main/proc/get_ch_data.php'
            params = {'chId': source_id}
            postdata = py_urllib.urlencode(params)
            request = py_urllib2.Request(url, postdata)
            request.add_header(
                'Cookie',
                'etv_api_key=88abc0e1c8e61c8c3109788ec8392c7fd86c16765fc0b80d5f2366c84c894203'
            )
            response = py_urllib2.urlopen(request)
            data = json.load(response, encoding='utf8')
            #url2 = data['medias'][0]['url'] if len(data['medias']) > 0 else None
            url2 = data['media']['url'].replace('\\', '')
            #logger.debug('EVERYON22 :%s', url2)

            cookie = response.info().getheader('Set-Cookie')
            if cookie is None:
                # 종편
                req = py_urllib2.Request(url2)
                res = py_urllib2.urlopen(req)
                data = res.read()
                match = re.compile(r'chunklist(?P<tmp>.*?)$').search(data)
                if match:
                    redirect_url = '%schunklist%s' % (
                        url2.split('playlist.m3u8')[0], match.group('tmp'))
                    return 'redirect', redirect_url
                    #return 'return_after_read', redirect_url
            else:
                #logger.debug('EVERYON22 cookie :%s', cookie)
                ret = url2
                info = {}
                info['Key-Pair-Id'] = ''
                info['Policy'] = ''
                info['Signature'] = ''

                for c in cookie.split(','):
                    c = c.strip()
                    if c.startswith('CloudFront-Key-Pair-Id'):
                        info['Key-Pair-Id'] = c.split(';')[0].split('=')[1]
                    if c.startswith('CloudFront-Policy'):
                        info['Policy'] = c.split(';')[0].split('=')[1]
                    if c.startswith('CloudFront-Signature'):
                        info['Signature'] = c.split(';')[0].split('=')[1]
                ret = ret.replace('live.m3u8', 'live_hd.m3u8')
                #tmp = 'Key-Pair-Id=%s;Policy=%s;Signature=%s' % (info['Key-Pair-Id'], info['Policy'], info['Signature'])
                ret = '%s?Key-Pair-Id=%s&Policy=%s&Signature=%s' % (
                    ret, info['Key-Pair-Id'], info['Policy'],
                    info['Signature'])
                return 'return_after_read', ret
        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Beispiel #11
0
 def get_metadata(cls, code):
     try:
         from framework import py_urllib
         url = f"{app.config['DEFINE']['WEB_DIRECT_URL']}/meta/get_meta.php?"
         url += py_urllib.urlencode({'type': 'meta', 'code': code})
         logger.warning(url)
         data = requests.get(url).json()
         if data['ret'] == 'success':
             return data['data']
     except Exception as exception:
         #logger.debug('Exception:%s', exception)
         #logger.debug(traceback.format_exc())
         logger.error('metaserver connection fail.. get_metadata')
Beispiel #12
0
def getpermissionforcontent(contentid, contenttype='movie'):
    try:
        param = get_baseparameter()
        param['contentid'] = contentid
        param['contenttype'] = contenttype
        param['credential'] = SystemModelSetting.get('site_wavve_credential')

        url = "%s/getpermissionforcontent?%s" % (config['base_url'],
                                                 py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])
        data = response.json()
        return data
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #13
0
 def tving_get_search_json(keyword, type='all', page=1):
     try:
         param = {}
         param['kwd'] = keyword
         param['notFoundText'] = keyword
         default_param = 'siteName=TVING_WEB&category=PROGRAM&pageNum=%s&pageSize=50&indexType=both&methodType=allwordthruindex&payFree=ALL&runTime=ALL&grade=ALL&genre=ALL&screen=CSSD0100&os=CSOD0900&network=CSND0900&sort1=ins_dt&sort2=frequency&sort3=NO&type1=desc&type2=desc&type3=desc&fixedType=Y&spcMethod=someword&spcSize=0&adult_yn=&reKwd=&xwd=' % page
         url = '%s/search/getSearch.jsp?%s&%s' % (
             'https://search.tving.com', default_param,
             py_urllib.urlencode(param))
         res = requests.get(url)
         data = res.json()
         return data
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #14
0
 def get_remote_account(key):
     try:
         url = 'https://offcloud.com/api/remote/accounts'
         params = {'key': key}
         postdata = py_urllib.urlencode(params).encode('utf-8')
         request = py_urllib2.Request(url, postdata)
         response = py_urllib2.urlopen(request)
         data = json.load(response)
         if 'data' in data:
             return data['data']
         else:
             return None
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
         return None
Beispiel #15
0
def movie_contents_detail(movie_id):
    """영화 상세 정보"""
    #https://apis.pooq.co.kr/cf/movie/contents/MV_CA01_DY0000011394?apikey=E5F3E0D30947AA5440556471321BB6D9
    try:
        param = get_baseparameter()
        url = "%s/movie/contents/%s?%s" % (config['base_url'], movie_id, py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])
        data = response.json()
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #16
0
 def wavve_get_search_json(keyword, type='all', page=1):
     try:
         param = wavve_get_baseparameter()
         param['type'] = type
         param['keyword'] = keyword
         param['offset'] = (int(page) - 1) * 20
         param['limit'] = 20
         param['orderby'] = 'score'
         url = '%s/search?%s' % (wavve_config['base_url'],
                                 py_urllib.urlencode(param))
         res = requests.get(url)
         data = res.json()
         return data
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #17
0
def get_live_quality_list(source_id):
    try:
        url = 'https://wapie.pooq.co.kr/v1/lives30/%s' % source_id
        params = DEFAULT_PARAM.copy()
        params['credential'] = 'none'
        url = '%s?%s' % (url, py_urllib.urlencode(params))
        request = py_urllib2.Request(url)
        response = py_urllib2.urlopen(request)
        if sys.version_info[0] == 2:
            data = json.load(response, encoding='utf8')
        else:
            data = json.load(response)
        result = data['result']['qualityList'][0]['quality']
        return result
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #18
0
 def tving_get_SMTV_PROG_4K_json(type='program'):
     try:
         param = {}
         if type == 'program':
             param['positionKey'] = 'SMTV_PROG_4K'
         elif type == 'movie':
             param['positionKey'] = 'SMTV_MV_4K'
         default_param = 'screenCode=CSSD1200&networkCode=CSND0900&osCode=CSOD0900&teleCode=CSCD0900&apiKey=aeef9047f92b9dc4ebabc71fe4b124bf&pocType=APP_Z_TVING_1.0'
         url = '%s/v2/operator/highlights?%s&%s' % (
             'https://api.tving.com', default_param,
             py_urllib.urlencode(param))
         res = requests.get(url)
         data = res.json()
         return data
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #19
0
 def add_remote_by_magnet(key, magnet, remote_options_id, folder_id):
     try:
         url = 'https://offcloud.com/api/remote'
         params = {
             'key': key,
             'url': magnet,
             'remoteOptionId': remote_options_id,
             'folderId': folder_id,
         }
         postdata = py_urllib.urlencode(params).encode('utf-8')
         request = py_urllib2.Request(url, postdata)
         response = py_urllib2.urlopen(request)
         data = response.read()
         result = json.loads(data)
         return result
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #20
0
def get_live_list():
    try:
        url = 'https://wapie.pooq.co.kr/v1/livesgenresort30/'
        params = DEFAULT_PARAM.copy()
        params['credential'] = 'none'
        params['orderby'] = 'g'
        url = '%s?%s' % (url, py_urllib.urlencode(params))
        #logger.debug('get_live_list:%s', url)
        request = py_urllib2.Request(url)
        response = py_urllib2.urlopen(request)
        if sys.version_info[0] == 2:
            data = json.load(response, encoding='utf8')
        else:
            data = json.load(response)
        return data['result']['list']
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #21
0
def vod_contents_contentid(contentid):
    try:
        param = get_baseparameter()
        #param['ishevc'] = 'all'
        url = "%s/vod/contents/%s?%s" % (config['base_url'], contentid, py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])

        #logger.debug(url)
        data = response.json()
        #logger.debug(data)
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #22
0
def vod_program_contents_programid(programid, page=1, limit=20):
    try:
        page = int(page) if type(page) != int else page
        param = get_baseparameter()
        param['offset'] = (page-1)*limit
        param['limit'] = limit
        param['orderby'] = 'new'
        url = "%s/vod/programs-contents/%s?%s" % (config['base_url'], programid, py_urllib.urlencode(param))
        #logger.debug(url)
        response = session.get(url, headers=config['headers'])
        data = response.json()
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #23
0
def live_all_channels(genre='all'):
    try:
        param = get_baseparameter()
        param['genre'] = genre
        param['type'] = 'all'
        param['offset'] = 0
        param['limit'] = 999
        url = "%s/live/all-channels?%s" % (config['base_url'],
                                           py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])
        data = response.json()
        #logger.debug(url)
        #logger.debug(data)
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #24
0
def search(keyword, search_type='all'):
    try:
        param = get_baseparameter()
        param['keyword'] = keyword
        url = "https://apis.wavve.com/search/instance/keywords?%s" % (py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])
        data = response.json()
        logger.debug(url)
        if response.status_code == 200:
            if search_type == 'all':
                return data
            else:
                for item in data:
                    if item['type'] == search_type:
                        return item
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())    
Beispiel #25
0
 def GetChannelListFromCate(cls, cate, pageNo='1'):
     url = 'http://www.hcnmobile.tv/main/proc/ajax_ch_list.php'
     params = {
         'chNum': '',
         'cate': '',
         'sCate': cate,
         'chNum': '',
         'chNm': '',
         'page': pageNo,
         'perPage': '20',
         'srchTxt': ''
     }
     postdata = py_urllib.urlencode(params)
     request = py_urllib2.Request(url, postdata)
     request.add_header(
         'Cookie',
         'etv_api_key=88abc0e1c8e61c8c3109788ec8392c7fd86c16765fc0b80d5f2366c84c894203'
     )
     response = py_urllib2.urlopen(request)
     data = response.read()
     hasMore = 'Y' if int(data.split('|')[1]) > int(pageNo) * 20 else 'N'
     regax = 'thumb\"\stitle\=\"(.*?)\".*\s*.*selCh\(\'(.*?)\'.*\s*<img\ssrc\=\"(.*?)\"'
     regax2 = 'ch_name\"\stitle\=\"(.*?)\"'
     r = re.compile(regax)
     r2 = re.compile(regax2)
     m = r.findall(data)
     m2 = r2.findall(data)
     list = []
     #for item in m:
     for i in range(len(m)):
         info = {}
         info['title'] = m[i][0].replace(',', ' ')
         info['id'] = m[i][1]
         info['img'] = m[i][2]
         info['summary'] = m2[i]
         list.append(info)
     logger.debug('ret:%s %s', hasMore, len(list))
     return hasMore, list
Beispiel #26
0
 def refresh_status(key, feed):
     try:
         url = 'https://offcloud.com/api/remote/status'
         params = {'key': key, 'requestId': feed.oc_requestId}
         postdata = py_urllib.urlencode(params).encode('utf-8')
         request = py_urllib2.Request(url, postdata)
         response = py_urllib2.urlopen(request)
         data = response.read()
         data = json.loads(data)
         feed.oc_json = data
         if 'status' in data:
             feed.oc_status = data['status']['status']
             if feed.oc_status == 'error':
                 pass
             elif feed.oc_status == 'downloaded':
                 feed.oc_fileSize = int(data['status']['fileSize'])
                 feed.oc_fileName = data['status']['fileName']
         else:
             logger.debug('NO STATUS %s %s', url, params)
             feed.oc_status = 'NOSTATUS'
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Beispiel #27
0
def live_epgs_channels(channel_id, startdatetime, enddatetime):
    try:
        param = get_baseparameter()
        param['genre'] = 'all'
        param['type'] = 'all'
        param['offset'] = 0
        param['limit'] = 999
        param['startdatetime'] = startdatetime
        param['enddatetime'] = enddatetime
        param['orderby'] = 'old'
        url = "%s/live/epgs/channels/%s?%s" % (config['base_url'], channel_id,
                                               py_urllib.urlencode(param))
        #logger.debug(url)
        response = session.get(url, headers=config['headers'])
        data = response.json()
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #28
0
def vod_newcontents(page=1, limit=20, genre='all'):
    try:
        page = int(page) if type(page) != int else page
        param = get_baseparameter()
        param['genre'] = 'all'
        param['channel'] = 'all'
        param['type'] = 'all'
        param['weekday'] = 'all'
        param['offset'] = (page-1)*limit
        param['limit'] = limit
        param['orderby'] = 'new' # 최신순 = new 과거순 = old
        url = "%s/vod/newcontents?%s" % (config['base_url'], py_urllib.urlencode(param))
        response = session.get(url, headers=config['headers'])
        data = response.json()
        #logger.debug(url)
        if response.status_code == 200:
            return data
        else:
            if 'resultcode' in data:
                logger.debug(data['resultmessage'])
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Beispiel #29
0
 def cache(key, magnet_list, remoteOptionId):
     try:
         url = 'https://offcloud.com/api/torrent/check?key=%s' % (key)
         params = {'hashes': magnet_list}
         res = requests.post(url, json=params)
         result = res.json()
         for i in result['cachedItems']:
             url = 'https://offcloud.com/api/remote'
             params = {
                 'key': key,
                 'url': 'magnet:?xt=urn:btih:%s' % i,
                 'remoteOptionId': remoteOptionId,
                 'folderId': '10b5Z-0RA08d6p2iMNQ9D__7e5gWOV6v5',
             }
             postdata = py_urllib.urlencode(params).encode('utf-8')
             request = py_urllib2.Request(url, postdata)
             response = py_urllib2.urlopen(request)
             data = response.read()
             result = json.loads(data)
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
         return None
Beispiel #30
0
def streaming(contenttype,
              contentid,
              quality,
              action='hls',
              ishevc='y',
              isabr='y',
              return_url=False):
    """재생관련 정보 (스트리밍 / 다운로드 url 발급)"""
    # contenttype : live, vod, movie, clip, timemachine, onairvod
    # contentid  : live = channelid, 프로그램 = programid, vod = contentid, 영화 = movieid, 클립 = clipid
    # action : hls, dash, progressive, download
    # quality : 100p (라디오), 360p, 480p, 720p, 1080p, 2160p, default, radio
    # authtype  : signed url = url, http header 인증 = cookie
    # isabr - adaptive streaming 여부 : y, n
    # ishevc - hevc 여부 : y, n
    if quality == 'FHD':
        quality = '1080p'
    elif quality == 'HD':
        quality = '720p'
    elif quality == 'SD':
        quality = '480p'
    elif quality == 'UHD':
        quality = '2160p'
    #quality = '2160p'
    if contenttype == 'live':
        ishevc = 'n'
        isabr = 'n'

    try:
        param = get_baseparameter()
        param['credential'] = SystemModelSetting.get('site_wavve_credential')
        if contenttype == 'general':
            contenttype = 'vod'

        elif contenttype == 'onair':
            contenttype = 'onairvod'
        param['contenttype'] = contenttype
        param['contentid'] = contentid
        param['action'] = action
        param['quality'] = quality
        #param['guid'] = get_guid()
        param['guid'] = ''
        param['deviceModelId'] = 'Windows 10'
        param['authtype'] = 'url'  #cookie, url
        #if contenttype == 'vod':
        #    isabr = 'y'
        param['isabr'] = isabr
        param['ishevc'] = ishevc
        param['lastplayid'] = 'none'

        url = "%s/streaming?%s" % (config['base_url'],
                                   py_urllib.urlencode(param))
        if return_url:
            logger.debug(url)
            return url
        response = session.get(url,
                               headers=config['headers'],
                               proxies=get_proxies())
        data = response.json()

        if response.status_code == 200:
            #logger.debug(url)
            #logger.debug(data)
            try:
                if data['playurl'].startswith('https://event.pca.wavve.com'):
                    logger.debug(
                        'playurl startswith https://event.pca.wavve.com!!!!!')
                    return streaming_imsi(contenttype,
                                          contentid,
                                          quality,
                                          action=action,
                                          ishevc=ishevc,
                                          isabr=isabr)
            except:
                logger.debug('https://event.pca.wavve.com error')

            return data
        else:
            if 'resultcode' in data:
                #logger.debug(data['resultmessage'])
                pass
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())