SimpleerTube/peertube.py

74 lines
2.5 KiB
Python
Raw Normal View History

2021-01-17 15:04:24 +00:00
from bs4 import BeautifulSoup
import requests
import json
2021-01-19 11:13:21 +00:00
def get_instance_name(domain):
2021-01-20 15:29:58 +00:00
soup = BeautifulSoup(requests.get("https://" + domain).text, "lxml")
title = soup.find('title')
if title:
return title.text
else:
return "PeerTube Instance"
2021-01-19 11:13:21 +00:00
2021-01-17 15:04:24 +00:00
def video(domain, id):
video_url = "https://" + domain + "/api/v1/videos/" + id
video_object = json.loads(requests.get(video_url).text)
return video_object
def search(domain, term, start = 0, count = 10):
search_url = "https://" + domain + "/api/v1/search/videos?start=" + str(start) + "&count=" + str(count) + "&search=" + term + "&sort=-match&searchTarget=local"
search_object = json.loads(requests.get(search_url).text)
amount = search_object["total"]
results = search_object["data"]
return amount, results
2021-01-20 20:00:11 +00:00
def get_comments(domain, id):
2021-01-20 15:29:58 +00:00
url = "https://" + domain + "/api/v1/videos/" + id + "/comment-threads"
return json.loads(requests.get(url).text)
2021-01-20 15:29:58 +00:00
# --- Accounts ---
def account_video_channels(domain, name):
url = "https://" + domain + "/api/v1/accounts/" + name + "/video-channels"
return json.loads(requests.get(url).text)
def account_videos(domain, name):
url = "https://" + domain + "/api/v1/accounts/" + name + "/videos"
return json.loads(requests.get(url).text)
def account(domain, name):
url = "https://" + domain + "/api/v1/accounts/" + name
return json.loads(requests.get(url).text)
# --- Video Channels ---
def video_channel_videos(domain, name):
url = "https://" + domain + "/api/v1/video-channels/" + name + "/videos"
return json.loads(requests.get(url).text)
def video_channel_video_playlists(domain, name):
url = "https://" + domain + "/api/v1/video-channels/" + name + "/video-playlists"
return json.loads(requests.get(url).text)
def video_channel(domain, name):
url = "https://" + domain + "/api/v1/video-channels/" + name
return json.loads(requests.get(url).text)
2021-01-17 15:04:24 +00:00
if __name__ == "__main__":
2021-01-20 20:00:11 +00:00
#name = get_instance_name("videos.lukesmith.xyz")
#print(name)
#com = get_comments("videos.lukesmith.xyz", "d1bfb082-b203-43dc-9676-63d28fe65db5")
#print(json.dumps(com, indent=2))
2021-01-20 15:29:58 +00:00
#vid = video("diode.zone", "c4f0d71b-bd8b-4641-87b0-6d9edd4fa9ce")
#print(json.dumps(vid, indent=2))
_, results = search("diode.zone", "test")
print(json.dumps(results, indent=2))
#video_channels = account_video_channels("peer.tube", "mouse@peertube.dsmouse.net")
#print(json.dumps(video_channels, indent=2))