Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
Data Science
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Anurag Kumar
Data Science
Commits
5860c596
Commit
5860c596
authored
Nov 28, 2021
by
Anurag Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete Youtube_Api_data.ipynb
parent
13d4828f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
205 deletions
+0
-205
Youtube_Api_data.ipynb
Youtube_Api_data.ipynb
+0
-205
No files found.
Youtube_Api_data.ipynb
deleted
100644 → 0
View file @
13d4828f
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Youtube_Api_data.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "PBHEstklEjUq"
},
"source": [
"import requests\n",
"import pandas as pd\n",
"import time"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "hsSIBQbJFFzA"
},
"source": [
"API_KEY = \"AIzaSyCq9fWteOyROajADP4Ww2xSMa2p4TFAyUI\" # this is fake api key\n",
"Channel_Id = \"UCeVHRraqf7I68yt9dfsHx-l19T\" # this is fake channel id"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 269
},
"id": "bZGkPXgENd8h",
"outputId": "7259eac6-d1d8-4b25-9956-8c9037af58d4"
},
"source": [
"def getVideo_details(video_id):\n",
" url_stat = \"https://www.googleapis.com/youtube/v3/videos?id=\"+video_id+\"&part=statistics&key=\"+API_KEY\n",
" responce_stats = requests.get(url_stat).json()\n",
"\n",
" view_count = responce_stats['items'][0]['statistics']['viewCount']\n",
" comment_count = responce_stats['items'][0]['statistics']['commentCount']\n",
"\n",
" return view_count, comment_count\n",
"\n",
"\n",
"\n",
"\n",
"def getData(df): \n",
" pageToken = \"\"\n",
" url = \"https://www.googleapis.com/youtube/v3/search?key=\"+API_KEY+\"&channelId=\"+Channel_Id+\"&part=snippet,id&order=date&maxResults=1000\"+pageToken\n",
" responce = requests.get(url).json()\n",
"\n",
" responce['items'] = responce['items'][0:-1]\n",
" for video in responce['items']:\n",
" video_id = video['id']['videoId']\n",
" video_title = str(video['snippet']['title']).replace(\"&\",\"\")\n",
" upload_date = str(video['snippet']['publishedAt']).split(\"T\")[0]\n",
" \n",
" \n",
" view_count, comment_count = getVideo_details(video_id)\n",
" df = df.append({'video_id':video_id,\n",
" 'video_title':video_title,\n",
" 'upload_date':upload_date,\n",
" 'view_count':view_count,\n",
" 'comment_count':comment_count}, ignore_index=True)\n",
" \n",
" return df\n",
"\n",
"\n",
"\n",
"df = pd.DataFrame(columns=['video_id', 'video_title','upload_date','view_count','comment_count'])\n",
"df = getData(df)\n",
"df"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>video_id</th>\n",
" <th>video_title</th>\n",
" <th>upload_date</th>\n",
" <th>view_count</th>\n",
" <th>comment_count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3XJ3NOoeLf4</td>\n",
" <td>Piranha Movie Explained in Hindi | Piranha 201...</td>\n",
" <td>2021-09-05</td>\n",
" <td>29</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>BTW3dne0f3c</td>\n",
" <td>Mortal Kombat (2021) Film Explained in Hindi/U...</td>\n",
" <td>2021-09-03</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>mJ31LiGkj1E</td>\n",
" <td>Man of Steel (2013) Film Explained in Hindi/Ur...</td>\n",
" <td>2021-09-03</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>9wM_3tnLvnU</td>\n",
" <td>Life Like (2019) Film Explained in Hindi/Urdu ...</td>\n",
" <td>2021-09-03</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>sZkyTsZD2nM</td>\n",
" <td>Captain America The First Avenger Explained In...</td>\n",
" <td>2021-08-30</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>MRfjCVoQHds</td>\n",
" <td>Yummy (2019) Film Explained in Hindi/Urdu | Yu...</td>\n",
" <td>2021-08-29</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>hJuuymhiP14</td>\n",
" <td>The Cupid (2020) Film Explained in Hindi/Urdu ...</td>\n",
" <td>2021-08-26</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" video_id ... comment_count\n",
"0 3XJ3NOoeLf4 ... 0\n",
"1 BTW3dne0f3c ... 0\n",
"2 mJ31LiGkj1E ... 1\n",
"3 9wM_3tnLvnU ... 0\n",
"4 sZkyTsZD2nM ... 0\n",
"5 MRfjCVoQHds ... 0\n",
"6 hJuuymhiP14 ... 0\n",
"\n",
"[7 rows x 5 columns]"
]
},
"metadata": {},
"execution_count": 121
}
]
}
]
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment