Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1013874 // playRandomSoundFromFreesoundOrg

JavaX fragment (include)

static File playRandomSoundFromFreesoundOrg(S query) {
  print("Freesound search: " + query);
  S url = "https://freesound.org/search/?q=" + urlencode(query);
  S html = loadPage(url);
  L<S> tok = htmlTok(html);
  LL<S> tags = findContainerTagWithParams(tok, 'a, class := 'mp3_file);
  L<S> tag = random(tags);
  if (tag == null) null;
  L<S> duration = first(findContainerTagWithParams(
    subList(tok, indexOfSubList(tok, tag)-1), 'span,  class := 'duration));
  printStruct(+duration);
  S mp3 = "https://freesound.org" + getTagParam(second(tag), "href");
  File mp3File = programFile(urlencode(mp3));
  if (fileLength(mp3File) == 0)
    loadBinaryPageToFile(mp3, mp3File);
  playMP3(mp3File);
  ret mp3File;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1013874
Snippet name: playRandomSoundFromFreesoundOrg
Eternal ID of this version: #1013874/7
Text MD5: eecb8bae7cc62310af5e1d18d7f8706a
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-09 13:48:09
Source code size: 732 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 368 / 384
Version history: 6 change(s)
Referenced in: [show references]