Advertisement
niammuddin

youtube audio player

Aug 24th, 2018
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <script>
  2. var vid = "fUDKIOZ5OvE",
  3. audio_streams = {};
  4.  
  5. $.get('https://cors-anywhere.herokuapp.com/https://www.youtube.com/get_video_info?video_id=' + vid, function(data) {
  6. var data = parse_str(data),
  7. streams = (data.url_encoded_fmt_stream_map + ',' + data.adaptive_fmts).split(',');
  8. console.log(streams);
  9. $.each(streams, function(n, s) {
  10. var stream = parse_str(s),
  11. itag = stream.itag * 1,
  12. quality = false;
  13. console.log(stream);
  14. switch (itag) {
  15. case 139:
  16. quality = "48kbps";
  17. break;
  18. case 140:
  19. quality = "128kbps";
  20. break;
  21. case 141:
  22. quality = "256kbps";
  23. break;
  24. }
  25. if (quality) audio_streams[quality] = stream.url;
  26. });
  27. console.log(audio_streams);
  28. $("#youtube").attr({
  29. src: audio_streams['128kbps']
  30. });
  31. });
  32.  
  33. function parse_str(str) {
  34. return str.split('&').reduce(function(params, param) {
  35. var paramSplit = param.split('=').map(function(value) {
  36. return decodeURIComponent(value.replace('+', ' '));
  37. });
  38. params[paramSplit[0]] = paramSplit[1];
  39. return params;
  40. }, {});
  41. }
  42. </script>
  43. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  44. <audio id="youtube" autoplay controls loop></audio>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement