File size: 1,052 Bytes
762fa11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import axios from "axios";
export const getTitle = async (imdbId, language) => {
    try {
        const data = (await axios.get(`https://www.imdb.com/title/${imdbId}`, {
            headers: {
                "Accept-Language": language,
                "Accept-Encoding": "gzip,deflate,compress",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
            },
        })).data;
        const title = data.match(/<title>(.*?)<\/title>/)[1];
        if (!title)
            return undefined;
        return title.split(" (")[0];
    }
    catch {
        return undefined;
    }
};
export const getTitles = async (imdbId) => {
    const titles = new Set();
    (await Promise.all([getTitle(imdbId), getTitle(imdbId, "en")])).forEach((title) => {
        if (title)
            titles.add(title);
    });
    return [...titles];
};
export const isImdbId = (str) => /ev\d{7}\/\d{4}(-\d)?|(ch|co|ev|nm|tt)\d{7}/.test(str);
//# sourceMappingURL=imdb.js.map