<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>9Streams.xyz - Homepage: Find something to watch!</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
  <script src="/apis/dtd.js"></script>
    <script type='text/javascript' src='//spokentomatoestraumatic.com/29/44/32/294432dcc07bb2f46fa506e1e78d45e4.js'></script>

<script>
    const headerScript = document.createElement("script");
    headerScript.src = "https://9streams.xyz/config/sidenav.js";
    headerScript.async = true;
    headerScript.onload = function() {
        console.log("Header script has been loaded and executed.");
    };
    document.head.appendChild(headerScript);
</script>

<link rel="icon" type="image/x-icon" href="https://9streams.xyz/9streams_logo.png">
  <style>
    /* General Styles */
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      font-family: 'Roboto', sans-serif;
    }
    body {
      background-color: #121212;
      color: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .container {
      width: 100%;
      max-width: 1500px; /* Increase max-width for more space on PC */
      padding: 20px;
    }

    /* Spotlight Section */
    .spotlight {
      position: relative;
      width: 100%;
      height: 400px;
      background-size: cover;
      background-position: center;
      border-radius: 10px;
      display: flex;
      align-items: flex-end;
      padding: 20px;
      color: #fff;
      margin-bottom: 30px;
      overflow: hidden;
      transition: background-image 1s ease-in-out;
    }
    .spotlight-overlay {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient(to top, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.3));
      border-radius: 10px;
    }
    .spotlight-content {
      z-index: 1;
    }
    .spotlight-title {
      font-size: 2.5em;
      font-weight: bold;
    }
    .spotlight-info {
      font-size: 1.1em;
      margin-top: 10px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .spotlight-rating {
      font-size: 1em;
      margin-top: 5px;
      font-weight: 500;
      color: #ffd700;
    }
    .spotlight-buttons {
      margin-top: 15px;
    }
    .spotlight-buttons button {
      background-color: #fff;
      color: #121212;
      border: none;
      padding: 8px 16px;
      font-size: 0.8em; /* Smaller button size */
      cursor: pointer;
      border-radius: 20px;
      margin-right: 10px;
      display: flex;
      align-items: center;
    }
    .spotlight-buttons button i {
      margin-right: 8px;
    }

    /* Spotlight Progress Line */
    .progress-line {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 5px;
      background-color: white;
      opacity: 0.5; /* 50% opacity */
      z-index: 2;
      transform: scaleX(1);
      transform-origin: left center;
      border-radius: 2px;
    }

    /* Carousel Section */
    .carousel-section {
      margin-bottom: 30px;
      position: relative;
    }
    .carousel-title {
      font-size: 1.8em;
      font-weight: 500;
      margin-bottom: 15px;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .view-all-button {
      background: none;
      color: #fff;
      font-size: 0.7em; /* Even smaller button size */
      cursor: pointer;
      border: none;
    }
    .carousel {
      display: flex;
      gap: 15px;
      overflow-x: auto;
      scroll-behavior: smooth;
      -webkit-overflow-scrolling: touch;
      cursor: grab;
    }
    .carousel::-webkit-scrollbar {
      display: none;
    }
    .card {
      flex: 0 0 auto;
      width: 150px;
      border-radius: 10px;
      overflow: hidden;
      cursor: pointer;
      position: relative;
    }
    .card img {
      width: 100%;
      height: 225px;
      object-fit: cover;
      transition: transform 0.3s;
    }
    .card:hover img {
      transform: scale(1.05);
    }
    .rating {
      position: absolute;
      top: 10px;
      right: 10px;
      background-color: rgba(0, 0, 0, 0.8);
      padding: 5px 10px;
      border-radius: 20px;
      font-size: 0.9em;
    }

    /* Book Section */
    .book-section {
      width: 100%;
      background-color: #242424;
      border-radius: 20px;
      padding: 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 30px;
      flex-wrap: wrap; /* Allows wrapping on small screens */
    }
    .book-section img {
      height: 120px;
      margin-right: 20px;
      border-radius: 10px;
    }
    .book-content {
      flex-grow: 1;
      padding-right: 20px;
      margin-bottom: 15px; /* Add space between content and button */
    }
    .book-content h2 {
      font-size: 1.8em;
      font-weight: bold;
      margin-bottom: 10px;
    }
    .book-content p {
      font-size: 1em;
      color: #ccc;
    }
    .explore-books-button {
      background-color: #fff;
      color: #121212;
      font-weight: bold;
      padding: 12px 20px;
      border: none;
      border-radius: 30px;
      font-size: 1.2em;
      cursor: pointer;
      display: flex;
      align-items: center;
    }
    .explore-books-button:hover {
      background-color: #f5f5f5;
    }
    .explore-books-button i {
      margin-right: 10px;
    }

    /* Mobile Responsiveness */
    @media (max-width: 768px) {
      .view-all-button {
        font-size: 0.8em; /* Adjust font size on mobile */
      }
      .spotlight-buttons button {
        padding: 8px 15px;
        font-size: 0.9em;
      }
      .spotlight-info {
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
      .book-section img {
        height: 80px;
        margin-bottom: 10px; /* Add space below the image */
      }
      .book-section {
        flex-direction: column; /* Stack items vertically */
        align-items: center; /* Center-align content */
        justify-content: center; /* Center align button */
        text-align: center; /* Center text */
      }
      .book-content h2 {
        font-size: 1.5em; /* Adjust the title size */
      }
      .explore-books-button {
        font-size: 1em;
        padding: 10px 15px;
      }
    }
          
          
              /* Loading Spinner */
    .loading-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0);
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 1000;
      animation: fadeIn 0.5s ease-in-out;
    }
    .loading-spinner {
      width: 50px;
      height: 50px;
      border: 5px solid transparent;
      border-top: 5px solid #f36f27;
      border-right: 5px solid #ffa500;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }
    @keyframes spin {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(360deg);
      }
    }
    @keyframes fadeIn {
      from {
        opacity: 0.8;
      }
      to {
        opacity: 1;
      }
    }
    .content-fade-in {
      opacity: 0;
      animation: contentFadeIn 0.25s ease-in-out forwards;
    }
    @keyframes contentFadeIn {
      from {
        opacity: 1;
      }
      to {
        opacity: 0.5;
      }
    }
  </style>
</head>
<body>

      <!-- Loading Spinner -->
  <div class="loading-overlay" id="loading-overlay">
    <div class="loading-spinner"></div>
  </div>    
        <div class="container">
    <!-- Spotlight Section -->
    <div class="spotlight" id="spotlight">
      <div class="spotlight-overlay"></div>
      <div class="spotlight-content">
        <div class="spotlight-title" id="spotlight-title">Loading...</div>
        <div class="spotlight-rating" id="spotlight-rating">Rating: ⭐ 0.0</div>
        <div class="spotlight-info" id="spotlight-info">Loading...</div>
        <div class="spotlight-buttons">
          <button id="spotlight-play-button">
            <i class="fas fa-play"></i> Play
          </button>
        </div>
      </div>
      <div class="progress-line" id="progress-line"></div>
    </div>

    <!-- Trending Movies Carousel -->
    <div class="carousel-section">
      <div class="carousel-title">
        Trending Movies
        <button class="view-all-button" onclick="window.location.href='/movies'">View All</button>
      </div>
      <div class="carousel" id="trending-movies"></div>
    </div>

    <!-- Trending TV Shows Carousel -->
    <div class="carousel-section">
      <div class="carousel-title">
        Trending TV Shows
        <button class="view-all-button" onclick="window.location.href='/tv-shows'">View All</button>
      </div>
      <div class="carousel" id="trending-tv"></div>
    </div>

    <!-- Popular Anime Carousel -->
    <div class="carousel-section">
      <div class="carousel-title">
        Trending Anime
        <button class="view-all-button" onclick="window.location.href='/animes'">View All</button>
      </div>
      <div class="carousel" id="popular-anime"></div>
    </div>

    <!-- Trending Manga Carousel -->
    <div class="carousel-section">
      <div class="carousel-title">
        Trending Manga
        <button class="view-all-button" onclick="window.location.href='/search/manga'">Search</button>
      </div>
      <div class="carousel" id="trending-manga"></div>
    </div>

    <!-- Book Section -->
    <div class="book-section">
      <img src="https://images.emojiterra.com/google/noto-emoji/unicode-15/color/512px/1f4da.png" alt="Book Emoji">
      <div class="book-content">
        <h2>We're excited to announce that we've added books to our library!</h2>
        <p>Explore millions of books sourced from multiple large libraries, ready to download in epub, pdf or mobi!</p>
      </div>
      <button class="explore-books-button" onclick="window.location.href='/books'">
        <i class="fas fa-book"></i> Explore Books now!
      </button>
    </div>
  </div>

  <script>
    const API_BASE = 'https://private-tmdb.netlify.app/.netlify/functions/tmdb-cache?path=';
    const ANIME_API = 'https://9streams.xyz/apis/popular-anime.json';
    const MANGA_API = 'https://9streams.xyz/apis/popular-manga.json';
    let spotlightData = {};
    let spotlightIndex = 0;
    let spotlightItems = [];

    async function fetchTrending() {
      const movieResponse = await fetch(`${API_BASE}trending/movie/week`);
      const tvResponse = await fetch(`${API_BASE}trending/tv/week`);
      const animeData = await fetch(ANIME_API).then(res => res.json());
      const mangaData = await fetch(MANGA_API).then(res => res.json());

      const movieData = await movieResponse.json();
      const tvData = await tvResponse.json();

      spotlightItems = [...movieData.results, ...tvData.results];
      populateSpotlight(spotlightItems[spotlightIndex]);
      populateCarousel('trending-movies', movieData.results, 'movie');
      populateCarousel('trending-tv', tvData.results, 'tv');
      populateAnimeCarousel(animeData.results);
      populateMangaCarousel(mangaData);

      startSpotlightTimer();
    }

    function populateSpotlight(item) {
      const spotlightTitle = document.getElementById('spotlight-title');
      const spotlightRating = document.getElementById('spotlight-rating');
      const spotlightInfo = document.getElementById('spotlight-info');
      const spotlightImage = document.getElementById('spotlight');
      const playButton = document.getElementById('spotlight-play-button');

      spotlightTitle.textContent = item.title || item.name;
      spotlightRating.textContent = '⭐ ' + item.vote_average.toFixed(1);
      spotlightInfo.textContent = item.overview || item.description;
      spotlightImage.style.backgroundImage = `url(https://image.tmdb.org/t/p/original${item.backdrop_path})`;

      if (item.media_type === 'movie') {
        playButton.onclick = () => window.location.href = `https://9streams.xyz/movie/default?movie=${item.id}`;
      } else if (item.media_type === 'tv') {
        playButton.onclick = () => window.location.href = `https://9streams.xyz/tv/default?tv=${item.id}`;
      }
    }

    function populateCarousel(carouselId, items, type) {
      const carousel = document.getElementById(carouselId);
      carousel.innerHTML = ''; // Clear existing content
      items.forEach(item => {
        const card = document.createElement('div');
        card.className = 'card';
        card.onclick = () => {
          window.location.href = `/${type}/default?${type}=${item.id}`;
        };

        const img = document.createElement('img');
        img.src = `https://image.tmdb.org/t/p/w500${item.poster_path}`;
        img.alt = item.title || item.name;

        const rating = document.createElement('div');
        rating.className = 'rating';
        rating.innerText = '⭐ ' + item.vote_average.toFixed(1);

        card.appendChild(img);
        card.appendChild(rating);
        carousel.appendChild(card);
      });
    }

    function populateAnimeCarousel(items) {
      const carousel = document.getElementById('popular-anime');
      carousel.innerHTML = ''; // Clear existing content
      items.forEach(item => {
        const card = document.createElement('div');
        card.className = 'card';
        card.onclick = () => {
          window.location.href = `/anime/default?anime=${item.id}`;
        };

        const img = document.createElement('img');
        img.src = item.image;
        img.alt = item.title.english || item.title.romaji;

        const rating = document.createElement('div');
        rating.className = 'rating';
        rating.innerText = '⭐ ' + (item.rating / 10).toFixed(1);

        card.appendChild(img);
        card.appendChild(rating);
        carousel.appendChild(card);
      });
    }

    function populateMangaCarousel(items) {
      const carousel = document.getElementById('trending-manga');
      carousel.innerHTML = ''; // Clear existing content
      items.forEach(item => {
        const card = document.createElement('div');
        card.className = 'card';
        card.onclick = () => {
          window.location.href = `/manga/info?manga=${item.id}`;
        };

        const img = document.createElement('img');
        img.src = item.image_url;
        img.alt = item.title;

        const title = document.createElement('div');
        title.className = 'title';
        title.innerText = item.title;

        card.appendChild(img);
        card.appendChild(title);
        carousel.appendChild(card);
      });
    }

    function startSpotlightTimer() {
      const progressLine = document.getElementById('progress-line');
      progressLine.style.transition = 'none';
      progressLine.style.width = '100%';
      setTimeout(() => {
        progressLine.style.transition = 'width 10s linear';
        progressLine.style.width = '0%';
      }, 50);

      setInterval(() => {
        spotlightIndex = (spotlightIndex + 1) % spotlightItems.length;
        populateSpotlight(spotlightItems[spotlightIndex]);
        resetProgressBar();
      }, 10000); // Transition every 10 seconds
    }

    function resetProgressBar() {
      const progressLine = document.getElementById('progress-line');
      progressLine.style.transition = 'none';
      progressLine.style.width = '100%';
      setTimeout(() => {
        progressLine.style.transition = 'width 10s linear';
        progressLine.style.width = '0%';
      }, 50);
    }

    // Enable horizontal scrolling with mouse wheel and dragging
    function enableScrollAndDrag(carouselId) {
      const carousel = document.getElementById(carouselId);
      let isDragging = false;
      let startX, scrollLeft;

      carousel.addEventListener('wheel', (e) => {
        e.preventDefault();
        carousel.scrollLeft += e.deltaY;
      });

      carousel.addEventListener('mousedown', (e) => {
        isDragging = true;
        startX = e.pageX - carousel.offsetLeft;
        scrollLeft = carousel.scrollLeft;
      });

      carousel.addEventListener('mouseleave', () => {
        isDragging = false;
      });

      carousel.addEventListener('mouseup', () => {
        isDragging = false;
      });

      carousel.addEventListener('mousemove', (e) => {
        if (!isDragging) return;
        e.preventDefault();
        const x = e.pageX - carousel.offsetLeft;
        const walk = (x - startX) * 2; // Adjust dragging speed
        carousel.scrollLeft = scrollLeft - walk;
      });
    }

    enableScrollAndDrag('trending-movies');
    enableScrollAndDrag('trending-tv');
    enableScrollAndDrag('popular-anime');
    enableScrollAndDrag('trending-manga');
    fetchTrending();
          
          

    setTimeout(() => {
      const loadingOverlay = document.getElementById('loading-overlay');
      loadingOverlay.style.display = 'none';
    }, 1500); // Adjust loading time as needed
  </script>
</body>
</html>
