diff --git a/.gitignore b/.gitignore index a9825c7..7dbc86c 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ app/cache/* app/cache ./app/cache/* ./app/cache +/samples/ \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 0f9b598..2087c7e 100644 --- a/app/routes.py +++ b/app/routes.py @@ -234,53 +234,24 @@ def get_live_urls(urls): return best_urls +@app.route('/v/', 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", "
"))) - 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", "
"))) + + return render_template("video.html", video=video, description=description, config=config, comments=[]) def markupString(string): diff --git a/app/templates/video.html b/app/templates/video.html index a5d25f7..1ca7d39 100644 --- a/app/templates/video.html +++ b/app/templates/video.html @@ -4,20 +4,20 @@ {% extends "base.html" %} {% block content %}
- {% if info.error != None or info.playability_error != None %} + {% if video.invalid %}

ERROR WITH VIDEO

- {% elif info.playability_status != None %} + {% elif False and video.TODO_playability_status != None %}

SCHEDULED VIDEO

{{video.premieres}}
- {% elif info.live %} + {% elif video.is_live %}
Livestreams are under developent and still not supported o controls buffered preload="none"> - {% for source in vsources %} + {% for source in video.av_sources %} {% endfor %} - {% for caption in captions %} + {% for caption in video.caption_sources %} {% endfor %} @@ -52,18 +52,18 @@
Livestreams are under developent and still not supported o
-

{{info.title}}

+

{{video.title}}

- {{info.view_count}} + {{video.views_human}}
views @@ -71,42 +71,34 @@

{{info.title}}

- {% if info.rating | int > 49 %} -
-
- {{info.rating}}% -
-
- Total: {{info.like_count+info.dislike_count}} votes -
-
- {% else %}
- {{info.rating}}% + {% if video.rating | int > 49 %} + + {% else %} + + {% endif %} + {{video.rating}}%
- Total: {{info.like_count+info.dislike_count}} votes -
+ {{video.rating_count}} votes
- {% endif %} +

Audio Only

-

{{info.description}}

+

{{description}}

@@ -118,7 +110,7 @@

Comments

-{% if info.live %} +{% if video.is_live %}