From d7543a98ed401ed3440bbd85386b420eccc15033 Mon Sep 17 00:00:00 2001 From: pluja Date: Tue, 4 Aug 2020 23:18:59 +0200 Subject: [PATCH] Youtube: Break dependance with Invidious. Proxy not working. --- app/routes.py | 34 +++++++++++++++++------------ app/static/styles.css | 20 +++++++++++++++++ app/templates/base.html | 16 +------------- app/templates/video.html | 47 +++++++++++++++++++++------------------- 4 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 app/static/styles.css diff --git a/app/routes.py b/app/routes.py index 9db201c..f1453bd 100644 --- a/app/routes.py +++ b/app/routes.py @@ -6,19 +6,20 @@ from requests_futures.sessions import FuturesSession from concurrent.futures import as_completed from werkzeug.urls import url_parse from bs4 import BeautifulSoup +from youtube_dl import YoutubeDL from app import app, db import random, string import time, datetime import feedparser import requests -import youtubedl import json import re # Instances - Format must be instance.tld (No '/' and no 'https://') nitterInstance = "https://nitter.net/" nitterInstanceII = "https://nitter.mastodont.cat/" -invidiousInstance = "invidious.snopyta.org" +invidiousInstance = "invidio.us" +proxy = "" #eg. socks5://IP:PORT ######################### #### Twitter Logic ###### @@ -302,20 +303,24 @@ def ytunfollow(channelId): @app.route('/video/', methods=['POST', 'GET']) @login_required def video(id): - data = requests.get('https://{instance}/api/v1/videos/{id}'.format(instance=invidiousInstance, id=id)) - data = json.loads(data.content) + if proxy: + ydl_opts = { + 'proxy':proxy + } + else: + ydl_opts = {} + ydl = YoutubeDL(ydl_opts) + data = ydl.extract_info("{id}".format(id=id), download=False) video = { 'title':data['title'], - 'description':Markup(data['descriptionHtml']), - 'viewCount':data['viewCount'], - 'likeCount':data['likeCount'], - 'dislikeCount':data['dislikeCount'], - 'authorThumb':data['authorThumbnails'][4]['url'], - 'author':data['author'], - 'authorUrl':data['authorUrl'], - 'instance':invidiousInstance, - 'id':id + 'description':Markup(data['description']), + 'viewCount':data['view_count'], + 'author':data['uploader'], + 'authorUrl':data['uploader_url'], + 'id':id, + 'url': data['formats'][-1]['url'], + 'averageRating': str((float(data['average_rating'])/5)*100) } return render_template("video.html", video=video) @@ -501,6 +506,8 @@ def getPosts(account): def getInvidiousPosts(ids): videos = [] + ydl = YoutubeDL() + link = ydl.extract_info("https://www.youtube.com/watch?v=XCSfoiD8wUA", download=False)['formats'][-1]['url'] with FuturesSession() as session: futures = [session.get('https://{instance}/feed/channel/{id}'.format(instance=invidiousInstance, id=id.channelId)) for id in ids] for future in as_completed(futures): @@ -512,7 +519,6 @@ def getInvidiousPosts(ids): video.timeStamp = getTimeDiff(vid.published_parsed) video.channelName = vid.author_detail.name video.channelUrl = vid.author_detail.href - video.videoUrl = vid.link video.id = vid.link.split("?v=")[1] video.videoTitle = vid.title video.videoThumb = vid.media_thumbnail[0]['url'] diff --git a/app/static/styles.css b/app/static/styles.css new file mode 100644 index 0000000..0816937 --- /dev/null +++ b/app/static/styles.css @@ -0,0 +1,20 @@ +.para-light-grey{ + background-color: rgb(250, 82, 82); +} + +.para-green{ + background-color: lightgreen; +} + +.twitter{ + color: rgb(0, 166, 196) !important; +} + +.youtube{ + color: rgb(224, 32, 32) !important; +} + +.video-title{ + font-weight: bold; + font-size: 1.15em; +} \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index 437ee66..9ee6146 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -9,21 +9,7 @@ Parasitter {% endif %} - - +