- Implement watching YouTube and Odysee videos via mpv + yt-dlp - Implement displaying comments from Redditmaster
parent
50c9aa97c5
commit
104be86a54
@ -0,0 +1,24 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
|
class RedditComments:
|
||||||
|
def __init__(self, link):
|
||||||
|
page = httpx.get(link)
|
||||||
|
content = page.text
|
||||||
|
self.soup = BeautifulSoup(content)
|
||||||
|
self.commentObjects = self.soup.find_all("div", "Comment")
|
||||||
|
self.comments = []
|
||||||
|
|
||||||
|
def getHeader(self, commentObj):
|
||||||
|
headers = commentObj.find_all("a")
|
||||||
|
username = headers[0]["href"].split("/")[2]
|
||||||
|
date = headers[1].text
|
||||||
|
return username + " " + date
|
||||||
|
|
||||||
|
def getText(self, commentObj):
|
||||||
|
return commentObj.find("p").text
|
||||||
|
|
||||||
|
def getComments(self):
|
||||||
|
for co in self.commentObjects:
|
||||||
|
self.comments.append(self.getHeader(co) + "\n" + self.getText(co) + "\n")
|
||||||
@ -1,10 +1,26 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def timestampToDate(ts):
|
def timestampToDate(ts):
|
||||||
return datetime.fromtimestamp(int(ts)/1000000).strftime("%y-%m-%d %H:%M")
|
return datetime.fromtimestamp(int(ts)/1000000).strftime("%y-%m-%d %H:%M")
|
||||||
|
|
||||||
|
|
||||||
|
def checkStreamingVideo(link):
|
||||||
|
return re.search("^https://www.youtube.com", link) is not None or re.search("^https://player.odycdn.com", link)
|
||||||
|
|
||||||
|
|
||||||
|
def checkReddit(link):
|
||||||
|
return re.search("^https://www.reddit.com", link) is not None
|
||||||
|
|
||||||
|
|
||||||
|
def checkRedditComments(links):
|
||||||
|
for link in links:
|
||||||
|
if re.search("^https://www.reddit.com/[a-z1-9/]+/comments", link) is not None:
|
||||||
|
return link
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def writeLog(text):
|
def writeLog(text):
|
||||||
with open("debug.log", "a") as f:
|
with open("debug.log", "a") as f:
|
||||||
f.write(str(text))
|
f.write(str(text))
|
||||||
|
|||||||
Loading…
Reference in new issue