Spaces:
Sleeping
Sleeping
File size: 2,864 Bytes
ea87078 6a730ac ea87078 6a730ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/adewopova/Accident_detection_SM_City/blob/main/Youtube.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"import googleapiclient.discovery\n",
"from urllib.parse import parse_qs, urlparse\n",
"\n",
"#extract playlist id from url\n",
"url = input(\"Enter your Youtube Playlist URL : \")\n",
"query = parse_qs(urlparse(url).query, keep_blank_values=True)\n",
"playlist_id = query[\"list\"][0]\n",
"\n",
"print(f'get all playlist items links from {playlist_id}')\n",
"youtube = googleapiclient.discovery.build(\"youtube\", \"v3\", developerKey = \"\")\n",
"\n",
"request = youtube.playlistItems().list(\n",
" part = \"snippet\",\n",
" playlistId = playlist_id,\n",
" maxResults = 50\n",
")\n",
"response = request.execute()\n",
"\n",
"playlist_items = []\n",
"while request is not None:\n",
" response = request.execute()\n",
" playlist_items += response[\"items\"]\n",
" request = youtube.playlistItems().list_next(request, response)\n",
"\n",
"print(f\"total: {len(playlist_items)}\")\n",
"urllists=('\\n'.join([ \n",
" f'https://www.youtube.com/watch?v={t[\"snippet\"][\"resourceId\"][\"videoId\"]}&list={playlist_id}&t=0s'\n",
" for t in playlist_items\n",
"]))\n",
"\n",
"MyFile=open(\"C:/Users/Adewo/OneDrive - University of Cincinnati/Independent_Study/Dr.Nelly/Accident Video/playlist.txt\",'w')\n",
"MyFile.writelines(urllists)\n",
"MyFile.close()"
],
"metadata": {
"id": "cF2uMpP-0cbx"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"https://youtube.com/playlist?list=PLDMvZ0Ys4CdFasdrRUqF4dSISgrb5iPkM"
],
"metadata": {
"id": "xn_oNqse06CS"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "0pEmi6CL06gf"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"language_info": {
"name": "python"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"gpuClass": "standard"
},
"nbformat": 4,
"nbformat_minor": 0
}
|