{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "624782f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "import googleapiclient.discovery\n",
    "\n",
    "os.environ[\"OAUTHLIB_INSECURE_TRANSPORT\"] = \"1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c0716e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "api_service_name = \"youtube\"\n",
    "api_version = \"v3\"\n",
    "DEVELOPER_KEY = \"AIzaSyAnt9j-ctEjsgo0HHp_eGOID2iLa_pyo5k\"\n",
    "\n",
    "youtube = googleapiclient.discovery.build(\n",
    "    api_service_name, api_version, developerKey=DEVELOPER_KEY\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fa3c5e9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'kind': 'youtube#searchListResponse', 'etag': 'ixHrcEJ0vaUegQ2OAcBnLIjOaXo', 'nextPageToken': 'CAUQAA', 'regionCode': 'US', 'pageInfo': {'totalResults': 80344, 'resultsPerPage': 5}, 'items': [{'kind': 'youtube#searchResult', 'etag': 'STXIyprVwKfCtRLduS6QuxI2pKY', 'id': {'kind': 'youtube#video', 'videoId': '5NzazFJcSdI'}, 'snippet': {'publishedAt': '2022-12-03T08:50:12Z', 'channelId': 'UCtIUybZ-0lrbPJFb8SFCGuA', 'title': 'Deon Meyer koersvas wanneer hy skryf', 'description': 'Deon Meyer vertel in hierdie video meer oor sy ervaring van die Karoo Suite-produksies, hy brei uit oor sy skryfwerk en sê hoe hy ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/5NzazFJcSdI/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/5NzazFJcSdI/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/5NzazFJcSdI/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Maroela Media', 'liveBroadcastContent': 'none', 'publishTime': '2022-12-03T08:50:12Z'}}, {'kind': 'youtube#searchResult', 'etag': 'pFpBvWspWJZPB8BdboWldIMM0R0', 'id': {'kind': 'youtube#video', 'videoId': 'ZkinZRoiinA'}, 'snippet': {'publishedAt': '2020-08-24T11:39:57Z', 'channelId': 'UCjgCIKglePC8SaAZ14vuKPw', 'title': 'Skrywers vertel waarom en hoe hulle skryf', 'description': 'UJ-prysbenoemde in 2016, Johan Fourie, Marie Reyneke met talle voorgeskrewe boeke vir hoërskoolskoliere en Jaap Rabie, ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/ZkinZRoiinA/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/ZkinZRoiinA/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/ZkinZRoiinA/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Die Vulpenfles', 'liveBroadcastContent': 'none', 'publishTime': '2020-08-24T11:39:57Z'}}, {'kind': 'youtube#searchResult', 'etag': '7D9feI_WwWwWS5Omojrt6ziBy-c', 'id': {'kind': 'youtube#video', 'videoId': 'rRrUv3uDAIk'}, 'snippet': {'publishedAt': '2021-02-16T08:19:11Z', 'channelId': 'UCQ7dg47EldwFIEgvRydft9g', 'title': 'Skryf Syfers. Skryf getalle. Leer hoe om die syfers te skryf en vorm.', 'description': 'Afrikaanse opvoedkundige videos. Lettervorming en skryf. Herken getalle nul tot twintig. Klara kyk na hoe die syfers 0-20 geskryf ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/rRrUv3uDAIk/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/rRrUv3uDAIk/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/rRrUv3uDAIk/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Klara Klets!', 'liveBroadcastContent': 'none', 'publishTime': '2021-02-16T08:19:11Z'}}, {'kind': 'youtube#searchResult', 'etag': 'FoC08t3WaQfI3yKttgvKP-UDYYU', 'id': {'kind': 'youtube#video', 'videoId': 'SjRmp3-qzFE'}, 'snippet': {'publishedAt': '2020-03-02T03:30:01Z', 'channelId': 'UCqL392BrUmnEosYpmBnS9zw', 'title': 'Skryf a place to Read. Play. Eat an offline library with great food', 'description': 'An amazing place who sends books to your doorsteps as well as offline library with variety of plans available, a unique concept in ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/SjRmp3-qzFE/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/SjRmp3-qzFE/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/SjRmp3-qzFE/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Urban Khabri', 'liveBroadcastContent': 'none', 'publishTime': '2020-03-02T03:30:01Z'}}, {'kind': 'youtube#searchResult', 'etag': 'G_VwrMeY-tStLIijitkwtLwOUAc', 'id': {'kind': 'youtube#video', 'videoId': 'uuRybNqPi3A'}, 'snippet': {'publishedAt': '2020-07-06T00:56:06Z', 'channelId': 'UCNI6sHZBGQ8t23SA8g905gw', 'title': 'Skryf &#39;n dialoog', 'description': 'Learning dialogue writing format.', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/uuRybNqPi3A/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/uuRybNqPi3A/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/uuRybNqPi3A/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Grade 4 Teacher', 'liveBroadcastContent': 'none', 'publishTime': '2020-07-06T00:56:06Z'}}]}\n"
     ]
    }
   ],
   "source": [
    "request = youtube.search().list(\n",
    "    part=\"snippet\",\n",
    "    q=\"skryf\",\n",
    "    relevanceLanguage=\"af\",\n",
    "    type=\"video\",\n",
    "    videoCaption=\"any\"\n",
    ")\n",
    "response = request.execute()\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a496ec5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'kind': 'youtube#searchListResponse', 'etag': 'ewKY913O45DdW6uEgCpLTsRFQ_I', 'nextPageToken': 'CAUQAA', 'regionCode': 'US', 'pageInfo': {'totalResults': 80260, 'resultsPerPage': 5}, 'items': [{'kind': 'youtube#searchResult', 'etag': 'phKy5ZnNNf_iYU3ViBxq4GEQ15Y', 'id': {'kind': 'youtube#video', 'videoId': 'pzmB0GoEKkA'}, 'snippet': {'publishedAt': '2019-10-22T14:00:10Z', 'channelId': 'UCVcQH8A634mauPrGbWs7QlQ', 'title': 'Let&#39;s Learn Our Numbers 0-10 | Counting Song for Kids | Jack Hartmann Writing Numbers', 'description': \"Jack Hartmann's Let's Learn Our Numbers 0-10 engages students in recognizing and writing each numeral 0-10 with a rhyming ...\", 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/pzmB0GoEKkA/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/pzmB0GoEKkA/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/pzmB0GoEKkA/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Jack Hartmann Kids Music Channel', 'liveBroadcastContent': 'none', 'publishTime': '2019-10-22T14:00:10Z'}}, {'kind': 'youtube#searchResult', 'etag': 'auo7zZphb_o484FBJFWQb47wYlA', 'id': {'kind': 'youtube#video', 'videoId': 'AEOyHUXhGog'}, 'snippet': {'publishedAt': '2022-11-21T05:00:10Z', 'channelId': 'UC5W1Yz1i7Cvh904MJvYiMmg', 'title': 'Maandag, 21 November 2022.  Doeners skryf die geskiedenis', 'description': 'Suid-Afrika : Suidland Verdediging : www.suidlanders.co.za/verdediging-aansluit/ Suidlanders Siviel : www.suidlanders.co.za ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/AEOyHUXhGog/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/AEOyHUXhGog/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/AEOyHUXhGog/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Wynand du Toit', 'liveBroadcastContent': 'none', 'publishTime': '2022-11-21T05:00:10Z'}}, {'kind': 'youtube#searchResult', 'etag': 'XqWYUXkAXTFZu4oT8jl3PFi0lFc', 'id': {'kind': 'youtube#video', 'videoId': 'D9Ihs241zeg'}, 'snippet': {'publishedAt': '2009-10-07T19:40:32Z', 'channelId': 'UCAuUUnT6oDeKwE6v1NGQxug', 'title': 'Chimamanda Ngozi Adichie: The danger of a single story | TED', 'description': 'Our lives, our cultures, are composed of many overlapping stories. Novelist Chimamanda Adichie tells the story of how she found ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/D9Ihs241zeg/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/D9Ihs241zeg/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/D9Ihs241zeg/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'TED', 'liveBroadcastContent': 'none', 'publishTime': '2009-10-07T19:40:32Z'}}, {'kind': 'youtube#searchResult', 'etag': 'q0KrKQaeJ22ZgT-qsKBlyCGpAkc', 'id': {'kind': 'youtube#video', 'videoId': 'KGZFmW3uPJE'}, 'snippet': {'publishedAt': '2016-07-29T17:16:59Z', 'channelId': 'UCVcQH8A634mauPrGbWs7QlQ', 'title': 'Letter A  Alphabet Song for Kids  Let&#39;s Learn About The Alphabet  Phonics Song  Jack Hartmann', 'description': \"Let's Learn About the Alphabet by Jack Hartmann Learn the letter A. This Alphabet song in our Let's Learn About the Alphabet ...\", 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/KGZFmW3uPJE/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/KGZFmW3uPJE/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/KGZFmW3uPJE/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'Jack Hartmann Kids Music Channel', 'liveBroadcastContent': 'none', 'publishTime': '2016-07-29T17:16:59Z'}}, {'kind': 'youtube#searchResult', 'etag': '1PiB6LyXNc4KQjjG0wgZaHgTskY', 'id': {'kind': 'youtube#video', 'videoId': 'hmEd-BB9nZc'}, 'snippet': {'publishedAt': '2022-01-16T11:03:15Z', 'channelId': 'UCrI3Um2oFwR5ZELXRelUCpg', 'title': '20220116 Skryf die opskrif van jou lewe!|Janine Bevolo-Manders|#FB105', 'description': 'Wat sou jy as opskrif van jou lewe wou skryf, as jy nou die kans kry?', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/hmEd-BB9nZc/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/hmEd-BB9nZc/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/hmEd-BB9nZc/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'NHK Witfontein', 'liveBroadcastContent': 'none', 'publishTime': '2022-01-16T11:03:15Z'}}]}\n"
     ]
    }
   ],
   "source": [
    "request = youtube.search().list(\n",
    "    part=\"snippet\",\n",
    "    q=\"skryf\",\n",
    "    relevanceLanguage=\"af\",\n",
    "    type=\"video\",\n",
    "    videoCaption=\"closedCaption\"\n",
    ")\n",
    "response = request.execute()\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b442c1fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['pzmB0GoEKkA', 'AEOyHUXhGog', 'D9Ihs241zeg', 'KGZFmW3uPJE', 'hmEd-BB9nZc']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[m[\"id\"][\"videoId\"] for m in response[\"items\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4273bc7b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bff45164",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "974dee20",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfe37b07",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27d0b8aa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
