-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
169 lines (135 loc) · 4.67 KB
/
index.js
File metadata and controls
169 lines (135 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
Copyright 2018 LNFWebsite
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
**/
// Audius Import functions
var playlistName = null;
function audiusConvert(data) {
data = data["entities"];
console.log(playlistName);
if (playlistName === "undefined") {
playlistName = null;
}
if (playlistName !== null) {
playlistName = encodeURIComponent(playlistName).replace(/%20/g, " ");
}
var videos = [playlistName];
playlistName = null;
$.each(data, function(index, value) {
var video = [];
video[0] = encodeURIComponent(value["title"]).replace(/%20/g, " ");
video[1] = value["durationS"];
video[2] = index;
videos.push(video);
});
return videos;
}
function audiusInput() {
function loadPlaylist(input) {
try {
var playlist = audiusConvert(input);
playlist = JSON.stringify(playlist);
playlist = window.btoa(playlist);
playlist = "https://lnfwebsite.github.io/Streamly/#" + playlist;
window.location.href = playlist;
} catch (e) {
alert("Whoops, it seems that your playlist didn't load correctly\n\nTry copying again");
$("#audiusInput").val("");
return false;
}
}
var input = $("#audiusInput").val();
//https://audius.rockdapus.org/?import=https://api.myjson.com/bins/m7pxt&type=playList&title=PLAYLSIT
if (input.indexOf("myjson.com") !== -1) {
if (input.indexOf("audius.rockdapus.org") !== -1) {
var url = new URL(input);
input = url.searchParams.get("import");
playlistName = url.searchParams.get("title");
}
$.get(input, function (data, textStatus, jqXHR) {
loadPlaylist(data);
}).fail(function() {
alert("Whoops, it seems that your playlist didn't load correctly\n\nTry copying again");
$("#audiusInput").val("");
});
}
else {
try {
input = JSON.parse(input);
} catch(e) {};
loadPlaylist(input);
}
}
// Streamus Import functions
function streamusURLInput() {
var input = $("#streamusURLInput").val();
var regex = /^http(|s):\/\/streamus.com\/share\/playlist\/.*\/.*$/i;
input = input.trim();
input = input.match(regex);
if (input !== null) {
window.open(input[0] + "/json");
$("#streamusJSONInput").focus();
}
else {
alert("That doesn't appear to be a valid Streamus playlist\n\nTry copying the URL again");
}
}
function streamusJSONInput() {
var streamusJSON = $("#streamusJSONInput").val();
try {
var streamusPlaylist = JSON.parse(streamusJSON);
} catch (e) {
alert("Whoops, it seems that something's wrong with the data you entered\n\nTry copying again");
return false;
}
var videos = [];
var playlistName = streamusPlaylist["title"];
playlistName = playlistName.trim();
playlistName = encodeURIComponent(playlistName).replace(/%20/g, " ");
videos[0] = playlistName;
var streamusVideos = streamusPlaylist["items"];
for (i = 0; i < streamusVideos.length; i++) {
var streamusVideo = streamusVideos[i]["video"];
var video = [];
var videoName = streamusVideo["title"];
videoName = videoName.trim();
videoName = encodeURIComponent(videoName).replace(/%20/g, " ");
video[0] = videoName;
video[1] = streamusVideo["duration"];
video[2] = streamusVideo["id"];
videos.push(video);
}
var playlist = JSON.stringify(videos);
playlist = window.btoa(playlist);
window.open("https://lnfwebsite.github.io/Streamly/#" + playlist);
}
function streamusFileInput() {
var streamusFile = $("#streamusFileInput").val();
if (/.+?,.+?,.+?,.+?,\d+?/i.test(streamusFile)) {
streamusFile = streamusFile.split("\n");
var videos = [];
videos[0] = null;
for (var i = 0; i < streamusFile.length; i++) {
streamusFile[i] = streamusFile[i].split(",");
var video = [];
video[0] = streamusFile[i][0];
video[1] = +streamusFile[i][4];
video[2] = streamusFile[i][1];
videos.push(video);
}
var playlist = JSON.stringify(videos);
playlist = window.btoa(playlist);
window.open("https://lnfwebsite.github.io/Streamly/#" + playlist);
}
else {
alert("Whoops, it seems that something's wrong with the data you entered\n\nTry copying again");
}
}