Merge pull request #41 from medismail/master
Update filename in the database according to the download extension file
This commit is contained in:
@@ -17,6 +17,7 @@ class YoutubeController extends Controller
|
|||||||
private $settings = null;
|
private $settings = null;
|
||||||
//@config OC\AppConfig
|
//@config OC\AppConfig
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
private $audio_extensions = array("mp3", "m4a", "vorbis");
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, $UserId, IL10N $IL10N, Aria2 $aria2, Youtube $youtube)
|
public function __construct($appName, IRequest $request, $UserId, IL10N $IL10N, Aria2 $aria2, Youtube $youtube)
|
||||||
{
|
{
|
||||||
@@ -80,10 +81,11 @@ class YoutubeController extends Controller
|
|||||||
}
|
}
|
||||||
$url = trim($this->request->getParam('text-input-value'));
|
$url = trim($this->request->getParam('text-input-value'));
|
||||||
$yt = $this->youtube;
|
$yt = $this->youtube;
|
||||||
$yt->audioOnly = (bool) $this->request->getParam('audio-only');
|
if (in_array($this->request->getParam('extension'), $this->audio_extensions)) {
|
||||||
if ($yt->audioOnly) {
|
$yt->audioOnly = TRUE;
|
||||||
$yt->audioFormat = $this->request->getParam('extension');
|
$yt->audioFormat = $this->request->getParam('extension');
|
||||||
} else {
|
} else {
|
||||||
|
$yt->audioOnly = FALSE;
|
||||||
$yt->videoFormat = $this->request->getParam('extension');
|
$yt->videoFormat = $this->request->getParam('extension');
|
||||||
}
|
}
|
||||||
if (!$yt->isInstalled()) {
|
if (!$yt->isInstalled()) {
|
||||||
@@ -155,6 +157,15 @@ class YoutubeController extends Controller
|
|||||||
$row = $this->dbconn->getByGid($gid);
|
$row = $this->dbconn->getByGid($gid);
|
||||||
$data = $this->dbconn->getExtra($row["data"]);
|
$data = $this->dbconn->getExtra($row["data"]);
|
||||||
if (!empty($data['link'])) {
|
if (!empty($data['link'])) {
|
||||||
|
if (isset($data['ext'])) {
|
||||||
|
if (in_array($data['ext'], $this->audio_extensions)) {
|
||||||
|
$this->youtube->audioOnly = TRUE;
|
||||||
|
$this->youtube->audioFormat = $data['ext'];
|
||||||
|
} else {
|
||||||
|
$this->youtube->audioOnly = FALSE;
|
||||||
|
$this->youtube->videoFormat = $data['ext'];
|
||||||
|
}
|
||||||
|
}
|
||||||
//$this->dbconn->deleteByGid($gid);
|
//$this->dbconn->deleteByGid($gid);
|
||||||
$resp = $this->youtube->forceIPV4()->download($data['link']);
|
$resp = $this->youtube->forceIPV4()->download($data['link']);
|
||||||
folderScan::sync();
|
folderScan::sync();
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ class Youtube
|
|||||||
} else {
|
} else {
|
||||||
$this->audioFormat = "m4a";
|
$this->audioFormat = "m4a";
|
||||||
}
|
}
|
||||||
$pos = strrpos($this->outTpl, '.');
|
/*$pos = strrpos($this->outTpl, '.');
|
||||||
$this->outTpl = substr($this->outTpl, 0, $pos) . "." . $this->audioFormat;
|
$this->outTpl = substr($this->outTpl, 0, $pos) . "." . $this->audioFormat;
|
||||||
//$this->outTpl = "/%(id)s-%(title)s.m4a";
|
$this->outTpl = "/%(id)s-%(title)s.m4a";*/
|
||||||
$this->setAudioFormat($this->audioFormat);
|
$this->setAudioFormat($this->audioFormat);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -145,6 +145,11 @@ class Youtube
|
|||||||
$process = new Process($this->options, null, $this->env);
|
$process = new Process($this->options, null, $this->env);
|
||||||
$process->setTimeout($this->timeout);
|
$process->setTimeout($this->timeout);
|
||||||
$data = ['link' => $url];
|
$data = ['link' => $url];
|
||||||
|
if ($this->audioOnly) {
|
||||||
|
$data['ext'] = $this->audioFormat;
|
||||||
|
} else {
|
||||||
|
$data['ext'] = $this->videoFormat;
|
||||||
|
}
|
||||||
$process->run(function ($type, $buffer) use ($data, $process) {
|
$process->run(function ($type, $buffer) use ($data, $process) {
|
||||||
if (Process::ERR === $type) {
|
if (Process::ERR === $type) {
|
||||||
$this->onError($buffer);
|
$this->onError($buffer);
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class YoutubeHelper
|
|||||||
}
|
}
|
||||||
public function getFilePath($output)
|
public function getFilePath($output)
|
||||||
{
|
{
|
||||||
$rules = '#\[download\]\s+Destination:\s+(?<filename>.*\.(?<ext>(mp4|mp3|aac|webm|m4a|ogg|3gp|mkv|wav|flv)))#i';
|
$rules = '#\[(download|ExtractAudio|VideoConvertor|Merger)\]((\s+|\s+Converting.*;\s+)Destination:\s+|\s+Merging formats into\s+\")' .
|
||||||
|
'(?<filename>.*\.(?<ext>(mp4|mp3|aac|webm|m4a|ogg|3gp|mkv|wav|flv)))#i';
|
||||||
|
|
||||||
preg_match($rules, $output, $matches);
|
preg_match($rules, $output, $matches);
|
||||||
|
|
||||||
@@ -78,9 +79,14 @@ class YoutubeHelper
|
|||||||
'timestamp' => time(),
|
'timestamp' => time(),
|
||||||
'data' => $extra,
|
'data' => $extra,
|
||||||
];
|
];
|
||||||
|
if (isset($this->file)) {
|
||||||
|
$sql = sprintf("UPDATE %s set filename = ? WHERE gid = ?", $this->tablename);
|
||||||
|
$this->dbconn->executeUpdate($sql, [basename($file), $this->gid]);
|
||||||
|
} else {
|
||||||
|
$this->dbconn->insert($data);
|
||||||
|
}
|
||||||
//save the filename as this runs only once
|
//save the filename as this runs only once
|
||||||
$this->file = $file;
|
$this->file = basename($file);
|
||||||
$this->dbconn->insert($data);
|
|
||||||
//$this->dbconn->save($data,[],['gid' => $this->gid]);
|
//$this->dbconn->save($data,[],['gid' => $this->gid]);
|
||||||
}
|
}
|
||||||
if (preg_match_all(self::PROGRESS_PATTERN, $buffer, $matches, PREG_SET_ORDER) !== false) {
|
if (preg_match_all(self::PROGRESS_PATTERN, $buffer, $matches, PREG_SET_ORDER) !== false) {
|
||||||
|
|||||||
@@ -63,13 +63,10 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (formData.type === "youtube-dl") {
|
if (formData.type === "youtube-dl") {
|
||||||
formData["audio-only"] = "";
|
|
||||||
formData["extension"] = "";
|
formData["extension"] = "";
|
||||||
if (formData["select-value-extension"] !== "Default") {
|
|
||||||
|
if (formData["select-value-extension"] !== "defaultext") {
|
||||||
formData["extension"] = formData["select-value-extension"];
|
formData["extension"] = formData["select-value-extension"];
|
||||||
if (["mp3", "m4a", "vorbis"].includes(formData["select-value-extension"])) {
|
|
||||||
formData["audio-only"] = "true";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
message = helper.t("Download task started!");
|
message = helper.t("Download task started!");
|
||||||
helper.pollingYoutube();
|
helper.pollingYoutube();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<div class="download-controls-container">
|
<div class="download-controls-container">
|
||||||
<div v-if="checkboxes" id="select-value-extension-container">
|
<div v-if="checkboxes" id="select-value-extension-container">
|
||||||
<select :value="selectedExt" id="select-value-extension">
|
<select :value="selectedExt" id="select-value-extension">
|
||||||
<option id="defaultext" :value="selectedExt">Default</option>
|
<option id="defaultext" value="defaultext">Default</option>
|
||||||
<optgroup label="Video">
|
<optgroup label="Video">
|
||||||
<option id="mp4" value="mp4">mp4</option>
|
<option id="mp4" value="mp4">mp4</option>
|
||||||
<option id="webm" value="webm">webm</option>
|
<option id="webm" value="webm">webm</option>
|
||||||
@@ -74,7 +74,7 @@ export default {
|
|||||||
placeholder: t("ncdownloader", "Paste your http/magnet link here"),
|
placeholder: t("ncdownloader", "Paste your http/magnet link here"),
|
||||||
searchLabel: t("ncdownloader", "Search Torrents"),
|
searchLabel: t("ncdownloader", "Search Torrents"),
|
||||||
searchOptions: this.search_sites ? this.search_sites : this.noOptions(),
|
searchOptions: this.search_sites ? this.search_sites : this.noOptions(),
|
||||||
selectedExt: "Default",
|
selectedExt: "defaultext",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
Reference in New Issue
Block a user