# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Get the Data

# *To get the data, we'll use a library called **youtube_dlc**, this library get for us the videos and some information about them.*

# +
# import libraries

import pandas as pd
import numpy as np
import json, re, time
import youtube_dlc
# -

# We need to initialize the object
ydl = youtube_dlc.YoutubeDL({"ignoreerrors" : True}) # this argument set to true ignore possibles video that can't be downloaded

# +
# we'll be using some keywords for the video recommender
queries = [ "machine+learning", "kaggle", "deep+learning"]

resultados = []
for query in queries:
    r = ydl.extract_info(f'ytsearchdate300:{query}', download = False) # The first argument implies in get the information 
                                                                       # 300 videos for each query
    for entry in r['entries']:
        if entry is not None:
            entry['query'] = query
        resultados += r['entries']
            
# -

len(resultados)

resultados = [e for e in resultados if e is not None] # Retira os exemplos que deram algum erro para baixar

print(f'Quantidade de Exemplos: {len(resultados)}')

df = pd.DataFrame(resultados)
pd.set_option("display.max_columns", 66)
df.head()

colunas = ['title', 'upload_date', 'view_count', 'query'] # colunas que iremos utilizar para treinar o modelo

df[colunas].to_csv("raw_data1.csv")  # salva os dados



StarcoderdataJupyterScriptsDedupFiltered