Skip to content

Commit

Permalink
use random music
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Apr 30, 2024
1 parent 1117a36 commit b8e0383
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<div id="userInfo"></div>
<pre></pre>
<div id="soundInfo">
<a target="_blank" id="soundcloud"><img src="https://developers.soundcloud.com/assets/logo_white-af5006050dd9cba09b0c48be04feac57.png" /></a>
<a target="_blank" class="shrink" id="bandLink"></a>
<div id="soundTime" class="shrink"><a target="_blank" id="soundLink"></a></div>
</div>
Expand Down Expand Up @@ -194,5 +193,9 @@ <h1>saving</h1>
</pre>
</div>
</body>
<script data-main="js/start.js" src="3rdparty/require.js"></script>
<script type="module">
import getRandomMusic from 'https://greggman.github.io/music-lists/get-random-music.js';
window.getRandomMusic = getRandomMusic;
</script>
<script defer data-main="js/start.js" src="3rdparty/require.js"></script>
</html>
46 changes: 29 additions & 17 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ define([
var soundTime = $("#soundTime");
var soundLinkElem = $("#soundLink");
var soundLinkNode = misc.createTextNode(soundLinkElem);
var soundcloudElem = $("#soundcloud");
var bandLinkElem = $("#bandLink");
var bandLinkNode = misc.createTextNode(bandLinkElem);
var soundTimeElem = $("#soundTime");
Expand Down Expand Up @@ -998,14 +997,15 @@ define([
if (isMic(src)) {
s.streamSource.setSource(src);
} else {
s.sc.getRealStreamURL(src, function(err, url) {
if (err) {
console.log(err);
return;
}
console.log('headurl:', url);
s.streamSource.setSource(url);
});
//s.sc.getRealStreamURL(src, function(err, url) {
// if (err) {
// console.log(err);
// return;
// }
// console.log('headurl:', url);
// s.streamSource.setSource(url);
//});
s.streamSource.setSource(src);
}
}

Expand Down Expand Up @@ -1053,12 +1053,13 @@ define([
function setSoundLink(options) {
options = options || {};
options.user = options.user || {};
setLinkOrHide(soundLinkElem, options.permalink_url);
setLinkOrHide(bandLinkElem, options.user.permalink_url);
setLinkOrHide(soundcloudElem, options.permalink_url);
setLinkOrHide(soundTimeElem, options.permalink_url);
soundLinkNode.nodeValue = options.title || "";
bandLinkNode.nodeValue = options.user.username || "";
const trackLink = options.infoUrl || options.permalink_url || options.url;
setLinkOrHide(soundLinkElem, trackLink);
setLinkOrHide(bandLinkElem, options.url || options.user.permalink_url);
//setLinkOrHide(soundcloudElem, trackLink);
setLinkOrHide(soundTimeElem, trackLink);
soundLinkNode.nodeValue = options.name || options.title || "";
bandLinkNode.nodeValue = options.author || options.user.username || "";
if (s.cm) {
s.cm.refresh();
}
Expand All @@ -1082,7 +1083,7 @@ define([
setSoundLink();
s.gainNode.gain.value = track === 'feedback' ? 1 : 0;
} else {
var src = track.stream_url;// + '?client_id=' + g.soundCloudClientId;
var src = track.stream_url || track.trackUrl;// + '?client_id=' + g.soundCloudClientId;
setSoundSource(src);
setSoundLink(track);
s.gainNode.gain.value = 1;
Expand All @@ -1108,7 +1109,13 @@ define([
s.trackNdx = 0;
s.playlist = [url];
playNextTrack();
} else {
} else if (url.includes('soundcloud') || url === 'random') {
getRandomMusic().then(track => {
s.playlist = [track];
s.trackNdx = 0;
playNextTrack();
});
/*
fetch(`/resolve?${new URLSearchParams({format: 'json', url})}`)
.then(res => res.json())
.then(result => {
Expand All @@ -1130,6 +1137,11 @@ define([
console.error("bad url:", url, err);
setSoundSuccessState(false, "not a valid soundcloud url? " + (err.message ? err.message : ""));
});
*/
} else {
s.playList = [track];
s.trackNdx = 0;
playNextTrack();
}
}

Expand Down

0 comments on commit b8e0383

Please sign in to comment.