adewopova commited on
Commit
ea87078
·
1 Parent(s): 6b9d36f

Created using Colaboratory

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