Advertisement
JanoriaCorven

Wordpress plugin for Mixer API

Aug 12th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. (function($) {
  2. /* trigger when page is ready */
  3. $(document).ready(function() {
  4. var mixerAPI = 'https://mixer.com/api/v1/channels/';
  5. var streamName = MixerUsername;
  6. var logo = swLogo;
  7. var apiCall = mixerAPI + streamName;
  8. $.ajax({
  9. url: apiCall,
  10. type: 'GET',
  11. headers: {
  12. 'Client-ID': '3385f3732ff772308b89485d4b3f7c81b0c69d05001af9b4'
  13. },
  14. success: function(data) {
  15. if(data.online) {
  16. $('body').addClass('online');
  17. $('.cp-header__indicator').addClass('cp-header__indicator--online');
  18. $('.cp-header__game-playing .cp-header__middle--line-2').text(data.name);
  19. $('.cp-nav__game-playing--line-2').text(data.name);
  20. $('.cp-header__viewers .cp-header__middle--line-2').text(data.viewersCurrent);
  21. $('.button--watch-now').attr('href', 'https://mixer.com/embed/player/' + streamName);
  22. console.log('Querying ' + streamName + ' - streamer online...', data.stream);
  23. } else {
  24. console.log('Querying ' + streamName + ' - streamer offline...', data);
  25. }
  26. },
  27. error: function(data) {
  28. console.log('Querying ' + streamName + ' - Mixer API error...', data);
  29. }
  30. });
  31.  
  32.  
  33.  
  34. function getStreamId(streamName){
  35. $.ajax({
  36. url: 'https://mixer.com/api/v1/users/'+streamName,
  37. type: 'GET',
  38. headers: {
  39. 'Client-ID': '3385f3732ff772308b89485d4b3f7c81b0c69d05001af9b4'
  40. },
  41. success: function(data) {
  42. ID = data.data[0].id;
  43. },
  44. error: function(data) {
  45. console.log('[Easy Embed Twitch] - Failed to retrieve StreamId')
  46. },
  47. complete: function(data) {
  48. console.log('[Easy Embed Twitch] - Success - retrieved StreamId')
  49. getVods(ID)
  50. }
  51. });
  52. }
  53.  
  54. function getVods(ID) {
  55. var videoURL = 'https://mixer.com/api/v1/user_id='+ID;
  56. $.ajax({
  57. url: videoURL,
  58. type: 'GET',
  59. headers: {
  60. 'Client-ID': '3385f3732ff772308b89485d4b3f7c81b0c69d05001af9b4'
  61. },
  62. success: function(data) {
  63. var vod = data.data;
  64. var vodThumb, vodURL, vodId, vodTitle, template;
  65. $('.cp-blog__stream').show();
  66. $('.cp-blog__posts').removeClass('cp-blog__posts--full-width');
  67. if (vod !== 0) {
  68. for (var i = 0; i < 6; i++) {
  69. preview = data.data[i].thumbnail_url;
  70. preview = preview.replace("%{height}", "176");
  71. preview = preview.replace("%{width}", "313");
  72. vodId = data.data[i].id;
  73. vodTitle = data.data[i].title;
  74. template = '<div class="cp-blog__vods-tile"><a class="cp-blog__vods-link button--modal" href="https://player.twitch.tv?video=' + vodId + '" target="_blank"><img class="cp-blog__vods-image" src="' + preview + '" /><h4 class="cp-blog__vods-title">' + vodTitle + '</h4><div class="cp-blog__vods-overlay"><span class="icon-play"></span></div></a></div>';
  75. $('.cp-blog__vods').append(template);
  76. }
  77. } else {
  78. console.log('no vods found, hiding vod section...');
  79. $('.cp-blog__stream').hide();
  80. $('.cp-blog__posts').addClass('cp-blog__posts--full-width');
  81. }
  82. },
  83. error: function(data) {
  84. console.log('no vods found, hiding vod section...');
  85. $('.cp-blog__stream').hide();
  86. $('.cp-blog__posts').addClass('cp-blog__posts--full-width');
  87. }
  88. });
  89. }
  90.  
  91. if ($('.cp-blog__vods').length) {
  92. getStreamId(streamName);
  93. }
  94.  
  95. $(document).on('click', '.cp-modal', function() {
  96. $('.cp-modal').removeClass('cp-modal--active');
  97. $('.cp-modal iframe').attr('src', '');
  98. });
  99.  
  100. $(document).on('click', '.button--modal', function(e) {
  101. e.preventDefault();
  102. var url = $(this).attr('href');
  103. $('.cp-modal iframe').attr('src', url);
  104. $('.cp-modal').addClass('cp-modal--active');
  105. });
  106.  
  107. if (!$('body').hasClass('broadcast-pro')) {
  108. if ($('.cp-affiliates').hasClass('cp-affiliates--hide')) {
  109. $('.cp-affiliates').removeClass('cp-affiliates--hide')
  110. }
  111. $('.cp-affiliates__wrapper').prepend('<a href="https://www.streamweasels.com/?affiliate=true" target="_blank"><img src="'+logo+'"></a>')
  112. }
  113.  
  114. });
  115. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement