@@ -4,6 +4,8 @@ var deepFreeze = require('deep-freeze');
44var ERROR = require ( '../error' ) ;
55
66var SUBS_SCALE_FACTOR = 0.0066 ;
7+ var EOF_END_TOLERANCE = 5000 ;
8+ var HTTP_RECONNECT_OPTIONS = 'reconnect=1,reconnect_streamed=1,reconnect_on_network_error=1,reconnect_on_http_error=5xx,reconnect_delay_max=10,reconnect_max_retries=10' ;
79
810var stremioToMPVProps = {
911 'loaded' : 'loaded' ,
@@ -259,7 +261,9 @@ function ShellVideo(options) {
259261 ipc . on ( 'mpv-event-ended' , function ( args ) {
260262 // older shells report 'other' for every non-error reason, including eof
261263 if ( args . error ) onError ( args . error ) ;
262- else if ( ! args . reason || args . reason === 'eof' || args . reason === 'other' ) onEnded ( ) ;
264+ else if ( ! args . reason || args . reason === 'eof' || args . reason === 'other' ) {
265+ if ( ! isKnownEarlyEof ( ) ) onEnded ( ) ;
266+ }
263267 } ) ;
264268
265269 function getProp ( propName ) {
@@ -279,6 +283,15 @@ function ShellVideo(options) {
279283 function onEnded ( ) {
280284 events . emit ( 'ended' ) ;
281285 }
286+ function isKnownEarlyEof ( ) {
287+ var time = props [ 'time-pos' ] ;
288+ var duration = props . duration ;
289+ return typeof time === 'number' &&
290+ isFinite ( time ) &&
291+ typeof duration === 'number' &&
292+ isFinite ( duration ) &&
293+ time + EOF_END_TOLERANCE < duration ;
294+ }
282295 function onPropChanged ( propName ) {
283296 if ( observedProps [ propName ] ) {
284297 events . emit ( 'propChanged' , propName , getProp ( propName ) ) ;
@@ -409,6 +422,7 @@ function ShellVideo(options) {
409422
410423 var subAssOverride = commandArgs . assSubtitlesStyling ? 'strip' : 'no' ;
411424 ipc . send ( 'mpv-set-prop' , [ 'sub-ass-override' , subAssOverride ] ) ;
425+ ipc . send ( 'mpv-set-prop' , [ 'stream-lavf-o' , HTTP_RECONNECT_OPTIONS ] ) ;
412426
413427 var gpuProcessing = ! ! commandArgs . gpuVideoProcessing &&
414428 ! ! commandArgs . hardwareDecoding ;
0 commit comments