2025-01-18 23:06:34 -06:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
|
|
|
|
odysee_url = r'https://odysee.com'
|
|
|
|
odysee_api_url = r'https://api.na-backend.odysee.com/api/v1/proxy'
|
|
|
|
|
|
|
|
def odysee_get_channel_url(handle):
|
|
|
|
return f'{odysee_url}/{handle}'
|
|
|
|
|
|
|
|
def odysee_get_releases(handle):
|
|
|
|
releases = {}
|
|
|
|
try:
|
|
|
|
for i in range(1,20):
|
|
|
|
payload = {
|
|
|
|
"method": "claim_search",
|
|
|
|
"params": {
|
|
|
|
"channel": handle,
|
|
|
|
"page_size": 20,
|
|
|
|
"page": i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response = requests.post(odysee_api_url, json=payload)
|
|
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
|
|
|
lastpage = data.get("result", {}).get("total_pages", 1)
|
|
|
|
items = data.get("result", {}).get("items", [])
|
|
|
|
for raw_item in items:
|
|
|
|
item = raw_item
|
|
|
|
if item["value_type"] == "repost":
|
|
|
|
item = raw_item["reposted_claim"]
|
|
|
|
elif item["value_type"] == "stream":
|
|
|
|
# This is known to be a zip file
|
|
|
|
pass
|
2025-01-23 23:21:02 -06:00
|
|
|
elif item["value_type"] == "collection":
|
|
|
|
# Collections are playlists, and we don't care about the ones that aren't
|
|
|
|
continue
|
2025-01-18 23:06:34 -06:00
|
|
|
else:
|
2025-01-23 23:21:02 -06:00
|
|
|
print(f'Unknown value type, continuing: {item["value_type"]}')
|
2025-01-18 23:06:34 -06:00
|
|
|
releases[item["claim_id"]] = {
|
|
|
|
"name": item.get("name", "Unnamed Release"),
|
|
|
|
"title": item["value"].get("title", "Untitled Release"),
|
|
|
|
"description": item["value"].get("description", "No description provided for this release"),
|
|
|
|
"thumbnail": item["value"].get("thumbnail", {}).get("url", ""),
|
2025-01-18 23:29:52 -06:00
|
|
|
"url": f"{odysee_get_channel_url(handle)}/{item['name']}"
|
2025-01-18 23:06:34 -06:00
|
|
|
}
|
|
|
|
if i == lastpage:
|
|
|
|
break
|
|
|
|
except requests.RequestException as e:
|
|
|
|
print(f'RequestException occurred while getting releases for {handle}: {e}')
|
|
|
|
return None
|
|
|
|
except KeyError as e:
|
|
|
|
print(f'KeyError occurred while getting releases for {handle}: {e}')
|
|
|
|
print(f'Nonzero chance Odysee updated their API out from under you')
|
|
|
|
return None
|
|
|
|
return releases
|