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_login import login_user, logout_user, current_user, login_required
|
||||||
from flask import Flask, Response, stream_with_context
|
from flask import Flask, Response, stream_with_context
|
||||||
from requests_futures.sessions import FuturesSession
|
from requests_futures.sessions import FuturesSession
|
||||||
|
from werkzeug.datastructures import Headers
|
||||||
from concurrent.futures import as_completed
|
from concurrent.futures import as_completed
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from youtube_search import YoutubeSearch
|
from youtube_search import YoutubeSearch
|
||||||
@ -12,6 +13,7 @@ from youtube_dl import YoutubeDL
|
|||||||
from numerize import numerize
|
from numerize import numerize
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from app import app, db
|
from app import app, db
|
||||||
|
from re import findall
|
||||||
import random, string
|
import random, string
|
||||||
import time, datetime
|
import time, datetime
|
||||||
import feedparser
|
import feedparser
|
||||||
@ -321,18 +323,27 @@ def watch():
|
|||||||
return render_template("video.html", video=video)
|
return render_template("video.html", video=video)
|
||||||
|
|
||||||
## PROXY videos through Parasitter server to the client.
|
## PROXY videos through Parasitter server to the client.
|
||||||
@app.route('/stream', methods=['GET'])
|
@app.route('/stream', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def stream():
|
def stream():
|
||||||
|
#This function proxies the video stream from GoogleVideo to the client.
|
||||||
id = request.args.get('v', None)
|
id = request.args.get('v', None)
|
||||||
|
headers = Headers()
|
||||||
if(id):
|
if(id):
|
||||||
ydl = YoutubeDL()
|
ydl = YoutubeDL()
|
||||||
data = ydl.extract_info("{id}".format(id=id), download=False)
|
data = ydl.extract_info("{id}".format(id=id), download=False)
|
||||||
req = requests.get(data['formats'][-1]['url'], stream = True)
|
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:
|
else:
|
||||||
flash("Something went wrong loading the video... Try again.")
|
flash("Something went wrong loading the video... Try again.")
|
||||||
return redirect(url_for('youtube'))
|
return redirect(url_for('youtube'))
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
#### General Logic ######
|
#### General Logic ######
|
||||||
#########################
|
#########################
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<div class="meta">
|
<div class="meta">
|
||||||
<a href="{{url_for('channel', id=video.channelId)}}">{{video.channelName}}</a>
|
<a href="{{url_for('channel', id=video.channelId)}}">{{video.channelName}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="description">
|
<div class="description break-word">
|
||||||
{{video.description}}
|
{{video.description}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,8 +8,9 @@
|
|||||||
<video class="video-js vjs-default-skin"
|
<video class="video-js vjs-default-skin"
|
||||||
data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }'
|
data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }'
|
||||||
width="1080"
|
width="1080"
|
||||||
controls
|
controls = "1"
|
||||||
preload="auto">
|
buffered
|
||||||
|
preload="none">
|
||||||
<source src="/stream?v={{video.id}}" type="video/mp4">
|
<source src="/stream?v={{video.id}}" type="video/mp4">
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user