<commit_before>import 'moment-duration-format';
import URL from 'url-parse';
import Duration from 'duration-js';

const YT_HOSTNAME_VARIANTS = [
  'www.youtube.com',
  'youtube.com',
  'www.youtu.be',
  'youtu.be'
];

const YT_VIDEO_ID = /^[\w\d-]{5,12}$/;

const isYouTubeVideoID = input => YT_VIDEO_ID.test(input);

const isYouTubeURL = url => YT_HOSTNAME_VARIANTS.indexOf(url.hostname) > -1;

function parseVideoIdFromURL(url) {
  const id = url.query.v;
  return isYouTubeVideoID(id) ? id : null;
}

function parseVideoDelayFromURL({ query: { t } }) {
  try {
    return new Duration(t).seconds();
  } catch (err) {
    return parseInt(t, 10);
  }
}
<commit_msg>make parsing work for video ids that are in url path instead of query params<commit_after>import _ from 'lodash';
import 'moment-duration-format';
import URL from 'url-parse';
import Duration from 'duration-js';

const YT_HOSTNAME_VARIANTS = [
  'www.youtube.com',
  'youtube.com',
  'www.youtu.be',
  'youtu.be'
];

const YT_VIDEO_ID = /^[\w\d-]{5,12}$/;

const isYouTubeVideoID = input => YT_VIDEO_ID.test(input);

const isYouTubeURL = url => YT_HOSTNAME_VARIANTS.includes(url.hostname);

function parseVideoIdFromURL(url) {
  let id = url.query.v;
  if (id == null) {
    id = url.query.v || _.chain(url).split('/').last().value();
  }
  return isYouTubeVideoID(id) ? id : null;
}

function parseVideoDelayFromURL({ query: { t } }) {
  try {
    return new Duration(t).seconds();
  } catch (err) {
    return parseInt(t, 10);
  }
}

{'fraction_non_alphanumeric': 0.15989340439706862, 'fraction_numerical': 0.0073284477015323115, 'mean_word_length': 4.074324324324325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '764211', 'n_tokens_mistral': 577, 'n_tokens_neox': 576, 'n_words': 122}