added capability to generate auth_token

This commit is contained in:
Tristan Lee
2022-03-08 10:07:42 -06:00
parent 8506fd4377
commit c85dea215a
4 changed files with 58 additions and 28 deletions

View File

@@ -10,11 +10,6 @@ from urllib.parse import quote
import requests import requests
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#TODO Figure out how to reverse-engineer this
AUTH_TOKEN = 'BseGAiye641UqUsv4g31ZcUCRiLasv3U'
# API endpoints for Odysee data # API endpoints for Odysee data
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
@@ -24,6 +19,7 @@ VIEW_API_URL = 'https://api.odysee.com/file/view_count'
REACTION_API_URL = 'https://api.odysee.com/reaction/list' REACTION_API_URL = 'https://api.odysee.com/reaction/list'
COMMENT_API_URL = 'https://comments.odysee.com/api/v2' COMMENT_API_URL = 'https://comments.odysee.com/api/v2'
RECOMMENDATION_API_URL = 'https://recsys.odysee.com/search' RECOMMENDATION_API_URL = 'https://recsys.odysee.com/search'
NEW_USER_API_URL = 'https://api.odysee.com/user/new'
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
@@ -44,13 +40,29 @@ def make_request(request, kwargs):
response = request(**kwargs) response = request(**kwargs)
if response.status_code != 200: if response.status_code != 200:
msg = f'Maximum number of retries reached for request {request} with kwargs {kwargs}' msg = f'Maximum number of retries reached for request {request} with kwargs {kwargs}: status code {response.status_code}'
raise ValueError(msg) raise ValueError(msg)
return response return response
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def get_auth_token():
"""Get a fresh authorization token, to use for API calls that require it.
"""
response = make_request(
request = requests.post,
kwargs = {
'url' : NEW_USER_API_URL})
auth_token = json.loads(response.text)['data']['auth_token']
return auth_token
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def get_channel_info(channel_name): def get_channel_info(channel_name):
"""Get the channel information and ID from the channel name. """Get the channel information and ID from the channel name.
@@ -87,13 +99,16 @@ def get_channel_info(channel_name):
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def get_subscribers(channel_id): def get_subscribers(channel_id, auth_token = None):
"""Get the number of subscribers for a channel. """Get the number of subscribers for a channel.
""" """
if auth_token is None:
auth_token = get_auth_token()
json_data = { json_data = {
'auth_token': AUTH_TOKEN, 'auth_token': auth_token,
'claim_id': channel_id } 'claim_id': channel_id }
response = make_request( response = make_request(
@@ -156,13 +171,16 @@ def get_all_videos(channel_id):
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def get_views(video_id): def get_views(video_id, auth_token = None):
"""Get the number of views for a given video. """Get the number of views for a given video.
""" """
if auth_token is None:
auth_token = get_auth_token()
params = { params = {
'auth_token': AUTH_TOKEN, 'auth_token': auth_token,
'claim_id': video_id } 'claim_id': video_id }
response = make_request( response = make_request(
@@ -177,13 +195,16 @@ def get_views(video_id):
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def get_video_reactions(video_id): def get_video_reactions(video_id, auth_token = None):
"""Get all reactions for a given video. """Get all reactions for a given video.
""" """
if auth_token is None:
auth_token = get_auth_token()
post_data = { post_data = {
'auth_token': AUTH_TOKEN, 'auth_token': auth_token,
'claim_ids': video_id } 'claim_ids': video_id }
response = make_request( response = make_request(

View File

@@ -12,11 +12,6 @@ from polyphemus import api
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#TODO Figure out how to reverse-engineer this
AUTH_TOKEN = 'BseGAiye641UqUsv4g31ZcUCRiLasv3U'
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
class OdyseeChannel: class OdyseeChannel:
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
@@ -30,7 +25,11 @@ class OdyseeChannel:
self.info = info self.info = info
self._channel_id = self.info['channel_id'] self._channel_id = self.info['channel_id']
self.info['subscribers'] = api.get_subscribers(channel_id = self.info['channel_id']) self.auth_token = api.get_auth_token()
self.info['subscribers'] = api.get_subscribers(
channel_id = self.info['channel_id'],
auth_token = self.auth_token)
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
@@ -40,7 +39,7 @@ class OdyseeChannel:
""" """
all_video_info = api.get_all_videos(channel_id=self.info['channel_id']) all_video_info = api.get_all_videos(channel_id=self.info['channel_id'])
self.all_videos = (OdyseeVideo(video) for video in all_video_info) self.all_videos = (OdyseeVideo(video, self.auth_token) for video in all_video_info)
return self.all_videos return self.all_videos
@@ -67,7 +66,12 @@ class OdyseeVideo:
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
def __init__(self, full_video_info): def __init__(self, full_video_info, auth_token = None):
if auth_token is None:
self.auth_token = api.get_auth_token()
else:
self.auth_token = auth_token
# Handle edge cases # Handle edge cases
#.....................................................................# #.....................................................................#
@@ -129,10 +133,11 @@ class OdyseeVideo:
self.claim_id = self.info['claim_id'] self.claim_id = self.info['claim_id']
self.info['views'] = api.get_views(video_id=self.claim_id) self.info['views'] = api.get_views(video_id=self.claim_id, auth_token = self.auth_token)
self.info['likes'], self.info['dislikes']= api.get_video_reactions( self.info['likes'], self.info['dislikes'] = api.get_video_reactions(
video_id = self.claim_id) video_id = self.claim_id,
auth_token = self.auth_token)
self.info['streaming_url'] = api.get_streaming_url(self.info['canonical_url']) self.info['streaming_url'] = api.get_streaming_url(self.info['canonical_url'])
@@ -151,7 +156,7 @@ class OdyseeVideo:
recommended_video_info = api.get_recommended( recommended_video_info = api.get_recommended(
video_title=self.info['title'], video_id=self.claim_id) video_title=self.info['title'], video_id=self.claim_id)
recommended_videos = [OdyseeVideo(video_info) for video_info in recommended_video_info] recommended_videos = [OdyseeVideo(video_info, self.auth_token) for video_info in recommended_video_info]
return recommended_videos return recommended_videos

View File

@@ -20,11 +20,12 @@ from polyphemus import api
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
KWARGS_LIST = [ KWARGS_LIST = [
('get_auth_token', []),
('get_channel_info', ['channel_name']), ('get_channel_info', ['channel_name']),
('get_subscribers', ['channel_id']), ('get_subscribers', ['channel_id', 'auth_token']),
('get_all_videos', ['channel_id']), ('get_all_videos', ['channel_id']),
('get_views', ['video_id']), ('get_views', ['video_id', 'auth_token']),
('get_video_reactions', ['video_id']), ('get_video_reactions', ['video_id', 'auth_token']),
('get_all_comments', ['video_id']), ('get_all_comments', ['video_id']),
('append_comment_reactions', ['comment_info_list']), ('append_comment_reactions', ['comment_info_list']),
('normalized_name_to_video_info', ['normalized_name']), ('normalized_name_to_video_info', ['normalized_name']),

View File

@@ -7,6 +7,8 @@
import pytest import pytest
from polyphemus.api import get_auth_token
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
CHANNEL_NAME = 'Mak1nBacon' CHANNEL_NAME = 'Mak1nBacon'
@@ -90,7 +92,8 @@ def resources():
canonical_url = CANONICAL_URL, canonical_url = CANONICAL_URL,
full_video_info = FULL_VIDEO_INFO, full_video_info = FULL_VIDEO_INFO,
full_comment_info = {**COMMENT_INFO_LIST[0], **{'likes' : 8, 'dislikes' : 0}}, full_comment_info = {**COMMENT_INFO_LIST[0], **{'likes' : 8, 'dislikes' : 0}},
comment_info_list = COMMENT_INFO_LIST) comment_info_list = COMMENT_INFO_LIST,
auth_token = get_auth_token())
return resources_dict return resources_dict