!pip install youtube-data-api
Collecting youtube-data-api
Downloading youtube_data_api-0.0.20-py3-none-any.whl (12 kB)
Requirement already satisfied: requests in /shared-libs/python3.7/py/lib/python3.7/site-packages (from youtube-data-api) (2.25.1)
Requirement already satisfied: pandas in /shared-libs/python3.7/py/lib/python3.7/site-packages (from youtube-data-api) (1.2.2)
Requirement already satisfied: certifi>=2017.4.17 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->youtube-data-api) (2020.12.5)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->youtube-data-api) (1.26.3)
Requirement already satisfied: chardet<5,>=3.0.2 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->youtube-data-api) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->youtube-data-api) (2.10)
Requirement already satisfied: pytz>=2017.3 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas->youtube-data-api) (2020.5)
Requirement already satisfied: python-dateutil>=2.7.3 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from pandas->youtube-data-api) (2.8.1)
Requirement already satisfied: numpy>=1.16.5 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas->youtube-data-api) (1.19.5)
Requirement already satisfied: six>=1.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas->youtube-data-api) (1.15.0)
Installing collected packages: youtube-data-api
Successfully installed youtube-data-api-0.0.20
WARNING: You are using pip version 20.1.1; however, version 21.0.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
from youtube_api import YouTubeDataAPI
from youtube_api import parsers
api_key = "сюда ваш ключ"
yt = YouTubeDataAPI(api_key)
t_channel=yt.get_channel_id_from_user('Davidich D3')
print(t_channel)
None
yt.search(q='Davidich D3', max_results=5, order_by='relevance')
channel_id='UCv2hYhRYO8Fmbs5mUemz2oQ'
yt.get_playlists(channel_id=channel_id)
all_videos=yt.get_videos_from_playlist_id('PLyzrNBf9KMdqsCU_zO-0QYW5Qgg_LXUhB')
import pandas as pd
df=pd.read_json('d3.json')
df
df['published_date']=pd.to_datetime(df['publish_date'],unit='s')
df
df.index=df.published_date
df['day_of_week']=df['published_date'].dt.weekday
df['published_hour'] = df['published_date'].dt.hour
df['publish_minutes'] = df['published_date'].dt.minute
df['published_month'] = df['published_date'].dt.month
df
df
df.published_month.value_counts().plot.bar()
df.published_hour.value_counts().plot.bar()
df.day_of_week.value_counts().plot.bar()
yt.get_video_metadata('ycmfeA0a1jo')
comments=yt.get_video_comments('ycmfeA0a1jo')
df.to_json('d3.json')
len(comments)
df2=pd.DataFrame(comments)
df2
df2.commenter_channel_display_name.value_counts()
df2[df2['commenter_channel_display_name'] == 'Виталий Власенко']
df2[df2['commenter_channel_display_name'] == 'Max Vellini']
df2[df2['commenter_channel_display_name'] == 'ULTRA FASS']
df2[df2['commenter_channel_display_name'] == 'ULTRA FASS']
df2['text_len']=df2.text.apply(lambda x: len(x))
df2['text_len'].mean()
df2[df2['text_len'] > 1200]
df2.text_len.plot()
text=df2.text
bigrams = [b for l in text for b in zip(l.split(" ")[:-1], l.split(" ")[1:])]
unigram=[z.lower() for items in text for z in items.split(' ')]
len(unigram2)
len(bigrams)
from collections import Counter
Counter(unigram).most_common(100)