Added simplistic trailer detection

This commit is contained in:
itdominator 2022-09-05 15:34:18 -05:00
parent 0c945c72b0
commit 0aeb071215
5 changed files with 137 additions and 59 deletions

View File

@ -29,9 +29,22 @@ def get_window_controller():
id = secrets.token_hex(16)
controller = WindowController()
view = controller.get_window(1).get_view(0)
view.ABS_THUMBS_PTH = app.config['ABS_THUMBS_PTH']
view.REMUX_FOLDER = app.config['REMUX_FOLDER']
view.FFMPG_THUMBNLR = app.config['FFMPG_THUMBNLR']
try:
view.ABS_THUMBS_PTH = app.config['ABS_THUMBS_PTH']
except Exception as e:
...
try:
view.REMUX_FOLDER = app.config['REMUX_FOLDER']
except Exception as e:
...
try:
view.FFMPG_THUMBNLR = app.config['FFMPG_THUMBNLR']
except Exception as e:
...
view.logger = logger
session['win_controller_id'] = id
@ -85,15 +98,30 @@ def listFiles(_hash = None):
sub_path = view.get_current_sub_path()
current_directory = sub_path.split("/")[-1]
trailer = None
if "(" in current_directory and ")" in current_directory:
title = current_directory.split("(")[0].strip()
startIndex = current_directory.index('(') + 1
endIndex = current_directory.index(')')
date = current_directory[startIndex:endIndex]
video_data = tmdb.search(title, date)
background_url = video_data[0]["backdrop_path"]
video_data = tmdb.search(title, date)[0]
video_id = video_data["id"]
background_url = video_data["backdrop_path"]
background_pth = f"{view.get_current_directory()}/000.jpg"
try:
tmdb_videos = tmdb.tmdbapi.get_movie(str(video_id), append_to_response="videos")["videos"]["results"]
for tmdb_video in tmdb_videos:
if "YouTube" in tmdb_video["site"]:
trailer_key = tmdb_video["key"]
trailer = f"https://www.youtube-nocookie.com/embed/{trailer_key}?start=0&autoplay=1";
if not trailer:
raise Exception("No key found. Defering to none...")
except Exception as e:
print("No trailer found...")
trailer = None
if not os.path.isfile(background_pth):
r = requests.get(background_url, stream = True)
@ -113,6 +141,7 @@ def listFiles(_hash = None):
in_fave = "true" if fave else "false"
files.update({'in_fave': in_fave})
files.update({'trailer': trailer})
return files
else:
msg = "Can't manage the request type..."

View File

@ -51,6 +51,18 @@ const updateHTMLDirList = async (data) => {
let isInFaves = data.in_fave;
let background_image = (images[0]) ? images[0][0] : "";
if (data.hasOwnProperty("trailer")) {
let trailerBttn = document.getElementById("trailer-btn");
let trailerLink = document.getElementById("trailer-link");
if (data.trailer !== null) {
trailerBttn.style.display = "";
trailerLink.href = `javascript: showFile( "Trailer", "${data.trailer}", "", "trailer" )`;
} else {
trailerBttn.style.display = "none";
trailerLink.href = "#";
}
}
document.getElementById("path").innerText = data.path_head;
// Setup background if there is a 000.* in selection
if (background_image.match(/000\.(jpg|png|gif)\b/) != null) {

View File

@ -50,8 +50,9 @@ const scrollFilesToTop = () => {
const closeFile = () => {
const video = document.getElementById("video");
let title = document.getElementById("selectedFile");
const video = document.getElementById("video");
const trailerPlayer = document.getElementById("trailerPlayer")
let title = document.getElementById("selectedFile");
document.getElementById("image-viewer").style.display = "none";
document.getElementById("text-viewer").style.display = "none";
@ -61,6 +62,9 @@ const closeFile = () => {
video.style.display = "none";
video.style.cursor = '';
video.pause();
trailerPlayer.src = "#";
trailerPlayer.style.display = "none";
}
const showFile = async (title, hash, extension, type) => {
@ -68,9 +72,10 @@ const showFile = async (title, hash, extension, type) => {
document.getElementById("text-viewer").style.display = "none";
document.getElementById("pdf-viewer").style.display = "none";
document.getElementById("video").style.display = "none";
document.getElementById("trailerPlayer").style.display = "none";
let titleElm = document.getElementById("selectedFile");
titleElm.innerText = title;
let titleElm = document.getElementById("selectedFile");
titleElm.innerText = title;
if (type === "video") {
setupVideo(hash, extension);
@ -78,15 +83,27 @@ const showFile = async (title, hash, extension, type) => {
if (type === "file") {
setupFile(hash, extension);
}
if (type === "trailer") {
launchTrailer(hash);
}
}
const launchTrailer = (link) => {
let modal = new bootstrap.Modal(document.getElementById('file-view-modal'), { keyboard: false });
let trailerPlayer = document.getElementById("trailerPlayer");
trailerPlayer.style.display = "";
trailerPlayer.src = link;
modal.show();
}
const setupVideo = async (hash, extension) => {
let modal = new bootstrap.Modal(document.getElementById('file-view-modal'), { keyboard: false });
let video = document.getElementById("video");
video.poster = "static/imgs/icons/loading.gif";
video.style.display = "";
video.src = "#"
video_path = "api/file-manager-action/files/" + hash;
let modal = new bootstrap.Modal(document.getElementById('file-view-modal'), { keyboard: false });
try {

View File

@ -7,9 +7,9 @@
<div id="navbarTogglerHeader" class="row collapse navbar-collapse">
{% if current_directory %}
<div class="col">
<div class="col col-auto">
<!-- Left menues -->
<ul class="navbar-nav col-auto">
<ul class="navbar-nav">
<li class="nav-item" data-bs-toggle="modal" data-bs-target="#file-view-modal">
<i class="nav-link bi bi-projector-fill" aria-hidden="true" title="File viewer..." >
Media Viewer
@ -38,6 +38,14 @@
</div>
{% endif %}
<div class="col">
<li class="nav-item mx-3">
<a id="trailer-link" href="#">
<span id="trailer-btn" class="btn btn-info btn-sm" style="display: none;" title="Trailer..." >Trailer</span>
</a>
</li>
</div>
<div class="col col-auto">
<!-- Right menues -->
<ul class="navbar-nav">

View File

@ -22,57 +22,69 @@
>
</video>
<!-- For image -->
<img id="image-viewer" class="card-img-top viewer"
style="display: none;"
src="" alt="" />
<iframe id="trailerPlayer"
width="560" height="315"
style="display: none;"
src=""
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen="allowfullscreen"
mozallowfullscreen="mozallowfullscreen"
msallowfullscreen="msallowfullscreen"
oallowfullscreen="oallowfullscreen"
webkitallowfullscreen="webkitallowfullscreen">
</iframe>
<!-- For pdf -->
<iframe id="pdf-viewer" class="card-img-top viewer"
src=""
style="display: none;"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen="allowfullscreen"
mozallowfullscreen="mozallowfullscreen"
msallowfullscreen="msallowfullscreen"
oallowfullscreen="oallowfullscreen"
webkitallowfullscreen="webkitallowfullscreen">
</iframe>
<!-- For image -->
<img id="image-viewer" class="card-img-top viewer"
style="display: none;"
src="" alt="" />
<!-- For text -->
<pre id="text-viewer" class="card-img-top viewer"
style="display: none;">
</pre>
<!-- For pdf -->
<iframe id="pdf-viewer" class="card-img-top viewer"
src=""
style="display: none;"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen="allowfullscreen"
mozallowfullscreen="mozallowfullscreen"
msallowfullscreen="msallowfullscreen"
oallowfullscreen="oallowfullscreen"
webkitallowfullscreen="webkitallowfullscreen">
</iframe>
<!-- For GBA JS Emulator -->
<div id="gbajs-viewer" class="card-img-top viewer"
style="display: none;">
<canvas id="screen" width="720" height="480"></canvas>
<section id="controls">
<div id="preload">
<button class="bigbutton" id="select" onclick="document.getElementById('loader').click()">SELECT</button>
<input id="loader" type="file" accept=".gba" onchange="run(this.files[0]);">
<button onclick="document.getElementById('saveloader').click()">Upload Savegame</button>
<input id="saveloader" type="file" onchange="uploadSavedataPending(this.files[0]);">
</div>
<div id="ingame" class="hidden">
<button id="pause" class="bigbutton" onclick="togglePause()">PAUSE</button>
<button class="bigbutton" onclick="reset()">RESET</button>
<button onclick="gba.downloadSavedata()">Download Savegame</button>
<button onclick="screenshot()">Screenshot</button>
<label id="pixelated">
<input type="checkbox" onchange="setPixelated(this.checked)">
<p>Pixelated</p>
</label>
<div id="sound">
<input type="checkbox" checked onchange="gba.audio.masterEnable = this.checked">
<p>Sound</p>
<input type="range" min="0" max="1" value="1" step="any" onchange="setVolume(this.value)" oninput="setVolume(this.value)">
<!-- For text -->
<pre id="text-viewer" class="card-img-top viewer"
style="display: none;">
</pre>
<!-- For GBA JS Emulator -->
<div id="gbajs-viewer" class="card-img-top viewer"
style="display: none;">
<canvas id="screen" width="720" height="480"></canvas>
<section id="controls">
<div id="preload">
<button class="bigbutton" id="select" onclick="document.getElementById('loader').click()">SELECT</button>
<input id="loader" type="file" accept=".gba" onchange="run(this.files[0]);">
<button onclick="document.getElementById('saveloader').click()">Upload Savegame</button>
<input id="saveloader" type="file" onchange="uploadSavedataPending(this.files[0]);">
</div>
<p id="openDebug" onclick="enableDebug()">Debugger</p>
</div>
</section>
</div>
<div id="ingame" class="hidden">
<button id="pause" class="bigbutton" onclick="togglePause()">PAUSE</button>
<button class="bigbutton" onclick="reset()">RESET</button>
<button onclick="gba.downloadSavedata()">Download Savegame</button>
<button onclick="screenshot()">Screenshot</button>
<label id="pixelated">
<input type="checkbox" onchange="setPixelated(this.checked)">
<p>Pixelated</p>
</label>
<div id="sound">
<input type="checkbox" checked onchange="gba.audio.masterEnable = this.checked">
<p>Sound</p>
<input type="range" min="0" max="1" value="1" step="any" onchange="setVolume(this.value)" oninput="setVolume(this.value)">
</div>
<p id="openDebug" onclick="enableDebug()">Debugger</p>
</div>
</section>
</div>
</div>
</div>
</div>