Skip to content

Commit

Permalink
Fix for download videos to network shared folder + resolved conflict …
Browse files Browse the repository at this point in the history
…if output youtube-dl option + download path is provided together (#91)

* Slash character replaced by DIRECTORY_SEPARATOR const

* fix error if downloadPath + output option is combined in same download request

* code style restored

* some braces added following the standard

* comparation edited to comply with the standard

* logic simplified (no extra parameters in constructor is needed).

* code styles

* restored code & small improvements reading the output.
  • Loading branch information
jacksnchz authored and norkunas committed Jun 5, 2019
1 parent de944a1 commit 32afb1b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/YoutubeDl.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function processDownload(Process $process): Video
throw new YoutubeDlException('Failed to detect metadata file.');
}

$metadataFile = $this->downloadPath.'/'.$m[1];
$metadataFile = $this->downloadPath.DIRECTORY_SEPARATOR.basename($m[1]);

$videoData = $this->jsonDecode(trim(file_get_contents($metadataFile)));

Expand All @@ -204,7 +204,7 @@ protected function processDownload(Process $process): Video
$videoData['_filename'] = pathinfo($this->findFile($videoData['_filename'], 'mkv'), PATHINFO_BASENAME);
}

$videoData['file'] = new \SplFileInfo($this->downloadPath.'/'.$videoData['_filename']);
$videoData['file'] = new \SplFileInfo($this->downloadPath.DIRECTORY_SEPARATOR.$videoData['_filename']);
} else {
$videoData['file'] = null;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ protected function createProcess(array $arguments = []): Process

protected function findFile(string $fileName, string $extension)
{
$iterator = new \RegexIterator(new \DirectoryIterator($this->downloadPath), sprintf('/%s\.%s$/ui', preg_quote(pathinfo($fileName, PATHINFO_FILENAME), '/'), '('.$extension.')'), \RegexIterator::GET_MATCH);
$iterator = new \RegexIterator(new \DirectoryIterator($this->downloadPath), sprintf('/%s\.%s$/ui', preg_quote(pathinfo($fileName, PATHINFO_FILENAME), DIRECTORY_SEPARATOR), '('.$extension.')'), \RegexIterator::GET_MATCH);
$iterator->rewind();

return $iterator->current()[0];
Expand Down

0 comments on commit 32afb1b

Please sign in to comment.