|
|
from tqdm import tqdm |
|
|
from itertools import islice |
|
|
from youtube_comment_downloader import * |
|
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline |
|
|
|
|
|
import matplotlib.pyplot as plt |
|
|
import csv |
|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import base64 |
|
|
|
|
|
st.title("Youtube Comment Downloader") |
|
|
|
|
|
|
|
|
video_url = st.text_input("Masukkan URL video YouTube:") |
|
|
|
|
|
|
|
|
num_comments = st.number_input("Jumlah komentar yang ingin diambil:", min_value=1, value=10) |
|
|
|
|
|
if st.button("Ambil Data Komentar"): |
|
|
|
|
|
downloader = YoutubeCommentDownloader() |
|
|
|
|
|
|
|
|
comments = downloader.get_comments_from_url(video_url, sort_by=SORT_BY_POPULAR) |
|
|
|
|
|
|
|
|
with open('comments.csv', mode='w', encoding='utf-8', newline='') as file: |
|
|
|
|
|
writer = csv.DictWriter(file, fieldnames=['cid', 'text', 'time', 'author', 'channel', 'votes', 'photo', 'heart', 'reply']) |
|
|
|
|
|
|
|
|
writer.writeheader() |
|
|
|
|
|
|
|
|
for comment in tqdm(islice(comments, num_comments)): |
|
|
|
|
|
comment.pop('time_parsed', None) |
|
|
writer.writerow(comment) |
|
|
|
|
|
st.success(f"Komentar berhasil diunduh dan disimpan dalam file 'comments.csv'") |
|
|
|
|
|
|
|
|
comments_df = pd.read_csv('comments.csv') |
|
|
|
|
|
|
|
|
st.subheader("Data Komentar") |
|
|
st.table(comments_df) |
|
|
|
|
|
|
|
|
csv = comments_df.to_csv(index=False) |
|
|
b64 = base64.b64encode(csv.encode()).decode() |
|
|
href = f'<a style="background-color: #008CBA; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; font-weight: bold;" href="data:file/csv;base64,{b64}" download="comments.csv">Download File CSV</a>' |
|
|
st.markdown(href, unsafe_allow_html=True) |