metascraper-media-provider 5.26.1 → 5.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +23 -25
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-media-provider",
3
3
  "description": "Get video property from HTML markup",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-media-provider",
5
- "version": "5.26.1",
5
+ "version": "5.26.2",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -65,5 +65,5 @@
65
65
  "slow": 300,
66
66
  "timeout": "120000"
67
67
  },
68
- "gitHead": "4cfc804a4bcb54ffe335415f806ff909be0d3df5"
68
+ "gitHead": "e3289bbeeab1150e08759908230ce247e75050ce"
69
69
  }
package/src/index.js CHANGED
@@ -1,14 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const {
4
- chain,
5
- eq,
6
- find,
7
- isEmpty,
8
- includes,
9
- isNil,
10
- overEvery
11
- } = require('lodash')
3
+ const { chain, eq, find, isEmpty, isNil, negate, overEvery } = require('lodash')
12
4
 
13
5
  const {
14
6
  extension: extensionFn,
@@ -37,6 +29,10 @@ const isAac = isMIME('aac')
37
29
  const isWav = isMIME('wav')
38
30
  const isMpga = isMIME('mpga')
39
31
 
32
+ const isM3u8 = ({ url }) => new URL(url).pathname.endsWith('.m3u8')
33
+
34
+ const isMpd = ({ url }) => new URL(url).pathname.endsWith('.mpd')
35
+
40
36
  const hasCodec = prop => format => format[prop] !== 'none'
41
37
 
42
38
  const hasAudioCodec = hasCodec('acodec')
@@ -52,7 +48,8 @@ const hasAudio = format =>
52
48
  const hasVideo = format =>
53
49
  isNil(format.format_note) || !isNil(format.height) || !isNil(format.width)
54
50
 
55
- const notDownloadable = format => !includes(format.url, 'download=1')
51
+ const isDownloadable = ({ url }) =>
52
+ new URL(url).searchParams.get('download') === '1'
56
53
 
57
54
  const getFormatUrls = ({ orderBy }) => ({ formats }, filters) => {
58
55
  const url = chain(formats)
@@ -69,22 +66,23 @@ const getVideoUrls = getFormatUrls({ orderBy: 'tbr' })
69
66
 
70
67
  const getAudioUrls = getFormatUrls({ orderBy: 'abr' })
71
68
 
72
- const getVideo = data => {
73
- const videoFilters = [
74
- hasVideo,
75
- isMp4,
76
- isHttps,
77
- notDownloadable,
78
- hasVideoCodec
79
- ]
80
- return (
81
- getVideoUrls(data, [...videoFilters, hasAudioCodec]) ||
82
- getVideoUrls(data, videoFilters)
83
- )
84
- }
69
+ const VIDEO_FILTERS = [
70
+ hasVideo,
71
+ isMp4,
72
+ isHttps,
73
+ negate(isDownloadable),
74
+ negate(isM3u8),
75
+ negate(isMpd),
76
+ hasVideoCodec
77
+ ]
78
+
79
+ const AUDIO_FILTERS = [hasAudio, isHttps, negate(isDownloadable), hasAudioCodec]
80
+
81
+ const getVideo = data =>
82
+ getVideoUrls(data, [hasAudioCodec, ...VIDEO_FILTERS]) ||
83
+ getVideoUrls(data, VIDEO_FILTERS)
85
84
 
86
- const getAudio = data =>
87
- getAudioUrls(data, [hasAudio, isHttps, notDownloadable, hasAudioCodec])
85
+ const getAudio = data => getAudioUrls(data, AUDIO_FILTERS)
88
86
 
89
87
  const getAuthor = ({ uploader, creator, uploader_id: uploaderId }) =>
90
88
  find([creator, uploader, uploaderId], str => authorFn(str))