Skip to content

Instantly share code, notes, and snippets.

@VarunBatraIT
Last active March 30, 2025 12:27
Show Gist options
  • Save VarunBatraIT/a4a74d8352bf179aed5260e236a798c7 to your computer and use it in GitHub Desktop.
Save VarunBatraIT/a4a74d8352bf179aed5260e236a798c7 to your computer and use it in GitHub Desktop.
Youtube Money Calculator
# 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