def individualize(self, channel, format='mpd'): account = get_user() password = get_password() token = gettoken(account, password) device_id = get_device_id() profile = get_default_profile(account, device_id, token) url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/media/accounts/%s/profiles/%s/live/%s/individualize?deviceId=%s&tablet=false&useragent=%s' % ( account, profile, channel, device_id, 'ios' if format == 'm3u8' else 'web') headers = { 'Accept': 'application/json', 'X-Forwarded-For': '189.1.125.97', 'User-Agent': 'OiPlay-Store/5.1.1 (iPhone; iOS 13.3.1; Scale/3.00)' if format == 'm3u8' else 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36', 'Authorization': 'Bearer ' + token } control.log('OIPLAY GET ' + url) control.log(headers) try: individualize = client.request(url, headers=headers) control.log(individualize) control.log(individualize['individualization']['url']) return individualize except: control.log('RETRYING...') headers['Authorization'] = 'Bearer ' + gettoken( account, password, force_new=True) control.log('OIPLAY GET ' + url) control.log(headers) individualize = client.request(url, headers=headers) control.log(individualize) return individualize
def request_cached(url, headers=None, force_refresh=False): token, account = gettoken() headers = headers or {} headers.update({ 'Authorization': 'Bearer %s' % token, 'Accept': 'application/json', 'X-Forwarded-For': '189.1.125.97', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' }) control.log('GET %s' % url) response = cache.get(requests.get, 1, url, headers=headers, force_refresh=force_refresh, table='oiplay') response.raise_for_status() return response.json()
def like_content(id, like=True): token, account = gettoken() device_id = get_device_id() profile = get_default_profile(account, device_id, token) operation = 'like' if like else 'dislike' url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/users/accounts/{account}/profiles/{profile}/likes/{operation}'.format( account=account, profile=profile, operation=operation) headers = { 'Authorization': 'Bearer %s' % token, 'Accept': 'application/json', 'X-Forwarded-For': '189.1.125.97', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' } data = {'tmsId': id} control.log('POST %s' % url) control.log(data) response = requests.post(url, json=data, headers=headers) control.log(response.status_code) control.log(response.content) response = response.json() return True if response.get('name') == 'Like' else False if response.get( 'name') == 'Dislike' else None
def get_entitlements(): token, account = gettoken() url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/users/accounts/{account}/entitlements/list'.format( account=account) response = request_cached(url) return response
def is_content_liked(id): token, account = gettoken() device_id = get_device_id() profile = get_default_profile(account, device_id, token) url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/users/accounts/{account}/profiles/{profile}/likes/{id}/get'.format( account=account, profile=profile, id=id) response = request_cached(url, force_refresh=True) or {} return True if response.get('name') == 'Like' else False if response.get( 'name') == 'Dislike' else None
def individualize(self, is_live, content_id, provider, format='mpd'): token, account = gettoken() device_id = get_device_id() profile = get_default_profile(account, device_id, token) useragent = 'ios' if format == 'm3u8' else 'web' if is_live: url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/media/accounts/%s/profiles/%s/live/%s/individualize?deviceId=%s&tablet=false&useragent=%s' % ( account, profile, content_id, device_id, 'ios' if format == 'm3u8' else 'web') else: url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/media/accounts/{account}/profiles/{profile}/content/{content}/{provider}/individualize?deviceId={deviceId}&tablet=false&useragent={useragent}'.format( account=account, profile=profile, content=content_id, provider=provider.encode('utf-8'), deviceId=device_id, useragent=useragent) headers = { 'Accept': 'application/json', 'X-Forwarded-For': '189.1.125.97', 'User-Agent': 'OiPlay-Store/5.1.1 (iPhone; iOS 13.3.1; Scale/3.00)' if format == 'm3u8' else 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36', 'Authorization': 'Bearer ' + token } control.log('OIPLAY GET ' + url) control.log(headers) try: individualize = requests.get(url, headers=headers).json() control.log(individualize) control.log(individualize.get('individualization', {}).get('url')) return individualize except: control.log('RETRYING...') token, account_id = gettoken(force_new=True) headers['Authorization'] = 'Bearer ' + token control.log('OIPLAY GET ' + url) control.log(headers) individualize = requests.get(url, headers=headers).json() control.log(individualize) return individualize
def __init__(self): self.token = auth.gettoken() self.upload_file = API_SERVER + 'uploadfile/' self.consul_url = API_SERVER + 'nginx/'
def get_bookmarks(): token, account = gettoken() device_id = get_device_id() profile = get_default_profile(account, device_id, token) url = 'https://apim.oi.net.br/app/oiplay/oapi/v1/media/accounts/{account}/profiles/{profile}/bookmarks/list'.format( account=account, profile=profile) response = request_cached(url, force_refresh=True) or [] for bookmark in response: item = bookmark.get('cmsContentItem', {}) yield { 'handler': __name__, 'method': 'get_content', 'id': item.get('tmsId'), 'label': item.get('title'), 'title': item.get('title'), 'tvshowtitle': item.get('seriesTitle'), 'plot': item.get('synopsis'), 'genre': item.get('genres'), 'year': item.get('releaseYear'), 'episode': item.get('episodeNumber'), 'season': item.get('seasonNumber'), 'mpaa': item.get('rating'), 'duration': item.get('durationInSeconds', 0), 'setCast': [{ 'name': cast.get('name'), 'thumbnail': cast.get('photoUrl'), } for cast in item.get('castMembers', [])], 'directors': item.get('directors'), 'playType': item.get('playType'), 'adult': item.get('isAdult'), 'mediatype': 'movie' if item.get('itemType') == 'Movie' else 'tvshow' if item.get('itemType') == 'Serie' else 'video', 'art': { 'thumb': next((image.get('url') for image in item.get('programImages', []) if image.get('type') == 'Thumbnail'), LOGO), 'fanart': next((image.get('url') for image in item.get('programImages', []) if image.get('type') == 'Backdrop'), FANART), }, 'properties': { 'resumetime': str(bookmark.get('bookmarkPosition', 0) / 1000) } }
import sys import main import auth if __name__ == '__main__': if len(sys.argv) > 1: cmd = sys.argv[1] if cmd == 'code': auth.getcodeurl() elif cmd == 'token': auth.gettoken(sys.argv[2]) else: print 'invalid command: ' + cmd else: bot = main.Bot() bot.run()