diff --git a/daemon.py b/daemon.py index e5085ae3b..c377a4a84 100644 --- a/daemon.py +++ b/daemon.py @@ -112,6 +112,8 @@ from auth import authorizeBasic from auth import storeBasicCredentials from threads import threadWithTrace from threads import removeDormantThreads +from media import processMetaData +from media import convertImageToLowBandwidth from media import replaceYouTube from media import attachMedia from media import pathIsVideo @@ -286,7 +288,6 @@ from content import addHtmlTags from content import extractMediaInFormPOST from content import saveMediaInFormPOST from content import extractTextFieldsInPOST -from media import processMetaData from cache import checkForChangedActor from cache import storePersonInCache from cache import getPersonFromCache @@ -1165,7 +1166,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.allowLocalNetworkAccess, city, self.server.systemLanguage, self.server.sharedItemsFederatedDomains, - self.server.sharedItemFederationTokens) + self.server.sharedItemFederationTokens, + self.server.lowBandwidth) def _postToOutboxThread(self, messageJson: {}) -> bool: """Creates a thread to send a post @@ -4286,6 +4288,8 @@ class PubServer(BaseHTTPRequestHandler): city = getSpoofedCity(self.server.city, baseDir, nickname, domain) + if self.server.lowBandwidth: + convertImageToLowBandwidth(filename) processMetaData(baseDir, nickname, domain, filename, postImageFilename, city) if os.path.isfile(postImageFilename): @@ -13846,6 +13850,8 @@ class PubServer(BaseHTTPRequestHandler): city = getSpoofedCity(self.server.city, self.server.baseDir, nickname, self.server.domain) + if self.server.lowBandwidth: + convertImageToLowBandwidth(filename) processMetaData(self.server.baseDir, nickname, self.server.domain, filename, postImageFilename, city) @@ -14488,7 +14494,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.debug, city, itemPrice, itemCurrency, self.server.systemLanguage, - self.server.translate, sharesFileType) + self.server.translate, sharesFileType, + self.server.lowBandwidth) if filename: if os.path.isfile(filename): os.remove(filename) diff --git a/epicyon.py b/epicyon.py index c6cfed377..93d88456b 100644 --- a/epicyon.py +++ b/epicyon.py @@ -2488,7 +2488,7 @@ if args.testdata: "mechanical", "City", "0", "GBP", "2 months", - debug, city, args.language, {}, 'shares') + debug, city, args.language, {}, 'shares', args.lowBandwidth) addShare(baseDir, httpPrefix, nickname, domain, port, "witch hat", @@ -2498,7 +2498,7 @@ if args.testdata: "clothing", "City", "0", "GBP", "3 months", - debug, city, args.language, {}, 'shares') + debug, city, args.language, {}, 'shares', args.lowBandwidth) deleteAllPosts(baseDir, nickname, domain, 'inbox') deleteAllPosts(baseDir, nickname, domain, 'outbox') diff --git a/media.py b/media.py index 3fad2c4fb..b7382f4b2 100644 --- a/media.py +++ b/media.py @@ -116,7 +116,7 @@ def _spoofMetaData(baseDir: str, nickname: str, domain: str, return -def _convertImageToLowBandwidth(imageFilename: str) -> None: +def convertImageToLowBandwidth(imageFilename: str) -> None: """Converts an image to a low bandwidth version """ lowBandwidthFilename = imageFilename + '.low' @@ -136,9 +136,9 @@ def _convertImageToLowBandwidth(imageFilename: str) -> None: ctr = 0 while not os.path.isfile(lowBandwidthFilename): print('Waiting for low bandwidth image conversion ' + str(ctr)) - time.sleep(0.5) + time.sleep(0.2) ctr += 1 - if ctr > 20: + if ctr > 100: print('WARN: timed out waiting for low bandwidth image conversion') break if os.path.isfile(lowBandwidthFilename): @@ -303,7 +303,7 @@ def attachMedia(baseDir: str, httpPrefix: str, if baseDir: if mediaType.startswith('image/'): if lowBandwidth: - _convertImageToLowBandwidth(imageFilename) + convertImageToLowBandwidth(imageFilename) processMetaData(baseDir, nickname, domain, imageFilename, mediaFilename, city) else: diff --git a/outbox.py b/outbox.py index ef9bbc55e..a602f83ed 100644 --- a/outbox.py +++ b/outbox.py @@ -192,7 +192,8 @@ def postMessageToOutbox(session, translate: {}, allowLocalNetworkAccess: bool, city: str, systemLanguage: str, sharedItemsFederatedDomains: [], - sharedItemFederationTokens: {}) -> bool: + sharedItemFederationTokens: {}, + lowBandwidth: bool) -> bool: """post is received by the outbox Client to server message post https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery @@ -554,7 +555,7 @@ def postMessageToOutbox(session, translate: {}, print('DEBUG: handle share uploads') outboxShareUpload(baseDir, httpPrefix, postToNickname, domain, port, messageJson, debug, city, - systemLanguage, translate) + systemLanguage, translate, lowBandwidth) if debug: print('DEBUG: handle undo share uploads') diff --git a/schedule.py b/schedule.py index 9205dd0fc..3395b47df 100644 --- a/schedule.py +++ b/schedule.py @@ -114,7 +114,8 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd, httpd.allowLocalNetworkAccess, httpd.city, httpd.systemLanguage, httpd.sharedItemsFederatedDomains, - httpd.sharedItemFederationTokens): + httpd.sharedItemFederationTokens, + httpd.lowBandwidth): indexLines.remove(line) os.remove(postFilename) continue diff --git a/shares.py b/shares.py index 0d8b85315..4d16f0fbb 100644 --- a/shares.py +++ b/shares.py @@ -38,6 +38,7 @@ from utils import isfloat from utils import getCategoryTypes from utils import getSharesFilesList from media import processMetaData +from media import convertImageToLowBandwidth from filters import isFilteredGlobally from siteactive import siteIsActive from content import getPriceFromString @@ -293,7 +294,7 @@ def addShare(baseDir: str, duration: str, debug: bool, city: str, price: str, currency: str, systemLanguage: str, translate: {}, - sharesFileType: str) -> None: + sharesFileType: str, lowBandwidth: bool) -> None: """Adds a new share """ if isFilteredGlobally(baseDir, @@ -343,6 +344,8 @@ def addShare(baseDir: str, for ext in formats: if not imageFilename.endswith('.' + ext): continue + if lowBandwidth: + convertImageToLowBandwidth(imageFilename) processMetaData(baseDir, nickname, domain, imageFilename, itemIDfile + '.' + ext, city) @@ -989,7 +992,8 @@ def getSharedItemsCatalogViaServer(baseDir, session, def outboxShareUpload(baseDir: str, httpPrefix: str, nickname: str, domain: str, port: int, 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 """ if not messageJson.get('type'): @@ -1054,7 +1058,8 @@ def outboxShareUpload(baseDir: str, httpPrefix: str, debug, city, messageJson['object']['itemPrice'], messageJson['object']['itemCurrency'], - systemLanguage, translate, 'shares') + systemLanguage, translate, 'shares', + lowBandwidth) if debug: print('DEBUG: shared item received via c2s')