Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use @kikobeats/time-span #664

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
]
},
"nano-staged": {
"*.js,!*.min.js": [
"*.js": [
"prettier-standard",
"standard --fix"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-audio/test/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ test('transistor.fm (twitter:player)', async t => {

t.is(
metadata.audio,
'https://media.transistor.fm/e83b42d0/9e93424b.mp3?src=player'
'https://chrt.fm/track/637E/2.gum.fm/op3.dev/e/dts.podtrac.com/redirect.mp3/media.transistor.fm/e83b42d0/9e93424b.mp3?src=player'
)
})
53 changes: 0 additions & 53 deletions packages/metascraper-audio/test/snapshots/providers.js.md

This file was deleted.

Binary file not shown.
5 changes: 2 additions & 3 deletions packages/metascraper-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,10 @@ memoizeOne.EqualityUrlAndHtmlDom = (newArgs, oldArgs) =>
const jsonld = memoizeOne(
$ =>
$('script[type="application/ld+json"]')
.map(function () {
.map((_, element) => {
try {
const el = $(this)
const el = $(element)
const json = JSON.parse($(el).contents().text())

const { '@graph': graph, ...props } = json
if (!graph) return json
return graph.map(item => ({ ...props, ...item }))
Expand Down
9 changes: 5 additions & 4 deletions packages/metascraper-media-provider/bench/provider/generic.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict'

const timeSpan = require('@kikobeats/time-span')({
format: require('pretty-ms')
})
const debug = require('debug-logfmt')(
'metascraper-media-provider:bench:generic'
)
const timeSpan = require('time-span')
const prettyMs = require('pretty-ms')

const createFromGeneric = require('../../src/get-media/provider/generic')
const { getUrl, ...opts } = require('../constants')
Expand All @@ -17,12 +18,12 @@ const mainLoop = async () => {
let error = false
while (!error) {
try {
const end = timeSpan()
const duration = timeSpan()
const url = getUrl()
const media = await fromGeneric(getUrl())
const hasMedia = !!media && !!media.extractor

debug({ n: n++, hasMedia, time: prettyMs(end()) })
debug({ n: n++, hasMedia, duration: duration() })

if (!hasMedia) {
const err = new Error(`No media detected for '${url}'`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict'

const timeSpan = require('@kikobeats/time-span')({
format: require('pretty-ms')
})
const debug = require('debug-logfmt')(
'metascraper-media-provider:bench:twitter'
)
const prettyMs = require('pretty-ms')
const timeSpan = require('time-span')

const {
createGuestToken,
Expand All @@ -21,11 +22,11 @@ const mainLoop = async () => {
let error = false
while (!error) {
try {
const end = timeSpan()
const duration = timeSpan()
const data = await twitterVideo(getUrl())
const hasVideo = data && data.formats && data.formats.length > 0

debug({ n: n++, hasVideo, time: prettyMs(end()) })
debug({ n: n++, hasVideo, duration: duration() })

if (!hasVideo) {
const err = new Error('No video detected!')
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-media-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"youtube-dl-exec": "~2.4.12"
},
"devDependencies": {
"@kikobeats/time-span": "latest",
"ava": "latest",
"parse-proxy-uri": "latest",
"pretty-ms": "latest",
"time-span": "4",
"unique-random-array": "2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-spotify/test/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Generated by [AVA](https://avajs.dev).
author: 'Syntax - Tasty Web Development Treats',
date: '2020-01-06T14:00:00.000Z',
description: 'In this Hasty Treat, Scott and Wes talk about modules in Node — what are they, how they’re different from browser modules, and more! Sentry - Sponsor If you want to know what’s happening with your errors, track them with Sentry. Sentry is open-source error tracking that helps developers monitor and…',
image: 'https://i.scdn.co/image/28df6337d6538a093fa1092a979a1f0f95f70992',
image: 'https://i.scdn.co/image/ab6765630000ba8a6c0e28e162c68d0e67bc10d5',
lang: 'en',
publisher: 'Spotify',
title: 'Hasty Treat - Modules in Node',
Expand Down
Binary file modified packages/metascraper-spotify/test/snapshots/index.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/metascraper-youtube/test/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Generated by [AVA](https://avajs.dev).
{
author: 'Elon Musk Viral Videos',
description: 'Subscribe for daily Elon Musk videos.',
image: 'https://img.youtube.com/vi/rXyKq7izYCQ/sddefault.jpg',
image: 'https://i.ytimg.com/vi/rXyKq7izYCQ/hqdefault.jpg',
lang: 'es',
logo: 'https://www.youtube.com/yts/img/favicon_144-vfliLAfaB.png',
publisher: 'YouTube',
Expand Down
Binary file modified packages/metascraper-youtube/test/snapshots/index.js.snap
Binary file not shown.