<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="UTF-8">
    <meta property="og:title" content=deflax.net>
    <meta property="og:site_name" content="▷">
    <meta property="og:url" content=https://deflax.net>
    <meta property="og:description" content="The landing page of the flaxnet">
    <meta property="og:type" content=product>
    <meta property="og:image" content=https://deflax.net/static/images/logo.png>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>▷ deflax.net</title>

    <link rel='shortcut icon' type='image/x-icon' href='/static/images/favicon.ico' />
    <link rel="stylesheet" href="static/css/root.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/plyr/dist/plyr.min.css">

    <script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.min.js" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/plyr/dist/plyr.min.js" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js" crossorigin="anonymous"></script>
</head>

<body>
<nav class="navbar fixed-top navbar-dark bg-dark navbar-expand">
  <div class="container-fluid">
    <div class="col-lg-1 d-none d-md-block">
    </div>
    <a class="navbar-brand" href="#">
      <img src="static/images/logo.png" alt="" width="40" height="40" class="d-inline-block align-text-center">
    deflax.net
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse text-right" id="navbarNav">
      <ul class="navbar-nav ms-auto flex-nowrap">
        <li class="nav-item">
          <a class="nav-link" href="#stream">Stream <i class="fa fa-satellite-dish" aria-hidden="true"></i></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#archive">Archive <i class="fa fa-file-video" aria-hidden="true"></i></a>
        </li>
      </ul>
    </div>
    <div class="col-lg-1 d-none d-md-block">
    </div>
  </div>
</nav>

<div class="content-container bg-dark text-white">
  <div id="stream" class="container-fluid p-3 bg-dark text-white">
    <div class="row">
      <div class="col-md-1 d-none d-md-block">
      </div>
      <div class="col-12 col-lg-10">
          <div class="content">
              <video controls crossorigin playsinline muted poster="static/images/poster.png">
              </video>
<script>
document.addEventListener('DOMContentLoaded', () => {
  const video = document.querySelector("video");
  const source = 'https://stream.deflax.net/memfs/f2844c7c-e86c-4f0a-afb6-a1b0e25a5071.m3u8';
  const playhead_url = "https://deflax.net/playhead";
  
  // For more options, see: https://github.com/sampotts/plyr/#options
  // captions.update is required for captions to work with hls.js
  const defaultOptions = {};

  //
  // First check for native browser HLS support
  //
  if (video.canPlayType('application/vnd.apple.mpegurl')) {
    async function fetchInitData() {
      try {
        // Fetch data from the API
        const response = await fetch(playhead_url);

        // Check if the response is successful (status code 200)
        if (!response.ok) {
          throw new Error(`Video: HTTP error! Status: ${response.status}`);
        }

        // Parse JSON from the response
        const data = await response.json();

        // Now 'data' contains the parsed JSON
        //console.log("Fetched JSON data:", data);

        video.src = data.head;
        console.log("Video: switching to ", data.head);

        const player = new Plyr(video, defaultOptions);
      } catch (error) {
        console.error("Video: Error fetching data:", error);
      }
    }
    fetchInitData();
    //
    // If no native HLS support, check if HLS.js is supported
    //
  } else if (Hls.isSupported()) {
    const hls = new Hls();

    // Function to fetch and process JSON from the API
    async function fetchData() {
      try {
        // Fetch data from the API
        const response = await fetch(playhead_url);

        // Check if the response is successful (status code 200)
        if (!response.ok) {
          throw new Error(`HLS.js: HTTP error! Status: ${response.status}`);
        }

        // Parse JSON from the response
        const data = await response.json();

        // Now 'data' contains the parsed JSON
        // console.log("Fetched JSON data:", data);

        const oldsrc = hls.url;
        const newsrc = data.head;

        if (newsrc === oldsrc) {
          console.log("HLS.js: playing from ", newsrc);
        } else {
          console.log("HLS.js: switching to ", newsrc);
          hls.loadSource(newsrc);
          video.load();  // Reload the video element to apply the new source
          video.play().catch(error => {
            console.error('HLS.js: Autoplay was prevented:', error);
          });
        }
      } catch (error) {
        console.error("HLS.js: Error fetching data:", error);
      }
    }
    fetchData();

    // Set the interval for periodic execution (e.g., every 5 seconds)
    const interval = 4200; // in milliseconds
    setInterval(fetchData, interval);

    // Attach Hls.js to the video element
    hls.loadSource(source);
    hls.attachMedia(video);

    // From the m3u8 playlist, hls parses the manifest and returns
    // all available video qualities. This is important; in this approach,
    // we will have one source on the Plyr player.
    hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
      console.log("HLS.js: manifest parsed");

      // Transform available levels into an array of integers (height values).
      const availableQualities = hls.levels.map((l) => l.height)
      availableQualities.unshift(0); //prepend 0 to quality array

      // Add new qualities to option
      defaultOptions.quality = {
        default: 0, //Default - AUTO
        options: availableQualities,
        forced: true,
        onChange: (e) => updateQuality(e),
      }

      // Add Auto Label 
      defaultOptions.i18n = {
        qualityLabel: {
          0: 'Auto',
        },
      }

      hls.on(Hls.Events.LEVEL_SWITCHED, function (event, data) {
        console.log("HLS.js: level switched");
        var span = document.querySelector(".plyr__menu__container [data-plyr='quality'][value='0'] span")
        if (hls.autoLevelEnabled) {
          span.innerHTML = `AUTO (${hls.levels[data.level].height}p)`
        } else {
          span.innerHTML = `AUTO`
        }
      });

      // Initialize new Plyr player with quality options
      const player = new Plyr(video, defaultOptions);
    });

    window.hls = hls;
  }

  function updateQuality(newQuality) {
    if (newQuality === 0) {
      window.hls.currentLevel = -1; //Enable AUTO quality if option.value = 0
    } else {
      window.hls.levels.forEach((level, levelIndex) => {
        if (level.height === newQuality) {
          console.log("HLS.js: Found quality match with " + newQuality);
          window.hls.currentLevel = levelIndex;
        }
      });
    }
  }
});

</script>
	</div>
      </div>
      <div class="col-md-1 d-none d-md-block">
      </div>
    </div>
  </div>
</div>

<div class="content-container bg-dark text-white">
<div id="archive" class="container-fluid p-3 bg-dark text-white">
  <div class="row">
    <div class="col-md-1 d-none d-md-block">
    </div>
    <div class="col-12 col-lg-10">
      <div class="content">
	      <div class="gallery">
          {% for thumbnail in thumbnails %}
          <div class="gallery-item">
              <a href="{{ url_for('video_watch_route', video_file_no_extension=thumbnail[:-4]) }}" class="image-link">
                  <img src="{{ url_for('thumb_route', thumb_file=thumbnail) }}" alt="{{ thumbnail }}">
                  <div class="overlay">
                    <div class="overlay-content">
                      <p>{{ thumbnail[:-4] }}</p>
                  </div>
              </div>
              </a>
          </div>
          {% endfor %}
	      </div>
      </div>
    </div>
    <div class="col-md-1 d-none d-md-block">
    </div>
  </div>
</div>
</div>

<div class="content-container bg-dark text-white">
<div id="info" class="container-fluid p-3 bg-dark text-white">
<div class="row">
  <div class="col-md-1 d-none d-md-block">
  </div>
  <div class="col col-xl-2">
    <div class="content">
      <h2>Friends</h2>
	      <p><a href='https://jungletrain.net/' target=_blank><img src="static/images/jtlogo.png" height="64"></a></p>
	      <p><a href='http://freerave.cz/' target=_blank><img src="static/images/freeravemini.png" height="64"></a></p>
	      <p><a href='http://iwayhigh.net/' target=_blank>|iway|High</a></p>
	      <p><a href='https://amoris.sknt.ru/' target=_blank>Anima Amoris</a></p>
	      <p>You! 🙃</p>
    </div>
  </div>
  <div class="col col-xl-2">
    <div class="content">
      <h2>Media</h2>
      <p><a href='https://youtube.com/@daniel.deflax' target=_blank><img src="static/images/icons8-youtube-96.png"></a></p>
      <p><a href='https://www.twitch.tv/deflaxtv' target_blank><img src="static/images/icons8-twitch-96.png"></a></p>
      <p><a href='https://soundcloud.com/deflax' target=_blank><img src="static/images/icons8-soundcloud-96.png"></a></p>
    </div>
  </div>
  <div class="col col-xl-4">
    <div class="content">
      <h2>Spam</h2>
        <p><a href='https://discord.com/invite/KKGtn6GCE3' target=_blank><img src="static/images/icons8-discord-96.png"></a></p>
        <p><a href='https://instagram.com/daniel.deflax' target=_blank><img src="static/images/icons8-instagram-96.png"></a></p>
        <p><a href='https://facebook.com/daniel.default' target=_blank><img src="static/images/icons8-facebook-96.png"></a></p>
    </div>
  </div>
  <div class="col col-xl-3">
    <div class="content">
      <h2>About</h2>
<pre>
  _______________________________
 /|o............................o|
| |:    .. flax network ..   .. :|
| |:   ... . .. 2008-{{ now.year }} ....  :|
| |:      ,-.   _____   ,-.     :|
| |:     ( `)) [_____] ( `))    :|
|v|:      `-`   ' ' '   `-`     :|
|||:      ,______________.      :|
|||....../::::o::::::o::::\......|
|^|o..../:::O::::::::::O:::\....o|
|/`----/--------------------`----|
`.____/ /====/ /=//=/ /====/_____/
      `--------------------'
</pre>
<p>Icons by <a target="_blank" href="https://icons8.com">Icons8</a></p>
<p>Everthying you do is a <a href='https://rareboc.org/' target=_blank>balloon</a></p>
    </div>
  </div>
  <div class="col-md-1 d-none d-md-block">
  </div>
</div>
</div>
</div>

</body>
</html>

