Last active
March 30, 2025 12:27
-
-
Save VarunBatraIT/a4a74d8352bf179aed5260e236a798c7 to your computer and use it in GitHub Desktop.
Youtube Money Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copied from https://www.reddit.com/user/secret_space_/ | |
# Updated to kind of see progress and seeing comments count as well. | |
import re | |
from collections import defaultdict | |
from youtube_comment_downloader import YoutubeCommentDownloader | |
downloader = YoutubeCommentDownloader() | |
video_url = "" | |
super_thanks_count = 0 | |
total_by_currency = defaultdict(float) | |
currency_amount_pattern = re.compile(r"([^\d\s]+)\s?([\d,]+(?:\.\d{1,2})?)") | |
def print_total_by_currency(): | |
for currency, total in total_by_currency.items(): | |
print(f" {currency} {total:,.2f}") | |
print("π Fetching all comments...\n") | |
for count, comment in enumerate(downloader.get_comments_from_url(video_url, sort_by=1), start=1): | |
if 'paid' in comment: | |
super_thanks_count += 1 | |
author = comment.get('author', 'Unknown') | |
text = comment.get('text', '') | |
paid = comment['paid'] | |
match = currency_amount_pattern.search(paid) | |
if match: | |
currency = match.group(1) | |
amount = float(match.group(2).replace(',', '')) | |
total_by_currency[currency] += amount | |
else: | |
currency = "Unknown" | |
amount = paid | |
print(f"{count:04d}. πΈ Super Thanks from @{author}") | |
print(f" Text: {text}") | |
print(f" Currency: {currency}") | |
print(f" Amount: {amount}\n") | |
print(f" Total in {currency}: {total_by_currency[currency]} from {count}\n") | |
print_total_by_currency(); | |
print("\nβ Done.") | |
print(f"π° Total Super Thanks found: {super_thanks_count}") | |
print("π Total Donation Breakdown by Currency:") | |
print_total_by_currency() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment