Closed leikxile closed 10 years ago
I'm at work at the moment, and will look at this tonight. But media is one outstanding issue for ePub 3 implementation.
Cheers A.Grandt
On 13 December 2013 at 10:41 leikxile notifications@github.com wrote:
Hi, I tried copying the function processChapterImages and renamed it to processChapterAudio with the exact code. I'm not that good in PHP so I didn't manage to change the variables because i fear I might do something wrong. Here is the code. `protected function processChapterAudio(&$xmlDoc, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $htmlDir = "", $backPath = "") { if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) { return FALSE; } // process img tags. $postProcDomElememts = array(); $images = $xmlDoc->getElementsByTagName("source"); $itemCount = $images->length; for ($idx = 0; $idx < $itemCount; $idx++) { $img = $images->item($idx); if ($externalReferences === EPub::EXTERNAL_REF_REMOVE_IMAGES) { $postProcDomElememts[] = $img; } else if ($externalReferences === EPub::EXTERNAL_REF_REPLACE_IMAGES) { $altNode = $img->attributes->getNamedItem("alt"); $alt = "image"; if ($altNode !== NULL && strlen($altNode->nodeValue) > 0) { $alt = $altNode->nodeValue; } $postProcDomElememts[] = array($img, $this->createDomFragment($xmlDoc, "[" . $alt . "]")); } else { $source = $img->attributes->getNamedItem("src")->nodeValue;
$parsedSource = parse_url($source); $internalSrc =
$this->sanitizeFileName(urldecode(pathinfo($parsedSource['path'], PATHINFO_BASENAME))); $internalPath = ""; $isSourceExternal = FALSE;
if ($this->resolveMedia($source, $internalPath, $internalSrc,
$isSourceExternal, $baseDir, $htmlDir, $backPath)) { $img->setAttribute("src", $backPath . $internalPath); } else if ($isSourceExternal) { $postProcDomElememts[] = $img; // External image is missing } // else do nothing, if the image is local, and missing, assume it's been generated. } }
Its actually the same with theprocessChapterImagesfunction the only difference is I am looking for thesourcetag and not theimgtag and I used theresolveMediato replace thesrc` of all the media files.
It replaces the src but it did not download the file. I did not change anything in the resolveMedia function. File source is in here :http://www.noiseaddicts.com/samples/280.mp3
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/16 .
I think I have solved the problem, and ensured that adding large files from external sources wouldn't result in out of memory errors. I need to test a little more before committing this.
Please have a look at the 3.20 branch to see if that'll help with your issue.
Ok i'll try it by tomorrow i'm currently in the province right now. But I know you've fixed it already I know! :D Thank you again for the quick response as always.
On Sun, Dec 15, 2013 at 9:01 AM, Asbjørn Grandt notifications@github.comwrote:
Please have a look at the 3.20 branch to see if that'll help with your issue.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/16#issuecomment-30595543 .
Hi! Media has been downloaded successfully! Thank you! I'm just wondering, what is the file size limit for the media so that I can validate the file size? again thank you!
The limit, as it is now, is basically the connection timeout. Images are downloaded into memory as before, they usually don't break the PHP instance, and the epub data are stored in a temp file while the book is being built. (External) Media from the source tag are downloaded to the server directly into a temp file, and then spooled into the ePub, so the only limit is whatever you feel comfortable with. The media files stored on the server itself are also just spooled into the book that way.
If the same book is to be serverd multiple times, you might want to use the $epub->saveBook($filename) function to cache a copy for future use.
Cheers A.Grandt
On 15-12-2013 14:36, leikxile wrote:
Hi! Media has been downloaded successfully! Thank you! I'm just wondering, what is the file size limit for the media so that I can validate the file size? again thank you!
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/16#issuecomment-30605297.
Well that's nice! I should continue my work now because this issue has been fixed. Thank you very much again! And thanks for the tip. I may want to use that function in the future.
Cheers!
If timeouts due to having to download too much data from external sources, before being able to start sending the book (only a problem with links pointing to external servers (src="http://...") there is one thing I can do. It'll require quite a bit of alteration of the EPub class, but I have written an alternative to the Zip.php class, witch is essentially streaming the contents to the user, rather than wait for the entire book to be built before sending.
Cheers A.Grandt
On 15-12-2013 15:11, leikxile wrote:
Well that's nice! I should continue my work now because this issue has been fixed. Thank you very much again! And thanks for the tip. I may want to use that function in the future.
Cheers!
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/16#issuecomment-30606038.
I will ask the users to upload the media file in my server rather than having them referencing the media file from another url. Making it more quicker to download the book. I'll just restrict it to that I guess.
Is the issue resolved?
Yes thank you! On Dec 22, 2013 4:21 PM, "Asbjørn Grandt" notifications@github.com wrote:
Is the issue resolved?
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/16#issuecomment-31080921 .
Resolved. Closing.
Hi, I tried copying the function
processChapterImages
and renamed it toprocessChapterAudio
with the exact code. I'm not that good in PHP so I didn't manage to change the variables because i fear I might do something wrong. Here is the code. `protected function processChapterAudio(&$xmlDoc, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $htmlDir = "", $backPath = "") { if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) { return FALSE; } // process img tags. $postProcDomElememts = array(); $images = $xmlDoc->getElementsByTagName("source"); $itemCount = $images->length; for ($idx = 0; $idx < $itemCount; $idx++) { $img = $images->item($idx); if ($externalReferences === EPub::EXTERNAL_REF_REMOVE_IMAGES) { $postProcDomElememts[] = $img; } else if ($externalReferences === EPub::EXTERNAL_REF_REPLACE_IMAGES) { $altNode = $img->attributes->getNamedItem("alt"); $alt = "image"; if ($altNode !== NULL && strlen($altNode->nodeValue) > 0) { $alt = $altNode->nodeValue; } $postProcDomElememts[] = array($img, $this->createDomFragment($xmlDoc, "[" . $alt . "]")); } else { $source = $img->attributes->getNamedItem("src")->nodeValue;Its actually the same with the
processChapterImages
function the only difference is I am looking for thesource
tag and not theimg
tag and I used theresolveMedia
to replace thesrc
of all the media files.It replaces the
src
but it did not download the file. I did not change anything in theresolveMedia
function. File source is in here : http://www.noiseaddicts.com/samples/280.mp3