home chevron_right src chevron_right tempatnonton.js
code

tempatnonton.js

JavaScript 14 KB 641 baris visibility 6 views
open_in_new
src/tempatnonton.js
async function searchMovie(keyword) {
  const axios = (await import("axios")).default

  try {
    const nonce = "d8a40860a6"

    const { data, headers, status } = await axios({
      method: "GET",
      url: "https://tempatnonton.online/wp-json/dooplay/search/",
      params: {
        keyword,
        nonce
      },
      headers: {
        Accept: "application/json, text/javascript, */*; q=0.01",
        "X-Requested-With": "XMLHttpRequest",
        Referer: "https://tempatnonton.online/",
        Origin: "https://tempatnonton.online",
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
      },
      timeout: 30000
    })

    const result = Object.values(data).map(item => ({
      title: item.title,
      url: item.url,
      genre: item.kat,
      thumbnail: item.img,
      year: item.extra?.date || null,
      imdb: item.extra?.imdb || null
    }))

    return {
      status: true,
      code: status,
      headers,
      total: result.length,
      result
    }
  } catch (e) {
    return {
      status: false,
      code: e.response?.status || 500,
      error: e.message,
      data: e.response?.data || null
    }
  }
}

return await searchMovie("Cars")


async function movieDetail(slug) {
  const axios = (await import("axios")).default
  const cheerio = await import("cheerio")

  try {
    const BASE_URL = "https://tempatnonton.online"

    const { data, status, headers } = await axios({
      method: "GET",
      url: `${BASE_URL}/${slug}/`,
      headers: {
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
        Accept:
          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Language": "id-ID,id;q=0.9,en-US;q=0.8",
        Referer: BASE_URL
      },
      timeout: 30000
    })

    const $ = cheerio.load(data)

    const titleRaw = $('h3[itemprop="name"]').first().text().trim()

    const year =
      titleRaw.match(/\((\d{4})\)/)?.[1] || null

    const title = titleRaw.replace(/\s*\(\d{4}\)\s*$/, "")

    const poster =
      ($(".thumb.mvic-thumb")
        .attr("style")
        ?.match(/url\((.*?)\)/)?.[1] || "")
        .replace(/['"]/g, "")

    const backdrop =
      ($(".thumb.mvi-cover")
        .attr("style")
        ?.match(/url\((.*?)\)/)?.[1] || "")
        .replace(/['"]/g, "")

    const overview =
      $(".desc p").text().trim() ||
      $('.desc span[itemprop="reviewBody"]')
        .text()
        .trim()

    const rating =
      parseFloat($(".irank .irank-voters").text()) ||
      0

    const votes =
      parseInt(
        $(".irank")
          .text()
          .replace(/[^\d]/g, "")
      ) || 0

    const runtime =
      parseInt(
        $(".mvici-right")
          .text()
          .match(/(\d+)\s*Min/i)?.[1]
      ) || 0

    const quality =
      $(".quality a").first().text().trim() ||
      "HD"

    const releaseDate =
      $(".mvici-right")
        .text()
        .match(/Release Date:\s*([^\n]+)/i)?.[1]
        ?.trim() || null

    const genres = []

    $('.mvici-left a[rel="tag"] span[itemprop="genre"]').each(
      (i, el) => {
        genres.push({
          id: i + 1,
          name: $(el).text().trim()
        })
      }
    )

    const actors = []

    $('.mvici-left span[itemprop="actor"] a').each(
      (_, el) => {
        actors.push({
          name: $(el).text().trim(),
          url: $(el).attr("href")
        })
      }
    )

    const directors = []

    $('.mvici-left span[itemprop="director"] a').each(
      (_, el) => {
        directors.push({
          name: $(el).text().trim(),
          url: $(el).attr("href")
        })
      }
    )

    const countries = []

    $('.mvici-right a[rel="tag"]').each(
      (_, el) => {
        const text = $(el).text().trim()

        if (text) countries.push(text)
      }
    )

    const trailer =
      $("#iframe-trailer").attr("src") || null

    const playUrl =
      $('a[href$="/play"]').attr("href") || null

    const id =
      parseInt(
        $('link[rel="shortlink"]')
          .attr("href")
          ?.match(/\?p=(\d+)/)?.[1]
      ) || null

    return {
      status: true,
      code: status,
      headers,
      result: {
        id,
        slug,
        title,
        originalTitle: title,
        year,
        releaseDate,
        runtime,
        quality,
        rating,
        votes,
        overview,
        language: "English",
        poster,
        backdrop,
        trailer,
        playUrl,
        genres,
        actors,
        directors,
        countries,
        url: `${BASE_URL}/${slug}/`
      }
    }
  } catch (e) {
    return {
      status: false,
      code: e.response?.status || 500,
      error: e.message,
      data: e.response?.data || null
    }
  }
}

return await movieDetail("cars-2-2011")


async function searchMovie(query, page = 1) {
  const axios = (await import("axios")).default
  const cheerio = await import("cheerio")

  try {
    const BASE_URL = "https://tempatnonton.online"

    const { data, status, headers } = await axios({
      method: "GET",
      url: `${BASE_URL}/`,
      params: {
        s: query,
        paged: page
      },
      headers: {
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
        Accept:
          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Language":
          "id-ID,id;q=0.9,en-US;q=0.8",
        Referer: BASE_URL
      },
      timeout: 30000
    })

    const $ = cheerio.load(data)

    const result = []

    $(".movies-list .ml-item, .items .item").each(
      (_, el) => {
        const title =
          $(el)
            .find(".mli-info h2, .data h3")
            .first()
            .text()
            .trim()

        const url =
          $(el).find("a").first().attr("href") ||
          null

        const slug = url
          ? url
              .replace(BASE_URL, "")
              .replace(/\//g, "")
          : null

        let poster =
          $(el)
            .find("img")
            .first()
            .attr("src") ||
          $(el)
            .find("img")
            .first()
            .attr("data-src") ||
          ""

        if (
          poster &&
          poster.startsWith("//")
        ) {
          poster = "https:" + poster
        }

        const quality =
          $(el)
            .find(".mli-quality,.quality")
            .first()
            .text()
            .trim() || null

        const rating =
          $(el)
            .find(".mli-rating,.rating")
            .first()
            .text()
            .trim() || null

        const year =
          $(el)
            .find(".mli-year,.year")
            .first()
            .text()
            .trim() || null

        if (title) {
          result.push({
            title,
            slug,
            url,
            poster,
            quality,
            rating,
            year
          })
        }
      }
    )

    return {
      status: true,
      code: status,
      headers,
      query,
      page: Number(page),
      total: result.length,
      result
    }
  } catch (e) {
    return {
      status: false,
      code: e.response?.status || 500,
      error: e.message,
      data: e.response?.data || null
    }
  }
}

return await searchMovie("cars")


async function popularMovie() {
  const axios = (await import("axios")).default
  const cheerio = await import("cheerio")

  try {
    const BASE_URL = "https://tempatnonton.online"

    const { data, status, headers } = await axios.get(BASE_URL, {
      headers: {
        "User-Agent": "Mozilla/5.0",
        "Accept-Language": "id-ID,id;q=0.9,en-US;q=0.8"
      },
      timeout: 30000
    })

    const $ = cheerio.load(data)

    const result = []

    $("article, .item, .items .item, .ml-item").each((_, el) => {
      const a = $(el).find("a").first()

      const url = a.attr("href") || null
      if (!url) return

      const slug = url
        .replace(BASE_URL, "")
        .replace(/^\/|\/$/g, "")

      const title =
        $(el).find("h2,h3,.data h3,.entry-title").first().text().trim() ||
        a.attr("title") ||
        null

      let poster =
        $(el).find("img").attr("data-src") ||
        $(el).find("img").attr("src") ||
        null

      if (poster?.startsWith("//")) poster = "https:" + poster
      if (poster?.startsWith("/")) poster = BASE_URL + poster

      const quality =
        $(el).find(".quality,.mli-quality").text().trim() || null

      const rating =
        $(el).find(".rating,.mli-rating,.imdb").text().trim() || null

      const duration =
        $(el).find(".runtime,.duration,.mli-durasi").text().trim() || null

      let year =
        $(el).find(".year,.mli-year").text().trim() || null

      if (!year && title) {
        const match = title.match(/\((\d{4})\)/)
        if (match) year = match[1]
      }

      result.push({
        title,
        slug,
        url,
        poster,
        quality,
        rating,
        duration,
        year
      })
    })

    return {
      status: true,
      code: status,
      total: result.length,
      result
    }

  } catch (e) {
    return {
      status: false,
      code: e.response?.status || 500,
      error: e.message,
      data: e.response?.data || null
    }
  }
}

return await popularMovie()


async function searchMovie(query) {
  const axios = (await import("axios")).default

  try {
    const BASE_URL = "https://tempatnonton.online"

    const { data, status, headers } = await axios.get(
      `${BASE_URL}/wp-json/dooplay/search/`,
      {
        params: {
          keyword: query,
          nonce: "d8a40860a6"
        },
        headers: {
          "User-Agent": "Mozilla/5.0",
          Accept: "application/json, text/javascript, */*; q=0.01",
          "X-Requested-With": "XMLHttpRequest",
          Referer: BASE_URL
        },
        timeout: 30000
      }
    )

    const result = Object.entries(data).map(([id, movie]) => ({
      id: Number(id),
      title: movie.title,
      slug: movie.url
        .replace(BASE_URL, "")
        .replace(/^\/|\/$/g, ""),
      url: movie.url,
      poster: movie.img,
      genres: movie.kat
        ? movie.kat.split(",").map(v => v.trim())
        : [],
      year: movie.extra?.date || null,
      imdb: movie.extra?.imdb || null
    }))

    return {
      status: true,
      code: status,
      total: result.length,
      result
    }

  } catch (e) {
    return {
      status: false,
      code: e.response?.status || 500,
      error: e.message,
      data: e.response?.data || null
    }
  }
}

return await searchMovie("Cars")


async function movieDetail(slug) {
  const axios = (await import("axios")).default
  const cheerio = await import("cheerio")

  const BASE_URL = "https://tempatnonton.online"

  try {
    const headers = {
      "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
      Referer: BASE_URL
    }

    const [{ data: html }, { data: playHtml }] = await Promise.all([
      axios.get(`${BASE_URL}/${slug}/`, { headers }),
      axios.get(`${BASE_URL}/${slug}/play/`, { headers })
    ])

    const $ = cheerio.load(html)
    const $$ = cheerio.load(playHtml)

    const title =
      $("h3[itemprop='name']").text().trim() ||
      $(".mvic-tagline2 h3").text().trim() ||
      $("title").text().replace(" | Tempat Nonton", "").trim()

    const releaseDate =
      $("meta[itemprop='datePublished']").attr("content") ||
      $("meta[property='video:release_date']").attr("content") ||
      null

    let year = null

    const yearMatch = title.match(/\((\d{4})\)/)

    if (yearMatch) {
      year = yearMatch[1]
    } else if (releaseDate) {
      year = releaseDate.substring(0, 4)
    }

    const overview =
      $(".desc p").text().trim() ||
      $("meta[property='og:description']").attr("content") ||
      null

    let poster =
      $(".thumb.mvic-thumb")
        .attr("style")
        ?.match(/url\(['"]?(.*?)['"]?\)/)?.[1] ||
      $("meta[property='og:image']").attr("content") ||
      null

    if (poster && poster.startsWith("//")) {
      poster = "https:" + poster
    }

    const genres = []

    $(".mvici-left p").each((_, el) => {
      const label = $(el).find("strong").text().trim().toLowerCase()

      if (label.includes("genre")) {
        $(el)
          .find("a[rel='tag']")
          .each((_, a) => {
            const name = $(a).text().trim()
            if (name) genres.push(name)
          })
      }
    })

    if (!genres.length) {
      $(".mv-stat a[rel='tag']").each((_, el) => {
        const txt = $(el).text().trim()

        if (
          txt &&
          txt.length < 20 &&
          !genres.includes(txt)
        ) {
          genres.push(txt)
        }
      })
    }

    const iframe =
      $$("#iframe-embed").attr("src") ||
      $$("iframe").attr("src") ||
      null

    const servers = []

    $$(".server").each((i, el) => {
      const server = $$(el)

      const onclick = server.attr("onclick") || ""

      const url =
        onclick.match(/src='([^']+)'/) ||
        onclick.match(/src="([^"]+)"/)

      servers.push({
        name:
          server.find(".server-title").text().trim() ||
          `Server ${i + 1}`,
        type: server.data("type") || null,
        index: String(server.data("idx") || i),
        url: url ? url[1] : null
      })
    })

    return {
      status: true,
      result: {
        title: title.replace(/\(\d{4}\)/, "").trim(),
        year,
        releaseDate,
        overview,
        poster,
        genres,
        slug,
        url: `${BASE_URL}/${slug}/`,
        playUrl: `${BASE_URL}/${slug}/play/`,
        video: {
          iframe,
          active: servers[0] || null,
          servers
        }
      }
    }
  } catch (e) {
    return {
      status: false,
      code: e.response?.status || 500,
      error: e.message,
      data: e.response?.data || null
    }
  }
}

return await movieDetail("cars-2-2011")
link

Direct URL

check Disalin!