Created
June 15, 2025 22:30
-
-
Save kamack38/a52d355f2472093f6d9584eed351ddaf to your computer and use it in GitHub Desktop.
Print how many times did I see this actor
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
| #!/usr/bin/env python3 | |
| import requests | |
| import json | |
| from collections import defaultdict | |
| requests.packages.urllib3.util.connection.HAS_IPV6 = False | |
| # Configure API | |
| API_KEY = "" # Replace with your TMDB API key | |
| BASE_URL = "https://api.themoviedb.org/3/movie/" | |
| HEADERS = {"accept": "application/json", "Authorization": f"Bearer {API_KEY}"} | |
| actor_counts = defaultdict(int) | |
| actor_names = defaultdict(str) | |
| def process_movie(movie_id): | |
| try: | |
| response = requests.get(f"{BASE_URL}{movie_id}/credits", headers=HEADERS) | |
| response.raise_for_status() | |
| credits = response.json() | |
| if "cast" in credits: | |
| for actor in credits["cast"]: | |
| # Filter only acting roles | |
| if actor.get("known_for_department") == "Acting": | |
| actor_id = actor["id"] | |
| actor_counts[actor_id] += 1 | |
| actor_names[actor_id] = actor["name"] | |
| except requests.exceptions.HTTPError as err: | |
| print(f"Error processing movie {movie_id}: {err}") | |
| # Load the JSON file | |
| with open("showly_2025.06.15.json", "r") as file: | |
| data = json.load(file) | |
| # Extract movie IDs (assuming 'movie_id' is the key) | |
| movie_ids = [obj["tmId"] for obj in data["movies"]["cH"] if "tmId" in obj] | |
| # print(movie_ids) | |
| # Example usage with movie IDs | |
| # movie_ids = [550, 155, 680] # Replace with your list of movie IDs | |
| for movie_id in movie_ids: | |
| process_movie(movie_id) | |
| # Print results sorted by frequency | |
| for actor_id, count in sorted(actor_counts.items(), key=lambda x: x[1], reverse=True): | |
| print(f"Actor: {actor_names[actor_id]} - Appearances: {count}") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works with a showly export. But it isn't that great because it counts voice actors in cartoons (you can't see them).