Add lowBandwidth to image conversions

main
Bob Mottram 2021-08-13 21:18:36 +01:00
parent d69bded0ae
commit 27544b7eaa
6 changed files with 29 additions and 15 deletions

View File

@ -112,6 +112,8 @@ from auth import authorizeBasic
from auth import storeBasicCredentials from auth import storeBasicCredentials
from threads import threadWithTrace from threads import threadWithTrace
from threads import removeDormantThreads from threads import removeDormantThreads
from media import processMetaData
from media import convertImageToLowBandwidth
from media import replaceYouTube from media import replaceYouTube
from media import attachMedia from media import attachMedia
from media import pathIsVideo from media import pathIsVideo
@ -286,7 +288,6 @@ from content import addHtmlTags
from content import extractMediaInFormPOST from content import extractMediaInFormPOST
from content import saveMediaInFormPOST from content import saveMediaInFormPOST
from content import extractTextFieldsInPOST from content import extractTextFieldsInPOST
from media import processMetaData
from cache import checkForChangedActor from cache import checkForChangedActor
from cache import storePersonInCache from cache import storePersonInCache
from cache import getPersonFromCache from cache import getPersonFromCache
@ -1165,7 +1166,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.allowLocalNetworkAccess, self.server.allowLocalNetworkAccess,
city, self.server.systemLanguage, city, self.server.systemLanguage,
self.server.sharedItemsFederatedDomains, self.server.sharedItemsFederatedDomains,
self.server.sharedItemFederationTokens) self.server.sharedItemFederationTokens,
self.server.lowBandwidth)
def _postToOutboxThread(self, messageJson: {}) -> bool: def _postToOutboxThread(self, messageJson: {}) -> bool:
"""Creates a thread to send a post """Creates a thread to send a post
@ -4286,6 +4288,8 @@ class PubServer(BaseHTTPRequestHandler):
city = getSpoofedCity(self.server.city, city = getSpoofedCity(self.server.city,
baseDir, nickname, domain) baseDir, nickname, domain)
if self.server.lowBandwidth:
convertImageToLowBandwidth(filename)
processMetaData(baseDir, nickname, domain, processMetaData(baseDir, nickname, domain,
filename, postImageFilename, city) filename, postImageFilename, city)
if os.path.isfile(postImageFilename): if os.path.isfile(postImageFilename):
@ -13846,6 +13850,8 @@ class PubServer(BaseHTTPRequestHandler):
city = getSpoofedCity(self.server.city, city = getSpoofedCity(self.server.city,
self.server.baseDir, self.server.baseDir,
nickname, self.server.domain) nickname, self.server.domain)
if self.server.lowBandwidth:
convertImageToLowBandwidth(filename)
processMetaData(self.server.baseDir, processMetaData(self.server.baseDir,
nickname, self.server.domain, nickname, self.server.domain,
filename, postImageFilename, city) filename, postImageFilename, city)
@ -14488,7 +14494,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.debug, self.server.debug,
city, itemPrice, itemCurrency, city, itemPrice, itemCurrency,
self.server.systemLanguage, self.server.systemLanguage,
self.server.translate, sharesFileType) self.server.translate, sharesFileType,
self.server.lowBandwidth)
if filename: if filename:
if os.path.isfile(filename): if os.path.isfile(filename):
os.remove(filename) os.remove(filename)

View File

@ -2488,7 +2488,7 @@ if args.testdata:
"mechanical", "mechanical",
"City", "0", "GBP", "City", "0", "GBP",
"2 months", "2 months",
debug, city, args.language, {}, 'shares') debug, city, args.language, {}, 'shares', args.lowBandwidth)
addShare(baseDir, addShare(baseDir,
httpPrefix, nickname, domain, port, httpPrefix, nickname, domain, port,
"witch hat", "witch hat",
@ -2498,7 +2498,7 @@ if args.testdata:
"clothing", "clothing",
"City", "0", "GBP", "City", "0", "GBP",
"3 months", "3 months",
debug, city, args.language, {}, 'shares') debug, city, args.language, {}, 'shares', args.lowBandwidth)
deleteAllPosts(baseDir, nickname, domain, 'inbox') deleteAllPosts(baseDir, nickname, domain, 'inbox')
deleteAllPosts(baseDir, nickname, domain, 'outbox') deleteAllPosts(baseDir, nickname, domain, 'outbox')

View File

@ -116,7 +116,7 @@ def _spoofMetaData(baseDir: str, nickname: str, domain: str,
return return
def _convertImageToLowBandwidth(imageFilename: str) -> None: def convertImageToLowBandwidth(imageFilename: str) -> None:
"""Converts an image to a low bandwidth version """Converts an image to a low bandwidth version
""" """
lowBandwidthFilename = imageFilename + '.low' lowBandwidthFilename = imageFilename + '.low'
@ -136,9 +136,9 @@ def _convertImageToLowBandwidth(imageFilename: str) -> None:
ctr = 0 ctr = 0
while not os.path.isfile(lowBandwidthFilename): while not os.path.isfile(lowBandwidthFilename):
print('Waiting for low bandwidth image conversion ' + str(ctr)) print('Waiting for low bandwidth image conversion ' + str(ctr))
time.sleep(0.5) time.sleep(0.2)
ctr += 1 ctr += 1
if ctr > 20: if ctr > 100:
print('WARN: timed out waiting for low bandwidth image conversion') print('WARN: timed out waiting for low bandwidth image conversion')
break break
if os.path.isfile(lowBandwidthFilename): if os.path.isfile(lowBandwidthFilename):
@ -303,7 +303,7 @@ def attachMedia(baseDir: str, httpPrefix: str,
if baseDir: if baseDir:
if mediaType.startswith('image/'): if mediaType.startswith('image/'):
if lowBandwidth: if lowBandwidth:
_convertImageToLowBandwidth(imageFilename) convertImageToLowBandwidth(imageFilename)
processMetaData(baseDir, nickname, domain, processMetaData(baseDir, nickname, domain,
imageFilename, mediaFilename, city) imageFilename, mediaFilename, city)
else: else:

View File

@ -192,7 +192,8 @@ def postMessageToOutbox(session, translate: {},
allowLocalNetworkAccess: bool, allowLocalNetworkAccess: bool,
city: str, systemLanguage: str, city: str, systemLanguage: str,
sharedItemsFederatedDomains: [], sharedItemsFederatedDomains: [],
sharedItemFederationTokens: {}) -> bool: sharedItemFederationTokens: {},
lowBandwidth: bool) -> bool:
"""post is received by the outbox """post is received by the outbox
Client to server message post Client to server message post
https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery
@ -554,7 +555,7 @@ def postMessageToOutbox(session, translate: {},
print('DEBUG: handle share uploads') print('DEBUG: handle share uploads')
outboxShareUpload(baseDir, httpPrefix, postToNickname, domain, outboxShareUpload(baseDir, httpPrefix, postToNickname, domain,
port, messageJson, debug, city, port, messageJson, debug, city,
systemLanguage, translate) systemLanguage, translate, lowBandwidth)
if debug: if debug:
print('DEBUG: handle undo share uploads') print('DEBUG: handle undo share uploads')

View File

@ -114,7 +114,8 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd,
httpd.allowLocalNetworkAccess, httpd.allowLocalNetworkAccess,
httpd.city, httpd.systemLanguage, httpd.city, httpd.systemLanguage,
httpd.sharedItemsFederatedDomains, httpd.sharedItemsFederatedDomains,
httpd.sharedItemFederationTokens): httpd.sharedItemFederationTokens,
httpd.lowBandwidth):
indexLines.remove(line) indexLines.remove(line)
os.remove(postFilename) os.remove(postFilename)
continue continue

View File

@ -38,6 +38,7 @@ from utils import isfloat
from utils import getCategoryTypes from utils import getCategoryTypes
from utils import getSharesFilesList from utils import getSharesFilesList
from media import processMetaData from media import processMetaData
from media import convertImageToLowBandwidth
from filters import isFilteredGlobally from filters import isFilteredGlobally
from siteactive import siteIsActive from siteactive import siteIsActive
from content import getPriceFromString from content import getPriceFromString
@ -293,7 +294,7 @@ def addShare(baseDir: str,
duration: str, debug: bool, city: str, duration: str, debug: bool, city: str,
price: str, currency: str, price: str, currency: str,
systemLanguage: str, translate: {}, systemLanguage: str, translate: {},
sharesFileType: str) -> None: sharesFileType: str, lowBandwidth: bool) -> None:
"""Adds a new share """Adds a new share
""" """
if isFilteredGlobally(baseDir, if isFilteredGlobally(baseDir,
@ -343,6 +344,8 @@ def addShare(baseDir: str,
for ext in formats: for ext in formats:
if not imageFilename.endswith('.' + ext): if not imageFilename.endswith('.' + ext):
continue continue
if lowBandwidth:
convertImageToLowBandwidth(imageFilename)
processMetaData(baseDir, nickname, domain, processMetaData(baseDir, nickname, domain,
imageFilename, itemIDfile + '.' + ext, imageFilename, itemIDfile + '.' + ext,
city) city)
@ -989,7 +992,8 @@ def getSharedItemsCatalogViaServer(baseDir, session,
def outboxShareUpload(baseDir: str, httpPrefix: str, def outboxShareUpload(baseDir: str, httpPrefix: str,
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
messageJson: {}, debug: bool, city: str, messageJson: {}, debug: bool, city: str,
systemLanguage: str, translate: {}) -> None: systemLanguage: str, translate: {},
lowBandwidth: bool) -> None:
""" When a shared item is received by the outbox from c2s """ When a shared item is received by the outbox from c2s
""" """
if not messageJson.get('type'): if not messageJson.get('type'):
@ -1054,7 +1058,8 @@ def outboxShareUpload(baseDir: str, httpPrefix: str,
debug, city, debug, city,
messageJson['object']['itemPrice'], messageJson['object']['itemPrice'],
messageJson['object']['itemCurrency'], messageJson['object']['itemCurrency'],
systemLanguage, translate, 'shares') systemLanguage, translate, 'shares',
lowBandwidth)
if debug: if debug:
print('DEBUG: shared item received via c2s') print('DEBUG: shared item received via c2s')