Skip to content

Commit

Permalink
Update Plyr (3.3.20 -> 3.3.21), improve API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
tocsinde committed Jun 29, 2018
1 parent bb09913 commit 8a9affc
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 34 deletions.
16 changes: 7 additions & 9 deletions newsic/autocomplete.py
Expand Up @@ -42,9 +42,9 @@ def search():

debug(("Incoming POST request: {}").format(request.json["search"]))

#TODO: use fields for filtering the results
yt_search_request = (
"{}/search?q={}&type=playlist&part=id,snippet"
+ "&fields=items(id/playlistId,snippet(thumbnails/medium/url,title))"
+ "&maxResults={}&key={}").format(
read_config("YOUTUBE_API_URL"), quote(request.json["search"]),
max_results, read_config("YOUTUBE_API_KEY"))
Expand All @@ -62,23 +62,21 @@ def search():

for playlist in youtube["items"]:

#TODO: use fields for filtering the results

req = (
"{}/playlistItems?playlistId={}"
+ "&part=id&fields=pageInfo(totalResults)"
+ "&part=id&fields=pageInfo/totalResults"
+ "&maxresults=1&key={}").format(
read_config("YOUTUBE_API_URL"), playlist["id"]["playlistId"], read_config("YOUTUBE_API_KEY"))
request_send = urllib_request.urlopen(req)
videos_in_playlist = loads(request_send.read().decode())

#TODO: decide what to return in case of missing thumbnail
thumbnail_url = ""

if "thumbnails" in playlist["snippet"]:
# api call needed as playlist thumbnail != thumbnail of first video (or not inevitable)
thumbnail_url = playlist["snippet"]["thumbnails"]["medium"]["url"]

#TODO: decide what to return in case of missing thumbnail
else:
thumbnail_url = ""

result.append({
"source": "youtube",
"id": playlist["id"]["playlistId"],
Expand All @@ -91,9 +89,9 @@ def search():
"source": "vimeo",
"id": video["uri"].split("/")[2],
"title": video["name"],
#TODO: check if thumbnail of first video is always thumbnail of channel (or customizable as on YouTube)
"thumb": ("https://i.vimeocdn.com/video/{}_100x75.jpg").format(video["pictures"]["uri"].split("/")[4]),
"amount": video["metadata"]["connections"]["videos"]["total"]
})


return dumps(result)
1 change: 0 additions & 1 deletion newsic/static/css/plyr/plyr-3.3.20.css

This file was deleted.

1 change: 1 addition & 0 deletions newsic/static/css/plyr/plyr-3.3.21.css

Large diffs are not rendered by default.

File renamed without changes
2 changes: 0 additions & 2 deletions newsic/static/js/autocomplete.js
Expand Up @@ -22,8 +22,6 @@

var list = [];
var timeout = null;
var playlist;
//var autocomplete = false;

var container = document.getElementById("autocomplete");
var input = container.getElementsByTagName("input")[0];
Expand Down
2 changes: 1 addition & 1 deletion newsic/static/js/autocomplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions newsic/static/js/plyr/plyr-3.3.20.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions newsic/static/js/plyr/plyr-3.3.21.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion newsic/static/js/plyr/plyr.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion newsic/static/js/videohandler.js
Expand Up @@ -90,7 +90,7 @@ var optionsPlyr = {
autoplay: autoplayPlyr,
blankUrl: '/static/blank.mp4',
debug: false,
iconUrl: '/static/img/plyr/plyr-3.3.20.svg',
iconUrl: '/static/img/plyr/plyr-3.3.21.svg',
keyboard: { global: false, focused: false },
tooltips: { controls: true },
captions: { active: false },
Expand Down
2 changes: 1 addition & 1 deletion newsic/static/js/videohandler.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions newsic/templates/play.html
Expand Up @@ -2,7 +2,7 @@

{% block css %}
<!-- Plyr -->
<link href="{{ url_for('static', filename='css/plyr/plyr-3.3.20.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ url_for('static', filename='css/plyr/plyr-3.3.21.css') }}" rel="stylesheet" type="text/css" />
{% endblock %}

{% block metatags %}
Expand Down Expand Up @@ -163,7 +163,7 @@ <h2>{{ playlistTitle }}</h2>
<!-- JavaScript files -->

<!-- Plyr -->
<script src="{{ url_for('static', filename='js/plyr/plyr-3.3.20.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/plyr/plyr-3.3.21.min.js') }}"></script>

<script async src="{{ url_for('static', filename='js/videohandler.js') }}"></script>
<script async src="{{ url_for('static', filename='js/autocomplete.js') }}"></script>
Expand Down
24 changes: 10 additions & 14 deletions newsic/youtube.py
Expand Up @@ -48,10 +48,9 @@ def yt_grab(video_ids=[], playlist_id=None):

# fetch video ids from playlist
while True:
#TODO: use fields for filtering the results
request_video_ids = (
"{}/playlistItems?part=contentDetails&playlistId={}"
+ "&fields=items%2FcontentDetails%2CnextPageToken%2CpageInfo"
+ "&fields=items/contentDetails/videoId,nextPageToken"
+ "&key={}&maxResults={}&pageToken={}").format(
read_config("YOUTUBE_API_URL"), playlist_id, read_config("YOUTUBE_API_KEY"),
max_results, next_page_token)
Expand Down Expand Up @@ -80,8 +79,10 @@ def yt_grab(video_ids=[], playlist_id=None):

while request_iteration > 0:
video_ids_part = ','.join(video_ids[range_start:range_end])
#TODO: use fields for filtering the results
url = ("{}/videos?part=contentDetails,snippet,status&id={}&key={}").format(
url = (
"{}/videos?part=contentDetails,snippet,status"
+ "&fields=items(contentDetails(countryRestriction,duration,regionRestriction),id,snippet/title,status(embeddable,privacyStatus,uploadStatus))"
+ "&id={}&key={}").format(
read_config("YOUTUBE_API_URL"), video_ids_part, read_config("YOUTUBE_API_KEY"))
response = urllib_request.urlopen(url)
data = loads(response.read().decode())
Expand Down Expand Up @@ -173,13 +174,12 @@ def yt_grab(video_ids=[], playlist_id=None):
def yt_general_playlist_info(playlist_id):

"""
Fetch general information about the playlist (defined by given playlist_id)
Fetch general information about a playlist (defined by given playlist_id)
"""

request_data = (
#TODO: use fields for filtering the results
"{}/playlists?part=snippet,status&id={}"
+ "&fields=items&key={}").format(
"{}/playlists?part=snippet&id={}"
+ "&fields=items(snippet(channelTitle,title))&key={}").format(
read_config("YOUTUBE_API_URL"), playlist_id, read_config("YOUTUBE_API_KEY"))
data_response = loads(urllib_request.urlopen(request_data).read().decode())

Expand All @@ -199,12 +199,9 @@ def mix_youtube(video_id):
TODO: improve performance
"""

#TODO: use fields for filtering the results
# needed: snippet title

api_get_video_title = (
"{}/videos?id={}&part=snippet"
+ "&key={}").format(
+ "&fields=items/snippet/title&key={}").format(
read_config("YOUTUBE_API_URL"), video_id, read_config("YOUTUBE_API_KEY"))
response_title = urllib_request.urlopen(api_get_video_title)
data_title = loads(response_title.read().decode())
Expand All @@ -216,10 +213,9 @@ def mix_youtube(video_id):

max_results = 15

#TODO: use fields for filtering the results
# needed: ["pageInfo"]["totalResults"], playlistID (random one from "items")
api_search_with_title = (
"{}/search?q={}&type=playlist&part=id"
+ "&fields=items/id/playlistId,pageInfo/totalResults"
+ "&maxResults={}&key={}").format(
read_config("YOUTUBE_API_URL"), quote(video_title_nospaces),
max_results, read_config("YOUTUBE_API_KEY"))
Expand Down

0 comments on commit 8a9affc

Please sign in to comment.