Skip to content

Commit

Permalink
feat: skip intro beta version (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhassan8 authored Jul 8, 2023
1 parent 1b181d6 commit 0eb52cb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
18 changes: 18 additions & 0 deletions server/css/video.css
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,21 @@
text-align: center;
line-height: 85px;
}

#video-screen #skip-intro {
background: rgba(0, 0, 0, 0.4);
padding: 15px 30px;
z-index: 2;
right: 100px;
position: absolute;
bottom: 0;
margin-bottom: 250px;
font-size: 35px;
color: #fff;
border-radius: 5px;
display: none;
}

#video-screen #skip-intro i {
margin-right: 15px;
}
4 changes: 4 additions & 0 deletions server/js/core/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ window.player = {
}, 500);
},

forwardTo: function (seconds) {
player.getVideo().currentTime = seconds;
},

stop: function () {
if (player.state != player.states.STOPPED) {
player.plugin.stopLoad();
Expand Down
9 changes: 9 additions & 0 deletions server/js/core/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ window.service = {
.catch((error) => request.error(error));
},

intro: function (request) {
fetch(
`https://static.crunchyroll.com/datalab-intro-v2/${request.data.id}.json`
)
.then((response) => response.json())
.then((json) => request.success(json))
.catch((error) => request.error(error));
},

format: function (params) {
return Object.keys(params)
.map(function (k) {
Expand Down
51 changes: 49 additions & 2 deletions server/js/screen/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ window.video = {
subtitle: null,
audios: [],
audio: null,
intro: null,
streams: [],
timers: {
history: {
Expand Down Expand Up @@ -77,6 +78,12 @@ window.video = {
<div id="next-episode-count">${video.next.time}</div>
</div>
</div>
<div id="skip-intro">
<i class="fa-solid fa-forward"></i>
SKIP INTRO
</div>
<div class="settings-slide">
<div id="languages-content">
<div class="title">Audios</div>
Expand Down Expand Up @@ -162,6 +169,9 @@ window.video = {
? video.changeAudio(options.index(selected[0]))
: video.changeSubtitle(options.index(selected[0]));
}
} if(video.intro && video.intro.state) {
osd = false;
player.forwardTo(video.intro.end);
} else {
if (video.next.status) {
clearInterval(video.timers.next);
Expand Down Expand Up @@ -276,6 +286,7 @@ window.video = {
},
success: function (data) {
video.stopNext();
video.setSkipIntro(item.id);
video.next.shown = false;
try {
video.streams = data.streams.adaptive_hls;
Expand All @@ -288,9 +299,9 @@ window.video = {
}

video.audio = data.audio_locale;
video.audios = [{name: video.audio, id: 0}];
video.audios = [{ name: video.audio, id: 0 }];

if(data.versions) {
if (data.versions) {
video.audios = data.versions.map((element) => ({
name: element.audio_locale,
id: element.media_guid,
Expand Down Expand Up @@ -323,6 +334,40 @@ window.video = {
});
},

setSkipIntro: function (id) {
service.intro({
data: {
id,
},
success: function (data) {
if (data.duration && data.duration > 10) {
video.intro = {
start: data.startTime + 2,
end: data.endTime - 2,
state: false,
};
} else {
video.intro = null;
}
},
error: function (error) {
console.log(error);
},
});
},

showSkip: function (time) {
if (time > video.intro.end) {
video.intro.state = false;
$("#skip-intro").hide();
} else {
if (!video.intro.state && time > video.intro.start && time < video.intro.end) {
video.intro.state = true;
$("#skip-intro").show();
}
}
},

setAudios: function () {
$("#audios li").remove();
var audios = "";
Expand Down Expand Up @@ -470,6 +515,8 @@ window.video = {
var totalTime = player.getDuration();
var timePercent = (100 * time) / totalTime;

video.intro && video.showSkip(time);

if (
!video.next.shown &&
player.state === player.states.PLAYING &&
Expand Down

0 comments on commit 0eb52cb

Please sign in to comment.