mirror of
https://github.com/bellingcat/polyphemus.git
synced 2026-06-07 19:08:33 +03:00
added method to get subscriber count for a channel
This commit is contained in:
@@ -3,6 +3,5 @@
|
||||
Scraper for alt-tech video sharing platform [Odysee](https://odysee.com/).
|
||||
|
||||
### TODO
|
||||
- Add number of subscribers to channel data
|
||||
- Implement CLI
|
||||
- Work on reverse-engineering auth_token instead of having it hard-coded
|
||||
@@ -13,7 +13,6 @@ import pandas as pd
|
||||
|
||||
from polyphemus.base import OdyseeChannel
|
||||
|
||||
|
||||
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
|
||||
|
||||
CHANNEL_NAME = 'PatriotFront'
|
||||
|
||||
@@ -62,9 +62,30 @@ class OdyseeChannel:
|
||||
|
||||
self.info = info
|
||||
self._channel_id = self.info['channel_id']
|
||||
|
||||
self.get_subscribers()
|
||||
|
||||
#-------------------------------------------------------------------------#
|
||||
|
||||
def get_subscribers(self):
|
||||
|
||||
"""Get the number of subscribers for a channel.
|
||||
"""
|
||||
|
||||
api_url = 'https://api.odysee.com/subscription/sub_count'
|
||||
|
||||
post_data = {
|
||||
'auth_token': AUTH_TOKEN,
|
||||
'claim_id': self.info['channel_id'] }
|
||||
|
||||
response = requests.post(url = api_url, data = post_data)
|
||||
result = json.loads(response.text)
|
||||
subscribers = result['data'][0]
|
||||
|
||||
self.info['subscribers'] = subscribers
|
||||
|
||||
#-------------------------------------------------------------------------#
|
||||
|
||||
def get_all_videos(self):
|
||||
|
||||
"""Get a list of all videos posted by a specified channel name.
|
||||
@@ -115,7 +136,7 @@ class OdyseeChannel:
|
||||
def process_all_videos(self):
|
||||
|
||||
self.get_all_videos()
|
||||
all_videos_processed = [OdyseeVideo(video).info for video in self._all_videos]
|
||||
all_videos_processed = [OdyseeVideo(video) for video in self._all_videos]
|
||||
|
||||
return all_videos_processed
|
||||
|
||||
@@ -125,7 +146,7 @@ class OdyseeChannel:
|
||||
|
||||
self.get_all_videos()
|
||||
all_videos = [OdyseeVideo(video) for video in self._all_videos]
|
||||
all_videos_processed = [video.info for video in all_videos]
|
||||
all_videos_processed = [video for video in all_videos]
|
||||
|
||||
all_comments_processed = []
|
||||
|
||||
@@ -185,7 +206,7 @@ class OdyseeVideo:
|
||||
"""Get all reactions for a given video.
|
||||
"""
|
||||
|
||||
api_url = f'https://api.odysee.com/reaction/list'
|
||||
api_url = 'https://api.odysee.com/reaction/list'
|
||||
|
||||
post_data = {
|
||||
'auth_token': AUTH_TOKEN,
|
||||
@@ -263,7 +284,7 @@ class OdyseeVideo:
|
||||
|
||||
#-------------------------------------------------------------------------#
|
||||
|
||||
def get_recommended(self, n = 20):
|
||||
def get_recommended(self):
|
||||
|
||||
api_url = 'https://recsys.odysee.com/search'
|
||||
|
||||
@@ -271,14 +292,14 @@ class OdyseeVideo:
|
||||
|
||||
params = {
|
||||
's':name,
|
||||
'size':str(int(n)),
|
||||
'size':'20',
|
||||
'from':'0',
|
||||
'related_to':self._claim_id}
|
||||
|
||||
response = requests.get(api_url, params = params)
|
||||
result = json.loads(response.text)
|
||||
|
||||
recommended_video_info = [name_to_video_info(r['name']) for r in result]
|
||||
recommended_video_info = [_name_to_video_info(r['name']) for r in result]
|
||||
recommended_video_info = [vi for vi in recommended_video_info if vi['value_type'] == 'stream']
|
||||
recommended_videos = [OdyseeVideo(video_info) for video_info in recommended_video_info]
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ from .base import OdyseeVideo
|
||||
|
||||
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
|
||||
|
||||
def name_to_video_info(name):
|
||||
ODYSEE_DOMAIN = 'https://odysee.com/'
|
||||
|
||||
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
|
||||
|
||||
def _name_to_video_info(name):
|
||||
|
||||
url = f"lbry://{name}"
|
||||
|
||||
@@ -32,9 +36,39 @@ def name_to_video_info(name):
|
||||
|
||||
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
|
||||
|
||||
def _url_to_video_info(url):
|
||||
|
||||
if url.startswith(ODYSEE_DOMAIN):
|
||||
name = url.split(ODYSEE_DOMAIN)[1]
|
||||
url = f"lbry://{name}"
|
||||
|
||||
post_data = {
|
||||
"jsonrpc":"2.0",
|
||||
"method":"resolve",
|
||||
"params":{
|
||||
"urls":[url]}}
|
||||
|
||||
api_url = 'https://api.na-backend.odysee.com/api/v1/proxy'
|
||||
|
||||
response = requests.post(url = api_url, json = post_data)
|
||||
result = json.loads(response.text)
|
||||
|
||||
return result['result'][url]
|
||||
|
||||
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
|
||||
|
||||
def name_to_video(name):
|
||||
|
||||
video_info = name_to_video_info(name)
|
||||
video_info = _name_to_video_info(name)
|
||||
video = OdyseeVideo(video_info)
|
||||
|
||||
return video
|
||||
|
||||
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
|
||||
|
||||
def url_to_video(name):
|
||||
|
||||
video_info = _url_to_video_info(name)
|
||||
video = OdyseeVideo(video_info)
|
||||
|
||||
return video
|
||||
|
||||
Reference in New Issue
Block a user