From 9234a02a48f57167b2a0c3f5ed0ebea2e71ee7f5 Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sun, 7 Jan 2024 23:47:54 +0100 Subject: [PATCH] add film processing script --- scripts/4i8O | 1454 ++++++++++++++++++++++++++++++++++ scripts/process_film_logs.py | 129 +++ 2 files changed, 1583 insertions(+) create mode 100644 scripts/4i8O create mode 100644 scripts/process_film_logs.py diff --git a/scripts/4i8O b/scripts/4i8O new file mode 100644 index 0000000..a9dcb3f --- /dev/null +++ b/scripts/4i8O @@ -0,0 +1,1454 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ‎The Battle of Chile: Part I (1975) directed by Patricio Guzmán • Reviews, film + cast • Letterboxd + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +
+ +
+ +
The Battle of Chile: Part I
+ + +
+ + + + + + + + + + + + +
+ +
+
+

Where to watch

+ + + + +
+
+
+   + JustWatch +
+
+
+ +
+ + + + + + + +
+ +
+ + +
+ +
+ + + +
+ + + +
+

The chronicle of the political tension in Chile in 1973 and of the violent counter revolution against the democratically elected government of Salvador Allende.

+
+ +
+ + + + + +
+ + + + + + +
+
+ +
+ +
+ + +
+ + +
+ +

+ Director + +

+ + +

+ Assistant Director + +

+
+

+ Jose Bartolome +

+
+ +

+ Writers + +

+ + +

+ Editor + +

+
+

+ Pedro Chaskel +

+
+ +

+ Cinematography + +

+ + +

+ Sound + +

+
+

+ Bernardo Menz +

+
+ +
+ + +
+ +

Studio

+ + + +

Countries

+ + + + + +

Language

+
+

+ Spanish +

+
+ + + +

Alternative Titles

+
+

+ La batalla de Chile. Parte 1, La insurrección de la burguesía, La batalla de Chile: La lucha de un pueblo sin armas - Primera parte: La insurrección de la burguesía, La batalla de Chile: La lucha de un pueblo sin armas - Primera parte, La batalla de Chile: La insurrección de la burguesía, The Battle of Chile - Part I, The Insurrection of the Bourgeoisie, La bataille du Chili, Partie 1 : L'insurrection de la bourgeoisie, Der Kampf um Chile: Der Aufstand der Bourgeoisie, Der Kampf um Chile (Teil 1/3): Der Aufstand der Bourgeoisie, 칠레 전투 제1부: 부르주아지의 봉기, A Batalha do Chile - Primeira Parte: A Insurreição da Burguesia, Битва за Чили: Часть первая, 智利之战1 +

+
+ +
+ + +
+ +

Genres

+ + + +
+ + +
+
+
+

Releases by Date

+ +
+ Sort by +
+ + +
+
+
+ + +

Theatrical

+ +
+ +
+
+
18 Mar 1975
+
+
+
    + +
  • + + + + + + + + + Flag for Cuba + + + Cuba + + + + +
  • + +
+
+
+ +
+
+
12 Jan 1978
+
+
+
    + +
  • + + + + + + + + + Flag for the USA + + + USA + + + + +
  • + +
+
+
+ +
+ +

TV

+ +
+ +
+
+
10 Sep 2021
+
+
+
    + +
  • + + + + + + + + + Flag for Chile + + + Chile + + + + +
  • + +
+
+
+ +
+ +
+
+ + +
+
+
+

Releases by Country

+ +
+ Sort by +
+ +
    +
  • Date
  • +
  • Country
  • +
+
+
+
+ +
+ +
+
+ + + + +
+
+ + +
+
+
10 Sep 2021
+ +
    + + + +
  • + TV + + La Red +
  • +
+
+
+ + + +
+
+ +
+
+ + + + +
+
+ + +
+
+
18 Mar 1975
+ +
    + + + +
  • + Theatrical + + +
  • +
+
+
+ + + +
+
+ +
+
+ + + + +
+
+ + +
+
+
12 Jan 1978
+ +
    + + + +
  • + Theatrical + + +
  • +
+
+
+ + + +
+
+ +
+
+
+ +
+ + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + +
+ +
+ +
+ + + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/process_film_logs.py b/scripts/process_film_logs.py new file mode 100644 index 0000000..f0c3c8b --- /dev/null +++ b/scripts/process_film_logs.py @@ -0,0 +1,129 @@ +import json +import logging +import requests +import time +from urllib.request import urlopen + +def process_items(items): + logging.info("Processing items…") + + for i, item in enumerate(items): + item_values = { + 'date_added': item['Date Added'], + 'date_watched': item['Date Watched'] + } + if 'Rewatch' in item: item_values['is_rewatch'] = item['Rewatch'] + if 'Comments' in item: item_values['comments'] = item['Comments'] + + if 'IMDB ID' in item: + items[i] = populate_from_id(item) + else: + items[i] = populate_from_details(item) + + items[i] |= item_values + + with open("../data/films/log.json", "w") as films_log: + json.dump(items, films_log, indent=4) + + logging.info("Finished processing items") + + +def populate_from_details(item): + logging.info(f"Processing {item['Title']}…") + + api_url = f"https://api.themoviedb.org/3/search/movie" + + # Sending API request + response = requests.get( + api_url, + params={ + 'query': item['Title'], + 'include_adult': True, + 'year': item['Release Year'] + }, + headers={'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1NWQ2ZjY3YzJlOTQwMDI1NTFmN2VkNmEyZWVjM2E3NyIsInN1YiI6IjUxNWMyNzkxMTljMjk1MTQ0ZDAzZDM0NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.92eNKubJ_CORCIIlta30P9Qjg_Q9gPRFDTfG4gyz9kY'} + ) + + # Process the response + if (200 == response.status_code): + logging.info(response.status_code) + elif (429 == response.status_code): + time.sleep(2) + populate_from_details(item) + else: + logging.error(response.text) + + response_data = json.loads(response.text) + + if len(response_data['results']) > 1: + response_data['results'] = [film for film in response_data['results'] if film['title'] == item['Title']] + if len(response_data['results']) > 1: + logging.warning(f"Returned more than one film for {item['Title']}") + return item + + if len(response_data['results']) > 0: + film = response_data['results'][0] + return cleanup_film(film) + else: + logging.warning(f"Returning no results for {item['Title']}") + return item + + +def populate_from_id(item): + logging.info(f"Processing ID {item['IMDB ID']} ({item['Title']})…") + + api_url = f"https://api.themoviedb.org/3/find/{item['IMDB ID']}" + + # Sending API request + response = requests.get( + api_url, + params={ + 'external_source': 'imdb_id' + }, + headers={'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1NWQ2ZjY3YzJlOTQwMDI1NTFmN2VkNmEyZWVjM2E3NyIsInN1YiI6IjUxNWMyNzkxMTljMjk1MTQ0ZDAzZDM0NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.92eNKubJ_CORCIIlta30P9Qjg_Q9gPRFDTfG4gyz9kY'} + ) + + # Process the response + if (200 == response.status_code): + logging.info(response.status_code) + elif (429 == response.status_code): + time.sleep(2) + populate_from_id(item) + else: + logging.error(response.text) + + response_data = json.loads(response.text) + if len(response_data['movie_results']) > 1: + logging.warning(f"Returned more than one film for ID {item['IMDB ID']}") + return item + + if len(response_data['movie_results']) > 0: + film = response_data['movie_results'][0] + return cleanup_film(film) + else: + logging.warning(f"Returning no results for {item['Title']}") + return item + + return cleanup_film(film) + + +def cleanup_film(film): + del film['adult'], film['backdrop_path'], film['genre_ids'], film['popularity'], film['video'], film['vote_average'], film['vote_count'] + + if 'media_type' in film: del film['media_type'] + + if film['original_title'] == film['title'] and film['original_language'] == 'en': + del film['original_title'], film['original_language'] + + film['poster_path'] = f"https://www.themoviedb.org/t/p/original/{film['poster_path']}" + + return film + + +logging.basicConfig(filename='run.log', encoding='utf-8', level=logging.DEBUG) + +with open("../data/films/log.json", "r") as films_log: + films = json.load(films_log) + +process_items(films) +