-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add details and better network handling Network code should now deal more consistently with token issues and reset the frame data to allow you to authorize again. Details is a new button for the google photos part which will expose more info about what content it saw. * Re-implement freshness logic Allow individual keywords to be expired if too old. Moved erasing of indexes into services instead of servicemanager * Major rewrites - Event system (not yet in use) - Improved memory handling (found major bug) - Streamlined code flow so it happens where it makes sense * Reworking memory handling and history * First working version with random and order Cleaned up API, now random and order works as expected. Next/Prev is broken and so is album next/prev. * Handle error display on frame better Used to just run full tilt when error shows, now it refreshes at a normal rate. * Many fixes - Uses unique filenames to avoid clashing when only one image is available - Handles changes to services/keywords better - Removed dead code - Removed printouts which clogged the log - Fixed issue with lingering .cache files filling /tmp
- Loading branch information
Showing
25 changed files
with
1,132 additions
and
479 deletions.
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
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
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,44 @@ | ||
# This file is part of photoframe (https://github.com/mrworf/photoframe). | ||
# | ||
# photoframe is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# photoframe is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with photoframe. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
class DedupeManager: | ||
def __init__(self, memoryLocation): | ||
try: | ||
from PIL import Image | ||
import imagehash | ||
self.hasImageHash = True | ||
logging.info('ImageHash functionality is available') | ||
except: | ||
self.hasImageHash = False | ||
logging.info('ImageHash functionality is unavailable') | ||
|
||
def _hamming_distance(self, i1, i2): | ||
x = i1 ^ i2 | ||
setBits = 0 | ||
|
||
while (x > 0): | ||
setBits += x & 1 | ||
x >>= 1 | ||
|
||
return setBits | ||
|
||
def _hamming(self, s1, s2): | ||
h = 0 | ||
for i in range(0, len(s1)/2): | ||
i1 = int(s1[i*2:i*2+2], 16) | ||
i2 = int(s2[i*2:i*2+2], 16) | ||
h += self._hamming_distance(i1, i2) | ||
return h |
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,58 @@ | ||
# This file is part of photoframe (https://github.com/mrworf/photoframe). | ||
# | ||
# photoframe is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# photoframe is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with photoframe. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
class Events: | ||
TYPE_PERSIST = 1 | ||
TYPE_NORMAL = 0 | ||
|
||
LEVEL_INFO = 0 | ||
LEVEL_WARN = 1 | ||
LEVEL_ERR = 2 | ||
LEVEL_DEBUG = 3 | ||
|
||
def __init__(self): | ||
self.idcount = 0 | ||
self.msgs = [] | ||
|
||
def add(self, message, unique=None, link=None, level=LEVEL_INFO, type=TYPE_NORMAL): | ||
record = {'id': self.idcount, 'unique' : unique, 'type' : type, 'level' : level, 'message' : message, 'link' : link} | ||
if unique is not None: | ||
unique = repr(unique) # Make it a string to be safe | ||
for i in range(0, len(self.msgs)): | ||
if self.msgs[i]['unique'] == unique: | ||
self.msgs[i] = record | ||
record = None | ||
break | ||
|
||
if record is not None: | ||
self.msgs.append(record) | ||
self.idcount += 1 | ||
|
||
def remove(self, id): | ||
for i in range(0, len(self.msgs)): | ||
if self.msgs[i]['id'] == id and self.msgs[i]['type'] != Events.TYPE_PERSIST: | ||
self.msgs.pop(i) | ||
break | ||
|
||
def getAll(self): | ||
return self.msgs | ||
|
||
def getSince(self, id): | ||
ret = [] | ||
for msg in self.msgs: | ||
if msg['id'] > id: | ||
ret.append(msg) | ||
return ret |
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,75 @@ | ||
# This file is part of photoframe (https://github.com/mrworf/photoframe). | ||
# | ||
# photoframe is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# photoframe is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with photoframe. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
import logging | ||
import os | ||
import shutil | ||
|
||
from modules.path import path as syspath | ||
|
||
class ImageHistory: | ||
MAX_HISTORY = 20 | ||
def __init__(self, settings): | ||
self._HISTORY = [] | ||
self.settings = settings | ||
|
||
# Also, make sure folder exists AND clear any existing content | ||
if not os.path.exists(syspath.HISTORYFOLDER): | ||
os.mkdir(syspath.HISTORYFOLDER) | ||
|
||
# Clear it | ||
for p, _dirs, files in os.walk(syspath.HISTORYFOLDER): | ||
for filename in [os.path.join(p, f) for f in files]: | ||
try: | ||
os.unlink(filename) | ||
except: | ||
logging.exception('Failed to delete "%s"' % filename) | ||
|
||
def _find(self, file): | ||
return next((entry for entry in self._HISTORY if entry.filename == file), None) | ||
|
||
def add(self, image): | ||
if image is None or image.error is not None: | ||
return | ||
historyFile = os.path.join(syspath.HISTORYFOLDER, image.getCacheId()) | ||
if not self._find(historyFile): | ||
shutil.copy(image.filename, historyFile) | ||
h = image.copy() | ||
h.setFilename(historyFile) | ||
h.allowCache(False) | ||
|
||
self._HISTORY.insert(0, h) | ||
self._obeyLimits() | ||
|
||
def _obeyLimits(self): | ||
# Make sure history isn't too big | ||
while len(self._HISTORY) > ImageHistory.MAX_HISTORY: | ||
entry = self._HISTORY.pop() | ||
if not self._find(entry.filename): | ||
os.unlink(entry.filename) | ||
|
||
def getAvailable(self): | ||
return len(self._HISTORY) | ||
|
||
def getByIndex(self, index): | ||
if index < 0 or index >= len(self._HISTORY): | ||
logging.warning('History index requested is out of bounds (%d wanted, have 0-%d)', index, len(self._HISTORY)-1) | ||
return None | ||
entry = self._HISTORY[index] | ||
# We need to make a copy which is safe to delete! | ||
f = os.path.join(self.settings.get('tempfolder'), 'history') | ||
shutil.copy(entry.filename, f) | ||
return entry.copy().setFilename(f) |
Oops, something went wrong.