Why Instagram “shortcode_media” is undefined?

I was trying to use a library to download videos from instagram, and it uses graphql, but it only downloads videos every now and then, other times it returns an error. The error:

TypeError: Cannot read properties of undefined (reading 'shortcode_media')

The code:

    async function downloadMetaData(url) {
      try {
        const metaData = await axios({
          method: "get",
          url: url,
        });
        return metaData.data.graphql;
      } catch (error) {
        throw error;
      }
    }
    
    function getMediaType(mediaData) {
      if (mediaData.shortcode_media.is_video === true) {
        return "video";
      }
      return "image";
    }

The link of library (if you need local tests)

Could anyone give me a suggestion on how to solve it or recommend another lib?