Video seeking is now possible
This commit is contained in:
parent
b06f96f9c4
commit
70c25f097f
@ -4,6 +4,7 @@ from app.models import User, twitterPost, ytPost, Post, youtubeFollow, twitterFo
|
||||
from flask_login import login_user, logout_user, current_user, login_required
|
||||
from flask import Flask, Response, stream_with_context
|
||||
from requests_futures.sessions import FuturesSession
|
||||
from werkzeug.datastructures import Headers
|
||||
from concurrent.futures import as_completed
|
||||
from werkzeug.utils import secure_filename
|
||||
from youtube_search import YoutubeSearch
|
||||
@ -12,6 +13,7 @@ from youtube_dl import YoutubeDL
|
||||
from numerize import numerize
|
||||
from bs4 import BeautifulSoup
|
||||
from app import app, db
|
||||
from re import findall
|
||||
import random, string
|
||||
import time, datetime
|
||||
import feedparser
|
||||
@ -321,18 +323,27 @@ def watch():
|
||||
return render_template("video.html", video=video)
|
||||
|
||||
## PROXY videos through Parasitter server to the client.
|
||||
@app.route('/stream', methods=['GET'])
|
||||
@app.route('/stream', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def stream():
|
||||
#This function proxies the video stream from GoogleVideo to the client.
|
||||
id = request.args.get('v', None)
|
||||
headers = Headers()
|
||||
if(id):
|
||||
ydl = YoutubeDL()
|
||||
data = ydl.extract_info("{id}".format(id=id), download=False)
|
||||
req = requests.get(data['formats'][-1]['url'], stream = True)
|
||||
return Response(req.iter_content(chunk_size=10*1024), mimetype=req.headers['Content-Type'], direct_passthrough=True, content_type=req.headers['Content-Type'])
|
||||
headers.add('Accept-Ranges','bytes')
|
||||
headers.add('Content-Length', str(int(req.headers['Content-Length'])+1))
|
||||
response = Response(req.iter_content(chunk_size=12*1024), mimetype=req.headers['Content-Type'], content_type=req.headers['Content-Type'], direct_passthrough=True, headers=headers)
|
||||
#enable browser file caching with etags
|
||||
response.cache_control.public = True
|
||||
response.cache_control.max_age = int(60000)
|
||||
return response
|
||||
else:
|
||||
flash("Something went wrong loading the video... Try again.")
|
||||
return redirect(url_for('youtube'))
|
||||
|
||||
#########################
|
||||
#### General Logic ######
|
||||
#########################
|
||||
|
@ -7,7 +7,7 @@
|
||||
<div class="meta">
|
||||
<a href="{{url_for('channel', id=video.channelId)}}">{{video.channelName}}</a>
|
||||
</div>
|
||||
<div class="description">
|
||||
<div class="description break-word">
|
||||
{{video.description}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -8,8 +8,9 @@
|
||||
<video class="video-js vjs-default-skin"
|
||||
data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }'
|
||||
width="1080"
|
||||
controls
|
||||
preload="auto">
|
||||
controls = "1"
|
||||
buffered
|
||||
preload="none">
|
||||
<source src="/stream?v={{video.id}}" type="video/mp4">
|
||||
</video>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user