-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tool to convert YouTube subscription to LBRY
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}) |