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

18
LINES

< > BotCompany Repo | #1013874 // playRandomSoundFromFreesoundOrg

JavaX fragment (include)

1  
static File playRandomSoundFromFreesoundOrg(S query) {
2  
  print("Freesound search: " + query);
3  
  S url = "https://freesound.org/search/?q=" + urlencode(query);
4  
  S html = loadPage(url);
5  
  L<S> tok = htmlTok(html);
6  
  LL<S> tags = findContainerTagWithParams(tok, 'a, class := 'mp3_file);
7  
  L<S> tag = random(tags);
8  
  if (tag == null) null;
9  
  L<S> duration = first(findContainerTagWithParams(
10  
    subList(tok, indexOfSubList(tok, tag)-1), 'span,  class := 'duration));
11  
  printStruct(+duration);
12  
  S mp3 = "https://freesound.org" + getTagParam(second(tag), "href");
13  
  File mp3File = programFile(urlencode(mp3));
14  
  if (fileLength(mp3File) == 0)
15  
    loadBinaryPageToFile(mp3, mp3File);
16  
  playMP3(mp3File);
17  
  ret mp3File;
18  
}

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: 371 / 388
Version history: 6 change(s)
Referenced in: [show references]