This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata extraction from image files (#22)
* Tested locally metadata extraction with diff types of files * Added Dockerfile for frontend * Handled metadata nulls and checked for proper metadata updation * Fixed linter issues
- Loading branch information
1 parent
a1d96a1
commit 01e5f63
Showing
12 changed files
with
84 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM node:14-alpine as build-step | ||
RUN mkdir /app | ||
WORKDIR /app | ||
COPY package.json /app | ||
RUN npm install | ||
COPY . /app | ||
RUN npm run build | ||
|
||
FROM nginx:1.21.3-alpine | ||
COPY --from=build-step /app/build /usr/share/nginx/html |
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
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 |
---|---|---|
@@ -1,19 +1,31 @@ | ||
"""Component""" | ||
import json | ||
import urllib.request | ||
from bson.objectid import ObjectId | ||
|
||
|
||
class Component: | ||
"""Component""" | ||
def __init__(self, name, queue): | ||
def __init__(self, name, queue, db): | ||
self.name = name | ||
self.queue = queue | ||
self.db = db | ||
|
||
def callback(self, _, __, ___, body): | ||
"""RabbitMQ Callback""" | ||
data = json.loads(body) | ||
print(f'[{self.name}]: {data}') | ||
self.process(data['id'], data['imageUrl']) | ||
|
||
def download(self, oid, image_url): # pylint: disable=no-self-use | ||
"""Downloads the file for processing""" | ||
urllib.request.urlretrieve(image_url, f'image-{oid}') | ||
print(f'downloaded file image-{oid}') | ||
|
||
def update(self, oid, data): | ||
"""Updates database with the pipeline result""" | ||
self.db['mediaitems'].update_one({'_id': ObjectId(oid)}, {'$set': data}) | ||
|
||
def process(self, oid, image_url): | ||
"""Component Process""" | ||
raise NotImplementedError |
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 |
---|---|---|
@@ -1,12 +1,30 @@ | ||
"""Metadata""" | ||
import exifread | ||
from .component import Component | ||
|
||
|
||
class Metadata(Component): | ||
"""Metadata Component""" | ||
def __init__(self): | ||
super().__init__('metadata', 'pipeline.metadata') | ||
def __init__(self, db): | ||
super().__init__('metadata', 'pipeline.metadata', db) | ||
|
||
def process(self, oid, image_url): | ||
print(oid) | ||
print(image_url) | ||
self.download(oid, image_url) | ||
with open(f'image-{oid}', 'rb') as f: | ||
tags = exifread.process_file(f) | ||
if len(tags.keys()) > 0: | ||
self.update(oid, { | ||
'mediaMetadata': { | ||
'creationTime': str(tags['EXIF DateTimeOriginal']) if 'EXIF DateTimeOriginal' in tags else None, | ||
'width': tags['EXIF ExifImageLength'].values[0] if 'EXIF ExifImageLength' in tags else None, | ||
'height': tags['EXIF ExifImageWidth'].values[0] if 'EXIF ExifImageWidth' in tags else None, | ||
'photo': { | ||
'cameraMake': str(tags['Image Make']) if 'Image Make' in tags else None, | ||
'cameraModel': str(tags['Image Model']) if 'Image Model' in tags else None, | ||
'focalLength': str(tags['EXIF FocalLength'].values[0].decimal()) if 'EXIF FocalLength' in tags else None, | ||
'apertureFNumber': str(tags['EXIF FNumber'].values[0].decimal()) if 'EXIF FNumber' in tags else None, | ||
'isoEquivalent': tags['EXIF ISOSpeedRatings'].values[0] if 'EXIF ISOSpeedRatings' in tags else None, | ||
'exposureTime': str(tags['EXIF ExposureTime']) if 'EXIF ExposureTime' in tags else None, | ||
}, | ||
} | ||
}) |
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
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
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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
pika==1.2.0 | ||
pika==1.2.0 | ||
ExifRead==2.3.2 | ||
pymongo==3.11.3 |
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