2021-07-28 19:22:40 +00:00
|
|
|
from bs4 import BeautifulSoup
|
2021-01-17 15:04:24 +00:00
|
|
|
import requests
|
2021-10-05 18:57:09 +00:00
|
|
|
import functools
|
2021-01-17 15:04:24 +00:00
|
|
|
import json
|
|
|
|
|
2021-10-05 18:57:09 +00:00
|
|
|
s = requests.Session()
|
|
|
|
s.request = functools.partial(s.request, timeout=5)
|
|
|
|
|
|
|
|
|
2021-01-22 04:08:04 +00:00
|
|
|
# --- Sepiasearch ---
|
2021-01-23 14:20:10 +00:00
|
|
|
def sepia_search(query, start=0, count=10):
|
|
|
|
url = "https://search.joinpeertube.org/api/v1/search/videos?search=" + query + "&start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-22 04:08:04 +00:00
|
|
|
|
|
|
|
# --- ----
|
|
|
|
|
|
|
|
|
2021-01-19 11:13:21 +00:00
|
|
|
def get_instance_name(domain):
|
2021-10-05 18:57:09 +00:00
|
|
|
soup = BeautifulSoup(s.get("https://" + domain).text, "lxml")
|
2021-01-20 15:29:58 +00:00
|
|
|
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):
|
2021-01-23 14:20:10 +00:00
|
|
|
url = "https://" + domain + "/api/v1/videos/" + id
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-17 15:04:24 +00:00
|
|
|
|
2021-07-28 23:43:34 +00:00
|
|
|
def video_captions(domain, id):
|
|
|
|
url = "https://" + domain + "/api/v1/videos/" + id + "/captions"
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-07-28 23:43:34 +00:00
|
|
|
|
2021-07-29 01:21:08 +00:00
|
|
|
def video_captions_download(domain, caption_id):
|
2021-07-28 23:43:34 +00:00
|
|
|
# URL is hardcoded to prevent further proxying. URL may change with updates, see captions API
|
|
|
|
# eg. https://kolektiva.media/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/captions
|
2021-07-29 01:21:08 +00:00
|
|
|
# TODO: What if the captionPath doesn't follow this format on an instance? Should we really proxy ANYTHING returned by API?
|
|
|
|
url = "https://" + domain + "/lazy-static/video-captions/" + caption_id
|
2021-10-05 18:57:09 +00:00
|
|
|
return s.get(url).text
|
2021-07-28 23:43:34 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def search(domain, term, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/search/videos?start=" + str(start) + "&count=" + str(count) + "&search=" + term + "&sort=-match&searchTarget=local"
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-17 15:04:24 +00:00
|
|
|
|
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"
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-20 15:29:58 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def get_videos_trending(domain, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/videos?sort=-trending&start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-22 03:17:02 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def get_videos_most_liked(domain, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/videos?sort=-likes&start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-22 03:17:02 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def get_videos_recently_added(domain, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/videos?sort=-publishedAt&start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-22 03:17:02 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def get_videos_local(domain, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/videos?sort=-publishedAt&filter=local&start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-22 03:17:02 +00:00
|
|
|
|
2021-01-21 22:26:31 +00:00
|
|
|
# --- Accounts ---
|
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def account_video_channels(domain, name, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/accounts/" + name + "/video-channels?start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-21 22:26:31 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def account_videos(domain, name, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/accounts/" + name + "/videos?start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-21 22:26:31 +00:00
|
|
|
|
|
|
|
def account(domain, name):
|
|
|
|
url = "https://" + domain + "/api/v1/accounts/" + name
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-21 22:26:31 +00:00
|
|
|
|
|
|
|
# --- Video Channels ---
|
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def video_channel_videos(domain, name, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/video-channels/" + name + "/videos?start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-21 22:26:31 +00:00
|
|
|
|
2021-01-23 14:20:10 +00:00
|
|
|
def video_channel_video_playlists(domain, name, start=0, count=10):
|
|
|
|
url = "https://" + domain + "/api/v1/video-channels/" + name + "/video-playlists?start=" + str(start) + "&count=" + str(count)
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.get(url).text)
|
2021-01-21 22:26:31 +00:00
|
|
|
|
|
|
|
def video_channel(domain, name):
|
|
|
|
url = "https://" + domain + "/api/v1/video-channels/" + name
|
2021-10-05 18:57:09 +00:00
|
|
|
return json.loads(s.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)
|
2021-01-21 22:26:31 +00:00
|
|
|
|
|
|
|
#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))
|
2021-01-21 22:26:31 +00:00
|
|
|
|
|
|
|
_, 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))
|