Skip to content

Commit

Permalink
[WIP] youtubeng video
Browse files Browse the repository at this point in the history
  • Loading branch information
lowne committed Oct 25, 2020
1 parent 3ed421f commit ff9e930
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ app/cache/*
app/cache
./app/cache/*
./app/cache
/samples/
53 changes: 12 additions & 41 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,53 +234,24 @@ def get_live_urls(urls):
return best_urls


@app.route('/v/<id>', methods=['GET'])
@login_required
def v_id(id):
return _video_page(request, ytVideo(id))

@app.route('/watch', methods=['GET'])
@login_required
def watch():
id = request.args.get('v', None)
info = ytwatch.extract_info(id, False, playlist_id=None, index=None)

vsources = ytwatch.get_video_sources(info, False)
# Retry 3 times if no sources are available.
retry = 3
while retry != 0 and len(vsources) == 0:
vsources = ytwatch.get_video_sources(info, False)
retry -= 1

for source in vsources:
source['src'] = proxy_video_source_url(source['src'])
vid = request.args.get('v', None)
if not vid: return redirect(url_for('error/405'))
return _video_page(request, ytVideo(vid))

# Parse video formats
for v_format in info['formats']:
v_format['url'] = proxy_video_source_url(v_format['url'])
if v_format['audio_bitrate'] is not None and v_format['vcodec'] is None:
v_format['audio_valid'] = True

captions = ytwatch.get_subtitle_sources(info)
for caption in captions:
caption['src'] = proxy_image_url(caption['src'])

def _video_page(request, video):
# Markup description
try:
info['description'] = Markup(bleach.linkify(info['description'].replace("\n", "<br>")))
except AttributeError or TypeError:
print(info['description'])

# Get comments
videocomments = comments.video_comments(id, sort=0, offset=0, lc='', secret_key='')
# videocomments = utils.post_process_comments_info(videocomments)
if videocomments is not None:
videocomments.sort(key=lambda x: x['likes'], reverse=True)
for cmnt in videocomments:
cmnt['thumbnail'] = proxy_image_url(cmnt['thumbnail'])

# Calculate rating %
if info['like_count']+info['dislike_count']>0:
info['rating'] = str((info['like_count'] / (info['like_count'] + info['dislike_count'])) * 100)[0:4]
else:
info['rating'] = 50.0
return render_template("video.html", info=info, title='{}'.format(info['title']), config=config,
videocomments=videocomments, vsources=vsources, captions=captions)
description = Markup(bleach.linkify(video.description.replace("\n", "<br>")))

return render_template("video.html", video=video, description=description, config=config, comments=[])


def markupString(string):
Expand Down
50 changes: 21 additions & 29 deletions app/templates/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
{% extends "base.html" %}
{% block content %}
<div class="ui text container">
{% if info.error != None or info.playability_error != None %}
{% if video.invalid %}
<div class="ui center aligned text container">
<div class="ui segment">
<h4 class="ui header">ERROR WITH VIDEO</h4>
</div>
</div>
{% elif info.playability_status != None %}
{% elif False and video.TODO_playability_status != None %}
<div class="ui center aligned text container">
<div class="ui segment">
<h4 class="ui header">SCHEDULED VIDEO</h4>
<h5 class="ui header">{{video.premieres}}</h5>
</div>
</div>
{% elif info.live %}
{% elif video.is_live %}
<div class="video-js-responsive-container vjs-hd">
<video-js id=live width="1080" class="video-js vjs-default-skin" controls>
<source
Expand All @@ -40,10 +40,10 @@ <h5 class="ui header">Livestreams are under developent and still not supported o
controls
buffered
preload="none">
{% for source in vsources %}
{% for source in video.av_sources %}
<source src="{{source.src}}" type="{{source.type}}">
{% endfor %}
{% for caption in captions %}
{% for caption in video.caption_sources %}
<track kind="captions" src="{{caption.src}}" srclang="{{caption.srclang}}" label="{{caption.label}}">
{% endfor %}
</video-js>
Expand All @@ -52,61 +52,53 @@ <h5 class="ui header">Livestreams are under developent and still not supported o

<div class="ui segments">
<div class="ui segment">
<h2 class="ui header break-word">{{info.title}}</h2>
<h2 class="ui header break-word">{{video.title}}</h2>
</div>
<div class="ui horizontal segments">
<div class="center aligned ui segment">
<a href="{{ url_for('channel', id=info.author_id)}}">
<i class="user icon"></i> <b>{{info.author}}</b>
<a href="{{ url_for('channel', id=video.cid)}}">
<i class="user icon"></i> <b>{{video.channel_name}}</b>
</a>
</div>
<div class="center aligned ui segment">
<div class="ui mini statistic">
<div class="value">
<i class="grey eye icon"></i> <b>{{info.view_count}}</b>
<i class="grey eye icon"></i> <b>{{video.views_human}}</b>
</div>
<div class="label">
views
</div>
</div>
</div>
<div class="center aligned ui segment">
{% if info.rating | int > 49 %}
<div class="ui mini statistic">
<div class="value">
<i class="green thumbs up icon"></i> <b>{{info.rating}}%</b>
</div>
<div class="label">
Total: {{info.like_count+info.dislike_count}} votes
</div>
</div>
{% else %}
<div class="ui mini statistic">
<div class="value">
<i class="red thumbs down icon"></i> <b>{{info.rating}}%</b>
{% if video.rating | int > 49 %}
<i class="green thumbs up icon"></i>
{% else %}
<i class="red thumbs down icon"></i>
{% endif %}
<b>{{video.rating}}%</b>
</div>
<div class="label">
Total: {{info.like_count+info.dislike_count}} votes
</div>
{{video.rating_count}} votes
</div>
{% endif %}
</div>
</div>
</div>

<div class="ui raised center aligned segment break-word">
<p><i class="grey music icon"></i><b>Audio Only</b></p>
<audio controls>
{% for format in info.formats %}
{% if format.audio_valid %}
<source src="{{format.url}}">
{%endif%}
{% for source in video.audio_sources %}
<source src="{{source.src}}">
{%endfor%}
No audio available.
</audio>
</div>

<div class="ui raised segment break-word">
<p>{{info.description}}</p>
<p>{{description}}</p>
</div>
</div>

Expand All @@ -118,7 +110,7 @@ <h3 class="ui dividing header">Comments</h3>
</div>

<script src="{{ url_for('static',filename='video.min.js') }}"></script>
{% if info.live %}
{% if video.is_live %}
<script src="{{ url_for('static',filename='videojs-http-streaming.min.js')}}"></script>
<script>
var player = videojs('live');
Expand Down
Loading

0 comments on commit ff9e930

Please sign in to comment.