Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-youtube-api

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-youtube-api - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

out/types/ISODuration.js

7

out/entities/Video.js

@@ -11,2 +11,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("../util");
/**

@@ -24,5 +25,5 @@ * A YouTube video.

const video = data;
this._length = video.contentDetails.duration;
this.minutes = parseInt(this._length.substring(this._length.indexOf('PT') + 2, this._length.indexOf('M')));
this.seconds = parseInt(this._length.substring(this._length.indexOf('M') + 1, this._length.length - 1));
this._length = util_1.parseIsoDuration(video.contentDetails.duration);
this.minutes = (this._length.hours * 60) + this._length.minutes;
this.seconds = this._length.minutes;
this.likes = Number(video.statistics.likeCount);

@@ -29,0 +30,0 @@ this.dislikes = Number(video.statistics.dislikeCount);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url_1 = require("url");
const numbers = '\\d+(?:[\\.,]\\d{0,3})?';
const weekPattern = `(${numbers}W)`;
const datePattern = `(${numbers}Y)?(${numbers}M)?(${numbers}D)?`;
const timePattern = `T(${numbers}H)?(${numbers}M)?(${numbers}S)?`;
const iso8601 = `P(?:${weekPattern}|${datePattern}(?:${timePattern})?)`;
const timeArray = ['weeks', 'years', 'months', 'days', 'hours', 'minutes', 'seconds'];
const pattern = new RegExp(iso8601);
function parseUrl(url) {

@@ -43,1 +50,8 @@ const parsed = url_1.parse(url, true);

exports.parseUrl = parseUrl;
function parseIsoDuration(duration) {
return duration.match(pattern).slice(1).reduce((prev, current, index) => {
prev[timeArray[index]] = parseFloat(current) || 0;
return prev;
}, { weeks: 0, years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0 });
}
exports.parseIsoDuration = parseIsoDuration;
{
"name": "better-youtube-api",
"version": "0.3.2",
"version": "0.3.3",
"description": "A very easy to use promise-based Youtube Data v3 API.",

@@ -5,0 +5,0 @@ "main": "out/index.js",

import { YouTube } from '..'
import { Thumbnail } from '../types'
import { Thumbnail, ISODuration } from '../types'
import { YTComment } from './Comment'
import { parseIsoDuration } from '../util'

@@ -60,3 +61,3 @@ /**

private _length: string
private _length: ISODuration

@@ -122,5 +123,5 @@ /**

this._length = video.contentDetails.duration
this.minutes = parseInt(this._length.substring(this._length.indexOf('PT') + 2, this._length.indexOf('M')))
this.seconds = parseInt(this._length.substring(this._length.indexOf('M') + 1, this._length.length - 1))
this._length = parseIsoDuration(video.contentDetails.duration)
this.minutes = (this._length.hours * 60) + this._length.minutes
this.seconds = this._length.minutes

@@ -127,0 +128,0 @@ this.likes = Number(video.statistics.likeCount)

export * from './Thumbnail'
export * from './ISODuration'
import { parse } from 'url'
import { ISODuration } from '../types'
const numbers = '\\d+(?:[\\.,]\\d{0,3})?'
const weekPattern = `(${numbers}W)`
const datePattern = `(${numbers}Y)?(${numbers}M)?(${numbers}D)?`
const timePattern = `T(${numbers}H)?(${numbers}M)?(${numbers}S)?`
const iso8601 = `P(?:${weekPattern}|${datePattern}(?:${timePattern})?)`
const timeArray = ['weeks', 'years', 'months', 'days', 'hours', 'minutes', 'seconds']
const pattern = new RegExp(iso8601)
export function parseUrl (url: string): { video: string, playlist: string, channel: string } {

@@ -47,1 +56,8 @@ const parsed = parse(url, true)

}
export function parseIsoDuration (duration: string): ISODuration {
return duration.match(pattern).slice(1).reduce((prev, current, index) => {
prev[timeArray[index]] = parseFloat(current) || 0
return prev
}, { weeks: 0, years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0 })
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc