Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added m3u8-player to Web Development Directory #1163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Web Development/m3u8-player/home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.page-name {
margin: 0.5em 2.5em;
color: rgb(18, 96, 101);
font-size: 2.5em;
}

#text-box {
position: fixed;
top: 50%;
left: 50%;
width: 30em;
height: 18em;
margin-top: -9em; /*set to a negative number 1/2 of your height*/
margin-left: -15em; /*set to a negative number 1/2 of your width*/
}
32 changes: 32 additions & 0 deletions Web Development/m3u8-player/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>M3U8 Player</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://unpkg.com/popper.js@1.12.3"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"
integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="home.css">
<script type="text/javascript" src="main.js"></script>
</head>

<body>
<div class="col-lg-6" id="text-box">
<h1 class="page-name">M3U8 Player</h1>
<div class="input-group">
<input type="text" class="form-control" placeholder="Paste the m3u8 link here" id="m3u8-placeholder">
<span class="input-group-btn">
<button class="btn btn-primary" type="button" id="play-btn">Play</button>
</span>
</div>

</div>
</body>

</html>
7 changes: 7 additions & 0 deletions Web Development/m3u8-player/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$(window).on('load', function () {
$('#m3u8-placeholder')[0].value = localStorage.getItem('m3u8-link') || '';
$('#play-btn').on('click', function () {
localStorage.setItem('m3u8-link', $('#m3u8-placeholder')[0].value);
window.location.href = './player' + '#' + $('#m3u8-placeholder')[0].value;
});
});
256 changes: 256 additions & 0 deletions Web Development/m3u8-player/player/index.html

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Web Development/m3u8-player/player/mousetrap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 140 additions & 0 deletions Web Development/m3u8-player/player/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
var video = document.getElementById("video");
var j = 0;

function playM3u8(url) {
if (Hls.isSupported()) {
video.volume = 0.3;
var hls = new Hls();
var m3u8Url = decodeURIComponent(url);
hls.loadSource(m3u8Url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
video.play();
});
document.title = url;
} else if (video.canPlayType("application/vnd.apple.mpegurl")) {
video.src = url;
video.addEventListener("canplay", function () {
video.play();
});
video.volume = 0.3;
document.title = url;
}
}

function playPause() {
video.paused ? video.play() : video.pause();
}

function volumeUp() {
if (video.volume <= 0.9) video.volume += 0.1;
}

function volumeDown() {
if (video.volume >= 0.1) video.volume -= 0.1;
}

function seekRight() {
video.currentTime += 5;
}

function seekLeft() {
video.currentTime -= 5;
}

function vidFullscreen() {
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen();
}
}

playM3u8(window.location.href.split("#")[1]);
$(window).on("load", function () {
$("#video").on("click", function () {
this.paused ? this.play() : this.pause();
});
Mousetrap.bind("space", playPause);
Mousetrap.bind("up", volumeUp);
Mousetrap.bind("down", volumeDown);
Mousetrap.bind("right", seekRight);
Mousetrap.bind("left", seekLeft);
Mousetrap.bind("f", vidFullscreen);
});

subreddit = ["IndianDankMemes","BikiniBottomTwitter", "AdviceAnimals", "MemeEconomy",
"ComedyCemetery", "memes", "PrequelMemes", "PewdiepieSubmissions",
"terriblefacebookmemes", "funny", "wholesomememes", "raimimemes",
"historymemes", "okbuddyretard", "im14andthisisdeep", "puns", "nnn",
"Community", "Puns", "IndianMeyMeys", "IndiaSpeaks", "IndianMemeTemplates", "indiameme",
"MemeAlleyway", "MemeChimera", "memeconvention", "india", "funnyindianvideo"
, "Indiafunny", "meme", "MemePiece", "dankvideos", "PlayItAgainSam"];
var randomInt = Math.floor(Math.random() * 33);
var sectionInt = Math.floor(Math.random() * 5);
sections = ["top", "", "new", "hot", "rising"];
console.log(subreddit[randomInt], sections[sectionInt]);

const api_url = `https://www.reddit.com/r/${subreddit[randomInt]}/${sections[sectionInt]}.json`;

var hls_urls = [];

async function getapi(url, int, int) {
const response = await fetch(url).then((d) => d.json());
for (let i = 0; i < response["data"]["children"].length; i++) {
try {
console.log(
response["data"]["children"][i]["data"]["media"]["reddit_video"][
"hls_url"
],
"hls url"
);
hls_urls.push(
response["data"]["children"][i]["data"]["media"]["reddit_video"][
"hls_url"
]
);
console.log(
response["data"]["children"][i]["data"]["permalink"],
"permalink"
);
} catch (error) {
const e = new ErrorEvent("error", { message: "my error", error: error });
window.dispatchEvent(e);
}
console.log(i);
}
}

getapi(api_url, 10, 10);

function nextVideo() {
$("#source").attr(
"src",
"https://v.redd.it/5xnc72zz72a81/HLSPlaylist.m3u8?a=1644069393%2CM2QzZWU0OWZlMDhkNDEzNGQ2OGVlZTZlNmMyYjZmOGU3NDk0MDUwZjdmYTkwNjIxYjk1YjgzZWIyYmZhYjMzYg%3D%3D&amp;v=1&amp;f=sd"
);
console.log("found");
}

console.log(hls_urls);

function delay(milisec) {
return new Promise(async (resolve) => {
setTimeout(() => {
resolve("");
}, milisec);
});
}

function next() {
playM3u8("https://yashdkadam.github.io/m3u8-player/player/#"+hls_urls[j]);
j++;
}

function load() {
navigator.clipboard.writeText(
"https://redditsave.com/info?url=" + hls_urls[j - 1]
);
}
Loading