S
S
Shura01022021-06-15 09:12:51
API
Shura0102, 2021-06-15 09:12:51

How to take info by id from movie search?

Hello! I take information about the film from the film search for such a request

function get_kinopoisk_data() {
let kinopoisk_id = document.getElementById("glink").value;
let xhr = new XMLHttpRequest();
xhr.open('GET', `https://kinopoiskapiunofficial.tech/api/v2.1/films...`, false);
xhr.setRequestHeader('X-API-KEY', '05e15730-5d36-4a7b-9cb8-1a9034ed276c');
xhr.send();
fill_other_fields(JSON.parse(xhr.responseText));
}

function fill_other_fields(response) {
console.log(response);
document.getElementById("sfF1 title").value = response.data.nameRu ?? "";
document.getElementById("brief").value = response.data.description ?? "";
document.getElementById("sfF6").value = response.data.ratingAgeLimits ?? "";
document.getElementById("slogan").value = response.data.slogan ?? "";
document.getElementById("sfF13").value = response.data.filmLength ?? "";
document.getElementById("sfF150").value = response.data.nameEn ?? "";
document.getElementById("sfF14").value = response.data.actors ?? "";
document.getElementById("sfF15").value = response.data.budget ?? "";
document.getElementById("sfF8").value = response.data.seasons.length ?? "";
document.getElementById("message").value = response.data.facts ?? "";
document.getElementById("sfF7").value = response.data.premiereRu ?? "";
document.getElementById("distributors").value = response.data.distributors ?? "";
document.getElementById("input_extrafl10").value = response.data.premiereWorld ?? "";
document.getElementById("input_extrafl8").value = response.data.posterUrl ?? "";
document.getElementById("input_extrafl9").value = response.data.posterUrlPreview ?? "";
document.getElementsByClassName("manFlFlt1").value = response.data.country;
let year_options = Array.from(document.querySelectorAll('.manFlFlt1 option'));
year_options.find(c => c.text == response.data.year).selected = true;


, but it is not possible to get a list of actors, director and number of episodes. Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2021-06-16
@xotkot

but it is not possible to get a list of actors, director and number of episodes. Tell me what am I doing wrong?
firstly, indicate the language used in the tags to the question, secondly, duplicating your question (already the third one) is a bad tone and is usually punished by moderators, thirdly, all the necessary information can be found in the documentation
for the sake of interest, I made myself a script to output information to the console
, maybe someone else will fit
#!/usr/bin/env bash
set -o errexit

BASE_URL="https://kinopoiskapiunofficial.tech/api"
API_KEY="05e15730-5d36-4a7b-9cb8-1a9034ed276c"
KEYWORD=$(echo "[email protected]" | jq -Rr '@uri')

# получаем список фильмов по ключевому слову
get_keyword=$(curl -s -X GET "$BASE_URL/v2.1/films/search-by-keyword?keyword=$KEYWORD&page=1" -H "accept: application/json" -H "X-API-KEY: $API_KEY")

# запоминаем id выбранного фильма
FilmID=$(echo "$get_keyword" | jq -r '.films[] | "\(.filmId);\(.year);\(.nameRu);\(.nameEn)"' | column -t -s';' | sk | awk '{print $1}')
 && exit


# получаем данные о фильме по его id
get_film_data=$(curl -s	-X GET "$BASE_URL/v2.1/films/$FilmID" -H "accept: application/json" -H "X-API-KEY: $API_KEY")

echo
echo "$get_film_data" | jq -r '.data | "\t*** \(.nameRu) (\(.year)) ***"'
echo "$get_film_data" | jq -r '.data | "\t    [ \(.nameEn) ]"'
echo
echo
echo "             О фильме"
echo =====================================================
x="Год производства;"$(echo "$get_film_data" | jq -r '.data.year')
x=$x"\nСтрана;"$(      echo "$get_film_data" | jq -r '.data.countries[].country' | sed -z 's/\n/, /g' | sed 's/..$//')
x=$x"\nЖанр;"$(        echo "$get_film_data" | jq -r '.data.genres[].genre' | sed -z 's/\n/, /g' | sed 's/..$//')
x=$x"\nВремя;"$(       echo "$get_film_data" | jq -r '.data.filmLength' | awk -F: '{print $1*60+$2" минут / "$0}')
echo -e "$x" | column -t -s';'
echo
echo
echo


echo "             Описание"
echo =====================================================
echo "$get_film_data" | jq -r '.data.description' | par -w 60d
echo
echo
echo


echo "             Эпизоды"
echo =====================================================
echo "$get_film_data" | jq -r '.data.seasons[].episodes[] | "\(.seasonNumber);\(.episodeNumber);\(.nameRu);\(.nameEn)"' | column -t -s';'
echo
echo
echo


# получаем информацию о людях работавших над фильмом
get_staff=$(curl -s	-X GET "$BASE_URL/v1/staff?filmId=$FilmID" -H "accept: application/json" -H "X-API-KEY: $API_KEY")


echo "             Над фильмом работали"
echo =====================================================
echo "$get_staff" | jq -r '.[] | "\(.professionText);\(.nameRu);\(.nameEn)"' | column -t -s';'
echo
echo
echo

exit

to run, you need to pass a keyword (phrase) to the script, by which information on matching films will be requested from the server, after which it will give a list in which we select the desired film with the keys (top, bottom).
When a movie is selected from the server, its id will be automatically requested and it will give out structured information on the movie, its description, episodes and actors
, in addition to bash, the curl, skim, jq, par utilities are needed to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question