Skip to content

Commit

Permalink
Merge pull request #75 from AN0NCER/develop
Browse files Browse the repository at this point in the history
December update
  • Loading branch information
AN0NCER authored Dec 19, 2023
2 parents e9e177d + 0c05019 commit 9e88a75
Show file tree
Hide file tree
Showing 38 changed files with 31,896 additions and 1,380 deletions.
Binary file modified images/icon-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/player-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/preview-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29,063 changes: 29,061 additions & 2 deletions javascript/library/hls.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions javascript/library/hls.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion javascript/library/hls.min.js.map

This file was deleted.

195 changes: 195 additions & 0 deletions javascript/library/rxjs.umd.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions javascript/library/rxjs.umd.min.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions javascript/modules/TunimeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,21 @@ export const ApiTunime = {
.then(function (data) { return resolve(data); })
.catch((res) => { console.log(res) });
});
},

/**
* Создание обьединеного файла m3u8
* @param {string} q720 - ссылка на 720p
* @param {string} q480 - ссылка на 480p
* @param {string} q360 - ссылка на 360p
* @returns Ссылку на объединенный файл m3u8
*/
link_file: function ({ q720 = undefined, q480 = undefined, q360 = undefined } = {}) {
const params = { q720, q480, q360 };
const queryParams = Object.entries(params)
.filter(([key, value]) => value !== undefined)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
return `https://anime-m3u8.onrender.com/m3u8?${queryParams}`;
}
}
2 changes: 1 addition & 1 deletion javascript/pages/index/mod_github.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function UpdatetGithub(data) {
if (saved_git_version == null || saved_git_version.tag != data.tag_name) {
//Пользователь находиться без ключа об обновлениях
if (localStorage.getItem(UpdateKey()) == null) {
localStorage.setItem(UpdateKey(), true);
localStorage.setItem(UpdateKey(), false);
}
//Если было обновление показываем диалоговое окно
if (localStorage.getItem(UpdateKey()) == "true") {
Expand Down
169 changes: 169 additions & 0 deletions javascript/pages/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { InitUI, InitUICallbacks, ResetUI } from "./player/mod_ui.js";
import { InitEvent, onDuration$, onPlay$ } from "./player/mod_event.js";
import { InitFunctions, ResetFunctions } from "./player/mod_functions.js";
import { InitAPI, ParentWindow, SendAPI } from "./player/mod_api.js";
import { FULL_PLAYER, InitSettings, QUALITY } from "./player/mod_settings.js";
import { AnimLoadPlayer } from "./player/mod_animation.js";
import { LoadM3U8, LoadM3U8Episode } from "./player/mod_stream.js";

export const Player = document.getElementById('player');
export const hls = new Hls();
export const onBuffered$ = new rxjs.Subject();

export const AnimeQuery = { id: new URLSearchParams(window.location.search).get("id"), episode: new URLSearchParams(window.location.search).get("e") };

/**
* Переключение эпизодов
* @param {number} e - Эпизод
*/
export async function LoadEpisode(e) {
if (!e) return;
AnimLoadPlayer.start();
ResetUI();
ResetFunctions();
const stream_file = await LoadM3U8Episode(AnimeQuery.id, e);
let b = onDuration$.subscribe({
next: () => {
Player.play();
b.unsubscribe();
}
});
LoadPlayer(stream_file);
}

/**
* Загрузка аниме
* @param {number} id - Индентификатор аниме
* @param {number} e - Эпизод
*/
async function LoadAnime(id, e) {
const stream_file = await LoadM3U8(id, e);
LoadPlayer(stream_file);
}

/**
* Загрузка экземпляра
*/
function Example() {
let stream_file = "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8";
LoadPlayer(stream_file);
}

//Начло запуска
(async () => {
//Запускаем анимацию загрузки плеера
AnimLoadPlayer.start();
//Проверяем на наличие query данных
if (!AnimeQuery.id || !AnimeQuery.episode) return;

//Инициализируем библиотеки свзяаные с плеером
InitEvent();
InitUI();
InitUICallbacks();
InitAPI();
InitFunctions();
InitSettings();
InitPlayer();

//Проверяем что плеер находится на моем сайте
if (ParentWindow.location.pathname == "/watch.html" && ParentWindow.location.hostname == window.location.hostname) {
LoadAnime(AnimeQuery.id, AnimeQuery.episode);
} else {
Example();
}
})();

/**
* Инициализирует плеер hls или стандартный
*/
function InitPlayer() {
if (Hls.isSupported()) {
console.log(`[plr] - Hls supported`)
hls.on(Hls.Events.BUFFER_APPENDED, function (event, data) {
var bufferedRanges = Player.buffered;

if (bufferedRanges.length > 0) {
var loadedTime = bufferedRanges.end(bufferedRanges.length - 1);
onBuffered$.next(loadedTime);
}
});
hls.on(Hls.Events.MANIFEST_PARSED, function () {
//Устанавливаем максимальное разрешение с параметров
let level = -1;
for (let i = 0; i < hls.levels.length; i++) {
const element = hls.levels[i];
if (element.name == QUALITY) {
level = i;
}
}
//Ставим максимальный разрешенный уровень прогрузки
hls.autoLevelCapping = level;
});
hls.on(Hls.Events.ERROR, (e, data) => {
if (data.fatal) {
SendAPI.error(data.details)
}
});
} else {
console.log(`[plr] - Hls unsupported`)
Player.addEventListener('progress', function () {
var bufferedRanges = Player.buffered;
if (bufferedRanges.length > 0) {
var loadedTime = bufferedRanges.end(bufferedRanges.length - 1);
onBuffered$.next(loadedTime);
}
});
}
}

/**
* Подключает ресур m3u8 к плееру
* @param {string} stream_file - URL link к файлу m3u8
*/
function LoadPlayer(stream_file) {
let s = onDuration$.subscribe({
next: () => {
AnimLoadPlayer.stop();
s.unsubscribe();
}
});
let f = onPlay$.subscribe({
next: () => {
if(FULL_PLAYER){
toggleFullScreen();
}
f.unsubscribe();
}
});
if (Hls.isSupported()) {
hls.loadSource(stream_file);
hls.attachMedia(Player);
} else {
Player.src = stream_file;
}
}

/**
* Функция включающая на весь экран плеер
*/
export const toggleFullScreen = async () => {
const container = document.getElementById('player-wrapper');
const fullscreenApi = container.requestFullscreen
|| container.webkitRequestFullScreen
|| container.mozRequestFullScreen
|| container.msRequestFullscreen;

if (fullscreenApi == undefined) {
if (Player.webkitEnterFullscreen) {
Player.webkitEnterFullscreen();
} else if (Player.requestFullscreen) {
Player.requestFullscreen();
}
}
if (!document.fullscreenElement) {
fullscreenApi.call(container);
}
else {
document.exitFullscreen();
}
};
Loading

0 comments on commit 9e88a75

Please sign in to comment.