diff --git a/conference/management/commands/get_video_urls.py b/conference/management/commands/get_video_urls.py new file mode 100644 index 000000000..651aae8dd --- /dev/null +++ b/conference/management/commands/get_video_urls.py @@ -0,0 +1,68 @@ +import os + +from django.core.management.base import BaseCommand, CommandError + +import googleapiclient.discovery +import googleapiclient.errors + + +class Command(BaseCommand): + """ + Get details of the videos corresponding to the provided playlist. + """ + def add_arguments(self, parser): + parser.add_argument('--playlist-id', type=str, required=True) + + def handle(self, *args, **options): + # Setup the API client + playlist_id = options['playlist_id'] + api_service_name = "youtube" + api_version = "v3" + api_key = os.getenv("GOOGLE_API_KEY") + + youtube_client = googleapiclient.discovery.build( + serviceName=api_service_name, + version=api_version, + developerKey=api_key, + ) + + # Fetch the video data from the API + playlist_items = [] + items_per_page = 50 # max allowed by the api + default_request_args = dict( + part="snippet,contentDetails", + maxResults=items_per_page, + playlistId=playlist_id, + ) + + request = youtube_client.playlistItems().list(**default_request_args) + response = request.execute() + + page_count = 1 + total_results = response["pageInfo"]["totalResults"] + playlist_items += response["items"] + + while page_count * items_per_page < total_results: + next_page_token = response["nextPageToken"] + + request = youtube_client.playlistItems().list(**default_request_args, pageToken=next_page_token) + response = request.execute() + + page_count += 1 + playlist_items += response["items"] + + # Process the results + processed_items = [] + for item in playlist_items: + video_id = item['contentDetails']['videoId'] + youtube_title = item['snippet']['title'] + title_separator = ' - ' + title_separator_ix = youtube_title.find(title_separator) + + processed_items.append({ + 'speaker': youtube_title[:title_separator_ix], + 'title': youtube_title[title_separator_ix + len(title_separator):], + 'url': f'https://www.youtube.com/watch?v={video_id}', + }) + + print(processed_items) diff --git a/conference/talks.py b/conference/talks.py index c27b6a6cf..5208699ab 100644 --- a/conference/talks.py +++ b/conference/talks.py @@ -152,6 +152,7 @@ def dump_relevant_talk_information_to_dict(talk: Talk): "schedule_url": talk.get_schedule_url(), "slides_file_url": talk.slides, "slides_remote_url": talk.slides_url, + "video_url": talk.video_url, } for speaker in talk.get_all_speakers(): diff --git a/templates/ep19/bs/talks/talk.html b/templates/ep19/bs/talks/talk.html index 76b5dac3f..446b237c1 100644 --- a/templates/ep19/bs/talks/talk.html +++ b/templates/ep19/bs/talks/talk.html @@ -49,6 +49,9 @@
{{ talk_as_dict.abstract|urlize|linebreaks }}
Type: {{ talk.get_type_display }}; Python level: {{ talk.get_level_display }}; Domain level: {{ talk.get_domain_level_display }}
diff --git a/tests/test_talks.py b/tests/test_talks.py
index 70c993d25..434a768d1 100644
--- a/tests/test_talks.py
+++ b/tests/test_talks.py
@@ -288,3 +288,26 @@ def test_view_slides_remote_url_on_talk_detail_page(client):
response = client.get(url)
assert 'view slides' in response.content.decode().lower()
+
+
+def test_video_url_on_talk_detail_page(client):
+ """
+ The view recording button only appears if the video url has been updated.
+ """
+ setup_conference_with_typical_fares()
+ talk = TalkFactory(status=TALK_STATUS.accepted)
+ url = talk.get_absolute_url()
+
+ # Slides URL does not appear when the slides haven't been uploaded
+ response = client.get(url)
+
+ assert not talk.slides
+ assert 'view recording' not in response.content.decode().lower()
+
+ # Slides URL does appear when the slides have been uploaded
+ talk.video_url = 'https://ep2019.europython.eu/video'
+ talk.save()
+
+ response = client.get(url)
+
+ assert 'view recording' in response.content.decode().lower()