gonzopi

git clone https://git.tarina.org/gonzopi
Log | Files | Refs | README | LICENSE

commit 4f8da412453c119cbd6565a0e52d38d28ad297c1
parent 97f7794660d0fdc2b30db9f05a858386585cc3ea
Author: rbckman <rob@tarina.org>
Date:   Tue,  8 Apr 2025 15:05:19 +0300

new player

Diffstat:
Msrv/gonzopiserver.py | 20+++++++++++++++++++-
Msrv/templates/player.html | 114+++++++++++++++++++++++++++++++++++++++++++------------------------------------
2 files changed, 81 insertions(+), 53 deletions(-)

diff --git a/srv/gonzopiserver.py b/srv/gonzopiserver.py @@ -9,6 +9,7 @@ import time import random import hashlib import configparser +from pymediainfo import MediaInfo # Get path of the current dir, then use it as working directory: rundir = os.path.dirname(__file__) @@ -57,12 +58,14 @@ vumeterold = '' #if config.read(configfile): # filmfolder = config['USER']['filmfolder']+'/' filmfolder = '/home/pi/gonzopifilms/' +real_filmfolder=filmfolder os.system("unlink static/*") #CHECK IF FILMING TO USB STORAGE filmfolderusb=usbfilmfolder() if filmfolderusb: filmfolder=filmfolderusb + real_filmfolder=filmfolder # Link video directory to static dir os.system("ln -s -t static/ " + filmfolder) filmfolder='static/gonzopifilms/' @@ -224,6 +227,21 @@ def checkvideo(video,filmfolder,film,scene,shot,take): return p, v return '', v +def has_audio_track(file_path): + try: + # Parse the media file + media_info = MediaInfo.parse(file_path) + + # Check for audio tracks + for track in media_info.tracks: + if track.track_type == "Audio": + return True + return False + + except Exception as e: + print(f"Error parsing {file_path}: {e}") + return None + class intro: def GET(self): return render.intro() @@ -373,7 +391,7 @@ class player: def GET(self, film): i=web.input(scene=None,shot=None,take=None) randhash = hashlib.md5(str(random.getrandbits(256)).encode('utf-8')).hexdigest() - return render.player(filmfolder,film,i.scene,i.shot,i.take,str,randhash) + return render.player(real_filmfolder,filmfolder,film,i.scene,i.shot,i.take,str,randhash,has_audio_track) class api: def GET(self): diff --git a/srv/templates/player.html b/srv/templates/player.html @@ -1,78 +1,88 @@ -$def with (filmfolder,film,scene,shot,take,str,randhash) +$def with (real_filmfolder,filmfolder,film,scene,shot,take,str,randhash,has_audio_track) $ video='' $ audio='' $if shot != None and take != None: $ video = '/'+filmfolder + film + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/take' + str(take).zfill(3) + '.mp4' + $ video_realpath = '/'+real_filmfolder + film + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/take' + str(take).zfill(3) + '.mp4' $ title = film + ' scene|' + str(scene).zfill(3) + ' shot|' + str(shot).zfill(3) + ' take|' + str(take).zfill(3) $ audio = '/'+filmfolder + film + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/take' + str(take).zfill(3) + '.wav' $elif scene != None: $ video = '/'+filmfolder + film + '/scene' + str(scene).zfill(3) + '/scene.mp4' + $ video_realpath = '/'+real_filmfolder + film + '/scene' + str(scene).zfill(3) + '/scene.mp4' $ audio = '/'+filmfolder + film + '/scene' + str(scene).zfill(3) + '/scene.wav' $ title = film + ' scene|' + str(scene).zfill(3) $elif film != None: $ video = '/'+filmfolder + film + '/'+film+'.mp4' + $ video_realpath = '/'+real_filmfolder + film + '/'+film+'.mp4' $ audio = '/'+filmfolder + film + '/'+film+'.wav' $ title = film <h3>$title</h3> -<div class="player-container"> -<video id="videoPlayer" controls> - <source src="$video?randhash" type="video/mp4"> - Your browser does not support the video element. -</video> -<audio id="audioPlayer"> - <source src="$audio?randhash" type="audio/wav"> - Your browser does not support the audio element. -</audio> -<div class="controls"> -</div> -</div> +$if has_audio_track(video_realpath) == False: + <div class="player-container"> + <video id="videoPlayer" controls> + <source src="$video?randhash" type="video/mp4"> + Your browser does not support the video element. + </video> + <audio id="audioPlayer"> + <source src="$audio?randhash" type="audio/wav"> + Your browser does not support the audio element. + </audio> + <div class="controls"> + </div> + </div> -<script> -const video = document.getElementById('videoPlayer'); -const audio = document.getElementById('audioPlayer'); + <script> + const video = document.getElementById('videoPlayer'); + const audio = document.getElementById('audioPlayer'); -// Sync video and audio playback -video.addEventListener('play', () => { - audio.play(); -}); + // Sync video and audio playback + video.addEventListener('play', () => { + audio.play(); + }); -video.addEventListener('pause', () => { - audio.pause(); -}); + video.addEventListener('pause', () => { + audio.pause(); + }); -// Sync playhead movement -video.addEventListener('seeked', () => { - audio.currentTime = video.currentTime; -}); + // Sync playhead movement + video.addEventListener('seeked', () => { + audio.currentTime = video.currentTime; + }); -// Keep audio in sync during playback -video.addEventListener('timeupdate', () => { - if (Math.abs(video.currentTime - audio.currentTime) > 0.5) { - audio.currentTime = video.currentTime; - } -}); + // Keep audio in sync during playback + video.addEventListener('timeupdate', () => { + if (Math.abs(video.currentTime - audio.currentTime) > 0.5) { + audio.currentTime = video.currentTime; + } + }); -// Optional: Handle playback rate changes -video.addEventListener('ratechange', () => { - audio.playbackRate = video.playbackRate; -}); + // Optional: Handle playback rate changes + video.addEventListener('ratechange', () => { + audio.playbackRate = video.playbackRate; + }); -// Control functions -function playBoth() { - video.play(); - audio.play(); -} + // Control functions + function playBoth() { + video.play(); + audio.play(); + } -function pauseBoth() { - video.pause(); - audio.pause(); -} + function pauseBoth() { + video.pause(); + audio.pause(); + } -// Ensure audio stays muted if video is muted -video.addEventListener('volumechange', () => { - audio.muted = video.muted; - audio.volume = video.volume; -}); -</script> + // Ensure audio stays muted if video is muted + video.addEventListener('volumechange', () => { + audio.muted = video.muted; + audio.volume = video.volume; + }); + </script> +$else: + <div class="player-container"> + <video id="videoPlayer" controls> + <source src="$video?randhash" type="video/mp4"> + Your browser does not support the video element. + </video> <h3><a href="/c">BACK</a></h3>