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 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/<id>', 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']

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>
{% endif %}
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='semantic/semantic.min.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>
<link rel="stylesheet" type= "text/css" href="{{ url_for('static',filename='styles.css') }}">
</head>
<body>
<div class="ui stackable menu">

View File

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