commit
fb323478f6
23
readme.md
23
readme.md
|
@ -73,4 +73,25 @@ Use the -k parameter to keep the original filenames:
|
|||
#### Adjust event distance
|
||||
|
||||
For the case you want to reduce or increase the timespan between events, simply use the parameter -d. The default is 4:
|
||||
`python recovery.py <path to files recovered by Photorec> <destination> -d10`
|
||||
|
||||
```python recovery.py <path to files recovered by Photorec> <destination> -d10```
|
||||
|
||||
#### Rename jpg-files with ```<Date>_<Time>``` from EXIF data if possible
|
||||
|
||||
If the original jpg image files were named by ```<Date>_<Time>``` it might be useful to rename the recovered files in the same way. This can be done by adding the parameter -j.
|
||||
|
||||
```python recovery.py <path to files recovered by Photorec> <destination> -j```
|
||||
|
||||
If no EXIF data can be retrieved the original filename is kept.
|
||||
|
||||
In case there are two or more files with the same EXIF data the filename is extended by an index to avoid overwritng files.
|
||||
|
||||
The result will look like:
|
||||
```
|
||||
20210121_134407.jpg
|
||||
20210122_145205.jpg
|
||||
20210122_145205(1).jpg
|
||||
20210122_145205(2).jpg
|
||||
20210122_145813.jpg
|
||||
20210122_153155.jpg
|
||||
```
|
||||
|
|
26
recovery.py
26
recovery.py
|
@ -5,6 +5,8 @@ from time import localtime, strftime
|
|||
import shutil
|
||||
import jpgSorter
|
||||
import numberOfFilesPerFolderLimiter
|
||||
import exifread
|
||||
from time import localtime, strftime, strptime, mktime
|
||||
|
||||
|
||||
def getNumberOfFilesInFolderRecursively(start_path = '.'):
|
||||
|
@ -57,6 +59,7 @@ def get_args():
|
|||
parser.add_argument('-m', '--split-months', action='store_true', required=False, help='split JPEG files not only by year but by month as well')
|
||||
parser.add_argument('-k', '--keep_filename', action='store_true', required=False, help='keeps the original filenames when copying')
|
||||
parser.add_argument('-d', '--min-event-delta', type=int, default=4, required=False, help='minimum delta in days between two days')
|
||||
parser.add_argument('-j', '--date_time_filename', action='store_true', required=False, help='sets the filename to the exif date and time if possible - otherwise keep the original filename')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
@ -67,7 +70,7 @@ splitMonths = False
|
|||
source = None
|
||||
destination = None
|
||||
keepFilename = False
|
||||
|
||||
date_time_filename = False
|
||||
|
||||
args = get_args()
|
||||
source = args.source
|
||||
|
@ -75,12 +78,15 @@ destination = args.destination
|
|||
maxNumberOfFilesPerFolder = args.max_per_dir
|
||||
splitMonths = args.split_months
|
||||
keepFilename = args.keep_filename
|
||||
date_time_filename = args.date_time_filename
|
||||
minEventDeltaDays = args.min_event_delta
|
||||
|
||||
print("Reading from source '%s', writing to destination '%s' (max %i files per directory, splitting by year %s)." %
|
||||
(source, destination, maxNumberOfFilesPerFolder, splitMonths and "and month" or "only"))
|
||||
if keepFilename:
|
||||
print("I will keep you filenames as they are")
|
||||
elif date_time_filename:
|
||||
print("If possible I will rename your files like <Date>_<Time>.jpg - otherwise keep the filenames as they are")
|
||||
else:
|
||||
print("I will rename your files like '1.jpg'")
|
||||
|
||||
|
@ -109,8 +115,26 @@ for root, dirs, files in os.walk(source, topdown=False):
|
|||
|
||||
if not os.path.exists(destinationDirectory):
|
||||
os.mkdir(destinationDirectory)
|
||||
|
||||
if keepFilename:
|
||||
fileName = file
|
||||
|
||||
elif date_time_filename:
|
||||
index = 0
|
||||
image = open(sourcePath, 'rb')
|
||||
exifTags = exifread.process_file(image, details=False)
|
||||
image.close()
|
||||
creationTime = jpgSorter.getMinimumCreationTime(exifTags)
|
||||
try:
|
||||
creationTime = strptime(str(creationTime), "%Y:%m:%d %H:%M:%S")
|
||||
creationTime = strftime("%Y%m%d_%H%M%S", creationTime)
|
||||
fileName = str(creationTime) + "." + extension.lower()
|
||||
while os.path.exists(os.path.join(destinationDirectory, fileName)):
|
||||
index += 1
|
||||
fileName = str(creationTime) + "(" + str(index) + ")" + "." + extension.lower()
|
||||
except:
|
||||
fileName = file
|
||||
|
||||
else:
|
||||
if extension:
|
||||
fileName = str(fileCounter) + "." + extension.lower()
|
||||
|
|
Loading…
Reference in New Issue