Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
refactor: avoid url.pase
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 18, 2021
1 parent 54f5234 commit b9633c7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const universalify = require('universalify')
const streamify = require('streamify')
const request = require('request')
const path = require('path')
const hms = require('hh-mm-ss')
const { URL } = require('url')
const path = require('path')
const http = require('http')
const url = require('url')

const {
isYouTubeRegex,
Expand Down Expand Up @@ -46,7 +46,7 @@ function processData (data, args, options, stream) {

// fix for pause/resume downloads
const headers = Object.assign(
{ Host: url.parse(item.url).hostname },
{ Host: new URL(item.url).hostname },
data.http_headers
)

Expand Down Expand Up @@ -143,13 +143,13 @@ function call (urls, args1, args2, options = {}, cb) {
const video = urls[i]
if (isYouTubeRegex.test(video)) {
// Get possible IDs.
const details = url.parse(video, true)
let id = details.query.v || ''
const videoUrlObj = new URL(video)
let id = videoUrlObj.searchParams.get('v') || ''
if (id) {
args.push('http://www.youtube.com/watch?v=' + id)
} else {
// Get possible IDs for youtu.be from urladdr.
id = details.pathname.slice(1).replace(/^v\//, '')
id = videoUrlObj.pathname.slice(1).replace(/^v\//, '')
if (id) {
args.push(video)
args.unshift('-i')
Expand Down

0 comments on commit b9633c7

Please sign in to comment.