mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-31 01:11:31 +00:00
Added YTtoLBRY
Added tool to convert YouTube subscription to LBRY
This commit is contained in:
parent
3b642891cd
commit
77d6476ea2
3 changed files with 147 additions and 0 deletions
36
tools/YTtoLBRY.css
Normal file
36
tools/YTtoLBRY.css
Normal file
|
@ -0,0 +1,36 @@
|
|||
body {
|
||||
width: 400px;
|
||||
text-align: center;
|
||||
background-color: #191a1c;
|
||||
color: whitesmoke;
|
||||
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: block;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
width: 80%;
|
||||
margin-bottom: 15px;
|
||||
|
||||
}
|
||||
|
||||
.goButton {
|
||||
border-radius: 5px;
|
||||
background-color: #075656;
|
||||
border: 4px solid #075656;
|
||||
color: whitesmoke;
|
||||
font-weight: 400;
|
||||
padding: 4px 15px;
|
||||
margin-right: 25px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
label {
|
||||
font-size: 1.1rem;
|
||||
margin: 15px auto;
|
||||
display: block;
|
||||
}
|
20
tools/YTtoLBRY.html
Normal file
20
tools/YTtoLBRY.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<link rel="stylesheet" href="YTtoLBRY.css" />
|
||||
<meta charset="utf-8">
|
||||
<title>Subscribtion Converter</title>
|
||||
<script src="YTtoLBRY.js" charset="utf-8"></script>
|
||||
</head>
|
||||
<body>
|
||||
<iframe width="560" height="315" src="https://lbry.tv/$/embed/howtouseconverter/c9827448d6ac7a74ecdb972c5cdf9ddaf648a28e" allowfullscreen></iframe>
|
||||
<label for="file">Select Youtube Subscriptions</label>
|
||||
<input type="file" id="subconv" class=PickFile>
|
||||
<input type="button" id="go-button" value="GO" class=goButton >
|
||||
<ul id="lbry-channel-list">
|
||||
</ul>
|
||||
<script type="text/javascript" src="content.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
91
tools/YTtoLBRY.js
Normal file
91
tools/YTtoLBRY.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
console.log("YouTube To LBRY finder!");
|
||||
var ytChannelsString = "";
|
||||
var lbryChannelsString = "";
|
||||
let lbryArray = [];
|
||||
var toCheck = [];
|
||||
let tempJson = {"0":0};
|
||||
var subconv;
|
||||
var goButton;
|
||||
var lbryChannelList;
|
||||
|
||||
window.addEventListener('load', (event) => {
|
||||
subconv = document.getElementById("subconv");
|
||||
goButton = document.getElementById("go-button");
|
||||
lbryChannelList = document.getElementById("lbry-channel-list");
|
||||
|
||||
goButton.addEventListener('click', () => onGoClicked());
|
||||
});
|
||||
|
||||
function getFile(file) {
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('load', (event) => {
|
||||
var content = event.target.result;
|
||||
content = content.replace('<opml version="1.1">','');
|
||||
content = content.replace('<body>','');
|
||||
content = content.replace('/><outline','');
|
||||
content = content.replace('</outline></body></opml>',' ');
|
||||
splitChannels = content.split("=");
|
||||
toCheck = [];
|
||||
for (var i = 0; i <= splitChannels.length-1; i++) {
|
||||
tempChannel = splitChannels[i];
|
||||
if (tempChannel.indexOf("outline text")>=29) {
|
||||
toCheck[toCheck.length] = tempChannel.slice(0, tempChannel.indexOf("outline text")-5);
|
||||
}
|
||||
}
|
||||
lbryAPIrequest();
|
||||
});
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
function onGoClicked() {
|
||||
if (subconv.files.length > 0) {
|
||||
getFile(subconv.files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function lbryAPIrequest() {
|
||||
// Clear current channel list
|
||||
while (lbryChannelList.lastElementChild) {
|
||||
lbryChannelList.removeChild(lbryChannelList.lastElementChild);
|
||||
}
|
||||
|
||||
chrome.storage.local.get('redirect', redirect => {
|
||||
validateChannels(toCheck, redirect.redirect);
|
||||
});
|
||||
}
|
||||
|
||||
function validateChannels(channels, redirect) {
|
||||
const requestSize = 325;
|
||||
var channelsString = "";
|
||||
for (let i = 0; i < channels.length && i < requestSize; i++) {
|
||||
channelsString += `${channelsString.length > 0 ? ',' : ''}${channels[i]}`
|
||||
}
|
||||
request = new XMLHttpRequest();
|
||||
request.open("GET", `https://api.lbry.com/yt/resolve?channel_ids={${channelsString}}`);
|
||||
request.send();
|
||||
request.onload = () => {
|
||||
if (request.status == 200) {
|
||||
var testChannels = JSON.parse(request.responseText).data.channels;
|
||||
Object.keys(testChannels).map((testChannelKey) => {
|
||||
let testChannel = testChannels[testChannelKey];
|
||||
if (testChannel != null) {
|
||||
let link = `${redirect === "lbry.tv" ? "https://lbry.tv/" : "lbry://"}${testChannel}`;
|
||||
let li = document.createElement('li');
|
||||
let a = document.createElement('a');
|
||||
a.href = link;
|
||||
a.innerText = link;
|
||||
li.appendChild(a);
|
||||
lbryChannelList.appendChild(li);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (requestSize < channels.length) {
|
||||
channels.splice(0, requestSize);
|
||||
validateChannels(channels, redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chrome.storage.local.get('redirect', redirect => {
|
||||
console.log(redirect);
|
||||
})
|
Loading…
Add table
Reference in a new issue