def Youtube_Scrape(api_key, vid):
    """
	Scrape metadata details of the video.
	"""
    yt = YoutubeDataApi(api_key)
    TomScott = yt.get_video_metadata(vid)
    return TomScott
Example #2
0
async def yt(ctx, *, query):
    yt = YoutubeDataApi(ytid)
    searches = yt.search(str(query), max_results=3)
    result = yt.get_video_metadata(
        searches[0]["video_id"],
        part=['id', 'snippet', 'contentDetails', 'statistics'])
    searches.clear()
    del yt
    url = 'https://www.youtube.com/watch?v=' + result["video_id"]
    desc = result["video_description"].split('\n')[0]
    if len(desc) > 300:
        desc = desc[:300] + "..."
    embed = discord.Embed(colour=0xff0000,
                          title=result["video_title"],
                          description=desc,
                          url=url)
    embed.set_author(name=result["channel_title"])
    embed.set_thumbnail(url=result["video_thumbnail"])
    embed.add_field(name="Views",
                    value=str(result["video_view_count"]),
                    inline=True)
    embed.add_field(name="Comments",
                    value=str(result["video_comment_count"]),
                    inline=True)
    embed.add_field(name="Duration",
                    value=str(result["duration"])[2:-1].replace("M",
                                                                ":").replace(
                                                                    "H", ":"),
                    inline=True)
    embed.add_field(name="Likes",
                    value=str(result["video_like_count"]),
                    inline=True)
    embed.add_field(name="Dislikes",
                    value=str(result["video_dislike_count"]),
                    inline=True)
    embed.set_footer(text=datetime.utcfromtimestamp(
        int(result["video_publish_date"])).strftime('%Y-%m-%d %H:%M:%S'))
    await ctx.send(embed=embed)
Example #3
0
from youtube_api import YoutubeDataApi
import pandas as pd
from utils import API_KEY
from utils import video_metadata_dict
from utils import tags

youtube = YoutubeDataApi(key=API_KEY)
for tag in tags:
    try:
        videos_df = pd.read_csv('data/{}/videos.csv'.format(tag))
    except Exception:
        print('Video file doesn\'t exist for tag {}'.format(tag))
        continue
    videos = videos_df.values.tolist()
    metas = []
    for video in videos:
        metadata = youtube.get_video_metadata(video[0])
        metadata = video_metadata_dict(metadata, video)
        metas.append(metadata)

    video_df = pd.DataFrame(metas)
    video_df.to_csv('data/{}/videos.csv'.format(tag), index=False)