-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding file creation and modified date support + more debugging output #47
Open
mfyz
wants to merge
6
commits into
TheFox:master
Choose a base branch
from
mfyz:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2df4ca7
adding file creation and modified date support + more debugging
mfyz 90470b7
var names converted to camelCase + fixed travis errors.
mfyz 786b77e
multil line method call issues fixed
mfyz 098c6cf
removed trailing spaces for method argument definitions.
mfyz ce0b7ea
final white space cleared.
mfyz 38b65cb
fix of travis not liking missing optional argument in the method call.
mfyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ composer.phar | |
/log/ | ||
.env | ||
.idea | ||
config | ||
photosets/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,14 +235,19 @@ protected function downloadByAlbumTitle(): int | |
} | ||
|
||
/** @var $photo SimpleXMLElement */ | ||
$totalPhotos = count($xmlPhotoList->photoset->photo); | ||
$currentPhoto = 0; | ||
foreach ($xmlPhotoList->photoset->photo as $photo) { | ||
$currentPhoto++; | ||
pcntl_signal_dispatch(); | ||
if ($this->getExit()) { | ||
break; | ||
} | ||
|
||
$this->getLogger()->debug(sprintf('[media] %d/%d photo %s', $page, $fileCount, $photo['id'])); | ||
$downloaded = $this->downloadPhoto($photo, $destinationPath); | ||
$debugInfo = " $currentPhoto/$totalPhotos at the page $page/$xmlPhotoListPagesTotal " | ||
. "- photo set: $photosetTitle"; | ||
$downloaded = $this->downloadPhoto($photo, $destinationPath, null, $debugInfo); | ||
if ($downloaded && isset($downloaded->filesize)) { | ||
$totalDownloaded += $downloaded->filesize; | ||
} | ||
|
@@ -275,8 +280,12 @@ protected function downloadByAlbumTitle(): int | |
* @return SimpleXMLElement|boolean Photo metadata as returned by Flickr, or false if something went wrong. | ||
* @throws Exception | ||
*/ | ||
private function downloadPhoto(SimpleXMLElement $photo, string $destinationPath, string $basename = null) | ||
{ | ||
private function downloadPhoto( | ||
SimpleXMLElement $photo, | ||
string $destinationPath, | ||
string $basename = null, | ||
string $debugInfo | ||
) { | ||
$id = (string)$photo->attributes()->id; | ||
|
||
$apiFactory = $this->getApiService()->getApiFactory(); | ||
|
@@ -416,8 +425,9 @@ private function downloadPhoto(SimpleXMLElement $photo, string $destinationPath, | |
} | ||
|
||
$this->getLogger()->info(sprintf( | ||
"[%s] %s, farm %s, server %s, %s, '%s', %s", | ||
"[%s%s] %s, farm %s, server %s, %s, '%s', %s", | ||
$media, | ||
$debugInfo, | ||
$id, | ||
$farm, | ||
$server, | ||
|
@@ -485,7 +495,7 @@ private function downloadPhoto(SimpleXMLElement $photo, string $destinationPath, | |
); | ||
} else { | ||
// Otherwise, just show the amount downloaded and speed. | ||
printf("[file] %s %10s\x1b[0K\r", number_format($downloaded), $downloadedDiffStr); | ||
printf("[file$debugInfo] %s %10s\x1b[0K\r", number_format($downloaded), $downloadedDiffStr); | ||
} | ||
} | ||
fclose($fh); | ||
|
@@ -506,6 +516,12 @@ private function downloadPhoto(SimpleXMLElement $photo, string $destinationPath, | |
|
||
/** @var SimpleXMLElement $photo */ | ||
$photo = $xmlPhoto->photo; | ||
|
||
// update the timstamps of the file | ||
$update_date = (int) $photo->dates['lastupdate']; | ||
$taken_date = strtotime((string) $photo->dates['taken']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use strval($photo->dates['taken']) instead of (string) $photo->dates['taken'] here. The same goes for |
||
touch($filePath, $taken_date, $update_date); | ||
// var_dump($taken_date); exit; | ||
|
||
return $photo; | ||
} | ||
|
@@ -585,7 +601,15 @@ private function downloadPhotoById(SimpleXMLElement $photo) | |
{ | ||
$id = $photo['id']; | ||
$idHash = md5($id); | ||
$destinationPath = sprintf('%s/%s/%s/%s/%s/%s', $this->destinationPath, $idHash[0], $idHash[1], $idHash[2], $idHash[3], $id); | ||
$destinationPath = sprintf( | ||
'%s/%s/%s/%s/%s/%s', | ||
$this->destinationPath, | ||
$idHash[0], | ||
$idHash[1], | ||
$idHash[2], | ||
$idHash[3], | ||
$id | ||
); | ||
|
||
$filesystem = new Filesystem(); | ||
if (!$filesystem->exists($destinationPath)) { | ||
|
@@ -594,7 +618,7 @@ private function downloadPhotoById(SimpleXMLElement $photo) | |
|
||
// Save the actual file. | ||
$apiFactory = $this->getApiService()->getApiFactory(); | ||
$photo = $this->downloadPhoto($photo, $destinationPath, $id); | ||
$photo = $this->downloadPhoto($photo, $destinationPath, $id, ""); | ||
if (false === $photo) { | ||
$this->getLogger()->error(sprintf('Unable to get metadata about photo: %s', $id)); | ||
return; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting a default value in the 3rd argument and then setting no default argument in the 4th should be avoided. This is in general not best practice. Either setting also a default value for
$debugInfo
or switch:... string $debugInfo, string $basename = null)
. Since$destinationPath
and$basename
are both path related I would prefer to also set a default value for$debugInfo
.You see, this line
doesn't look very nice. Because the empty string
""
can be avoided.Having a default value and a caller like this,
also looks nicer.