Youtube: Break dependance with Invidious. Proxy not working.

This commit is contained in:
pluja 2020-08-04 23:18:59 +02:00
parent 6c4444bd5c
commit d7543a98ed
4 changed files with 66 additions and 51 deletions

View File

@ -6,19 +6,20 @@ from requests_futures.sessions import FuturesSession
from concurrent.futures import as_completed from concurrent.futures import as_completed
from werkzeug.urls import url_parse from werkzeug.urls import url_parse
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from youtube_dl import YoutubeDL
from app import app, db from app import app, db
import random, string import random, string
import time, datetime import time, datetime
import feedparser import feedparser
import requests import requests
import youtubedl
import json import json
import re import re
# Instances - Format must be instance.tld (No '/' and no 'https://') # Instances - Format must be instance.tld (No '/' and no 'https://')
nitterInstance = "https://nitter.net/" nitterInstance = "https://nitter.net/"
nitterInstanceII = "https://nitter.mastodont.cat/" nitterInstanceII = "https://nitter.mastodont.cat/"
invidiousInstance = "invidious.snopyta.org" invidiousInstance = "invidio.us"
proxy = "" #eg. socks5://IP:PORT
######################### #########################
#### Twitter Logic ###### #### Twitter Logic ######
@ -302,20 +303,24 @@ def ytunfollow(channelId):
@app.route('/video/<id>', methods=['POST', 'GET']) @app.route('/video/<id>', methods=['POST', 'GET'])
@login_required @login_required
def video(id): def video(id):
data = requests.get('https://{instance}/api/v1/videos/{id}'.format(instance=invidiousInstance, id=id)) if proxy:
data = json.loads(data.content) ydl_opts = {
'proxy':proxy
}
else:
ydl_opts = {}
ydl = YoutubeDL(ydl_opts)
data = ydl.extract_info("{id}".format(id=id), download=False)
video = { video = {
'title':data['title'], 'title':data['title'],
'description':Markup(data['descriptionHtml']), 'description':Markup(data['description']),
'viewCount':data['viewCount'], 'viewCount':data['view_count'],
'likeCount':data['likeCount'], 'author':data['uploader'],
'dislikeCount':data['dislikeCount'], 'authorUrl':data['uploader_url'],
'authorThumb':data['authorThumbnails'][4]['url'], 'id':id,
'author':data['author'], 'url': data['formats'][-1]['url'],
'authorUrl':data['authorUrl'], 'averageRating': str((float(data['average_rating'])/5)*100)
'instance':invidiousInstance,
'id':id
} }
return render_template("video.html", video=video) return render_template("video.html", video=video)
@ -501,6 +506,8 @@ def getPosts(account):
def getInvidiousPosts(ids): def getInvidiousPosts(ids):
videos = [] videos = []
ydl = YoutubeDL()
link = ydl.extract_info("https://www.youtube.com/watch?v=XCSfoiD8wUA", download=False)['formats'][-1]['url']
with FuturesSession() as session: with FuturesSession() as session:
futures = [session.get('https://{instance}/feed/channel/{id}'.format(instance=invidiousInstance, id=id.channelId)) for id in ids] futures = [session.get('https://{instance}/feed/channel/{id}'.format(instance=invidiousInstance, id=id.channelId)) for id in ids]
for future in as_completed(futures): for future in as_completed(futures):
@ -512,7 +519,6 @@ def getInvidiousPosts(ids):
video.timeStamp = getTimeDiff(vid.published_parsed) video.timeStamp = getTimeDiff(vid.published_parsed)
video.channelName = vid.author_detail.name video.channelName = vid.author_detail.name
video.channelUrl = vid.author_detail.href video.channelUrl = vid.author_detail.href
video.videoUrl = vid.link
video.id = vid.link.split("?v=")[1] video.id = vid.link.split("?v=")[1]
video.videoTitle = vid.title video.videoTitle = vid.title
video.videoThumb = vid.media_thumbnail[0]['url'] video.videoThumb = vid.media_thumbnail[0]['url']

20
app/static/styles.css Normal file
View File

@ -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;
}

View File

@ -9,21 +9,7 @@
<title>Parasitter</title> <title>Parasitter</title>
{% endif %} {% endif %}
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='semantic/semantic.min.css') }}"> <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='semantic/semantic.min.css') }}">
<link rel="stylesheet" type= "text/css" href="{{ url_for('static',filename='styles.css') }}">
<style>
.twitter{
color: rgb(0, 166, 196) !important;
}
.youtube{
color: rgb(224, 32, 32) !important;
}
.video-title{
font-weight: bold;
font-size: 1.15em;
}
</style>
</head> </head>
<body> <body>
<div class="ui stackable menu"> <div class="ui stackable menu">

View File

@ -2,38 +2,41 @@
{% block content %} {% block content %}
<div style="margin-top: 2em;" class="ui one column centered grid"> <div style="margin-top: 2em;" class="ui one column centered grid">
<iframe id='ivplayer' width='640' height='360' src='https://{{video.instance}}/embed/{{video.id}}' style='border:none;'> <video width="720" height="480" controls>
</iframe> <source src="{{video.url}}" type="video/mp4">
<track label="English" kind="subtitles" srclang="en" src="captions/vtt/sintel-en.vtt" default>
</video>
</div> </div>
<div style="margin-top: 2em;" class="ui one column center aligned grid"> <div style="margin-top: 2em;" class="ui one column center aligned grid">
<a href="https://{{video.instance}}/watch?v={{video.id}}"><h2 class="ui header">{{video.title}}</h2></a> <h2 class="ui header">{{video.title}}</h2></a>
</div> </div>
<div style="margin-top: 2em;" class="ui one column center aligned grid"> <div style="margin-top: 2em;" class="ui center aligned grid">
<a target="_blank" href="https://{{video.instance}}{{video.authorUrl}}" class="ui image label"> <div class="two wide column">
<img src="{{video.authorThumb}}"> <a target="_blank" href="{{video.authorUrl}}" class="ui label">
{%if video.author.__len__() > 8%} {%if video.author.__len__() > 8%}
{{video.author[0:8]+'...'}} <i class="user icon"></i> {{video.author[0:10]+'...'}}
{%else%} {%else%}
{{video.author}} <i class="user icon"></i> {{video.author}}
{%endif%} {%endif%}
</a> </a>
<div class="ui label">
<i class="eye icon"></i> {{video.viewCount}}
</div> </div>
<div class="two wide column">
<div class="ui label"> <div class="ui label">
<i class="thumbs up green icon"></i> {{video.likeCount}} <i class="eye icon"></i>{{video.viewCount}}
</div>
</div> </div>
<div class="two wide column">
<div class="ui label"> <div class="para-light-grey">
<i class="thumbs down red icon"></i> {{video.dislikeCount}} <div class="para-green" style="height:12px;width:{{video.averageRating.split(".")[0]}}%"></div>
</div>
<div class="label"> Rating: {{video.averageRating[0:4]}}% <i class="green thumbs up icon"></i></div>
</div> </div>
</div> </div>
<div style="margin-top: 2em;" class="ui one column center aligned grid"> <div style="margin-top: 2em;" class="ui one column center aligned grid">
<div style="margin-bottom: 2em;" class="ui comments"> <div style="margin-bottom: 2em;" class="ui comments">
<h3 class="ui dividing header">Description</h3> <h3 class="ui dividing header">Description</h3>