<commit_before>import { calcDuration, convertSecToHHMMSS, throttle, isNonAnonLoggedInUser,
         readableDate, secondsToReadableDuration } from './utility.js';
import { subscribeToPodcast, unsubscribeFromPodcast } from './podcastHelper.js';
import { requestClipsFromAPI } from './clipHelper.js';
import { sendGoogleAnalyticsPlayerPageView,
         sendGoogleAnalyticsEvent } from './googleAnalytics.js';
import { isMobileOrTablet } from './browserSupportDetection.js';
import { allowedFilters, checkIfFilterIsAllowed } from '../../../constants.js';
const he = require('he');
const Autolinker = require('autolinker');
const stripTags = require('striptags');


// Set default values for vars that handle player crashes and autoplay functionality
window.restartAttempts = 0;
window.lastPlaybackPosition = -1;
window.endTimeHasBeenReached = false;

// Load the player
if (isEmptyPlaylist !== true) {
  $('#player').append('<i class="fa fa-spinner fa-spin"></i>');

  if (isNonAnonLoggedInUser()) {
    $('#toggle-playlist-btn, #toggle-recommend-btn').css('display', 'inline-block');
  }

  setPlayerInfo();
  setSubscribedStatus();
  createAutoplayBtn();
  checkIfEpisodeMediaFileIsFound(createAndAppendAudio, showEpisodeNotFoundMessage);
  onScrollCondensePlayerView();
} else {
  var isEmptyPlaylistEl = '<div id="empty-playlist-message">This playlist has no episodes or clips added to it.</div>';
  $(isEmptyPlaylistEl).insertAfter('#player');
}

if (!isPlaylist) {
  let params = {};
  params.podcastFeedURL = window.podcastFeedURL;
  params.filterType = 'pastMonth';

  var spinnerEl = $('<div class="load-clips-spinner"><i class="fa fa-spinner fa-spin"><i></div>');
  $(spinnerEl).insertAfter('.sort-by-dropdown.dropdown')

  requestClipsFromAPI(params)
  .then(clips => {
    loadClipsAsPlaylistItems(clips);
    $(spinnerEl).hide();
  })
  .catch(err => {
    console.log(err);
    $(spinnerEl).hide();
  });
} else {
  setPlaylistItemClickEvents();
}

function loadClipsAsPlaylistItems (clips) {
  $('#playlist .playlist-item').remove();

  let html  = '';

  for (let clip of clips) {

    let truncTitle;
    if (clip.title && clip.title.length > 340) {
      truncTitle = clip.title.substr(0, 340);
      truncTitle += '...';
    }

    let clipDuration = calcDuration(clip.startTime, clip.endTime);

    html += `<div class="playlist-item" data-media-ref-id="${clip.id}" tabindex="0">`;
    html +=   '<div class="playlist-item-podcast-title">';
    html +=     truncTitle || clip.title;
    html +=   '</div>';
    html +=   '<div class="playlist-item-sub-title">'
    html +=     clip.episodeTitle;
    html +=   '</div>';
    html +=   '<div class="playlist-item-time">';
    html +=     'Clip: ';
    html +=     convertSecToHHMMSS(clip.startTime);<commit_msg>Fix bug with request clips spinner showing when a function menu is toggled<commit_after>import { calcDuration, convertSecToHHMMSS, throttle, isNonAnonLoggedInUser,
         readableDate, secondsToReadableDuration } from './utility.js';
import { subscribeToPodcast, unsubscribeFromPodcast } from './podcastHelper.js';
import { requestClipsFromAPI } from './clipHelper.js';
import { sendGoogleAnalyticsPlayerPageView,
         sendGoogleAnalyticsEvent } from './googleAnalytics.js';
import { isMobileOrTablet } from './browserSupportDetection.js';
import { allowedFilters, checkIfFilterIsAllowed } from '../../../constants.js';
const he = require('he');
const Autolinker = require('autolinker');
const stripTags = require('striptags');


// Set default values for vars that handle player crashes and autoplay functionality
window.restartAttempts = 0;
window.lastPlaybackPosition = -1;
window.endTimeHasBeenReached = false;

// Load the player
if (isEmptyPlaylist !== true) {
  $('#player').append('<i class="fa fa-spinner fa-spin"></i>');

  if (isNonAnonLoggedInUser()) {
    $('#toggle-playlist-btn, #toggle-recommend-btn').css('display', 'inline-block');
  }

  setPlayerInfo();
  setSubscribedStatus();
  createAutoplayBtn();
  checkIfEpisodeMediaFileIsFound(createAndAppendAudio, showEpisodeNotFoundMessage);
  onScrollCondensePlayerView();
} else {
  var isEmptyPlaylistEl = '<div id="empty-playlist-message">This playlist has no episodes or clips added to it.</div>';
  $(isEmptyPlaylistEl).insertAfter('#player');
}

if (!isPlaylist) {
  let params = {};
  params.podcastFeedURL = window.podcastFeedURL;
  params.filterType = 'pastMonth';

  var spinnerEl = $('<div class="load-clips-spinner"><i class="fa fa-spinner fa-spin"><i></div>');
  $(spinnerEl).insertAfter('.sort-by-dropdown.dropdown');

  requestClipsFromAPI(params)
  .then(clips => {
    $(spinnerEl).remove();
    loadClipsAsPlaylistItems(clips);
  })
  .catch(err => {
    console.log(err);
    $(spinnerEl).remove();
  });
} else {
  setPlaylistItemClickEvents();
}

function loadClipsAsPlaylistItems (clips) {
  $('#playlist .playlist-item').remove();

  let html  = '';

  for (let clip of clips) {

    let truncTitle;
    if (clip.title && clip.title.length > 340) {
      truncTitle = clip.title.substr(0, 340);
      truncTitle += '...';
    }

    let clipDuration = calcDuration(clip.startTime, clip.endTime);

    html += `<div class="playlist-item" data-media-ref-id="${clip.id}" tabindex="0">`;
    html +=   '<div class="playlist-item-podcast-title">';
    html +=     truncTitle || clip.title;
    html +=   '</div>';
    html +=   '<div class="playlist-item-sub-title">'
    html +=     clip.episodeTitle;
    html +=   '</div>';
    html +=   '<div class="playlist-item-time">';
    html +=     'Clip: ';
    html +=     convertSecToHHMMSS(clip.startTime);
{'fraction_non_alphanumeric': 0.16067615658362988, 'fraction_numerical': 0.0035587188612099642, 'mean_word_length': 4.228837209302325, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908655', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1785, 'n_words': 357}