Skip to content

Commit

Permalink
Update matterport-dl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mu-ramadan authored Jul 14, 2022
1 parent d8656c7 commit 26bef76
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions matterport-dl.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3

'''
Downloads virtual tours from matterport.
Usage is either running this program with the URL/pageid as an argument or calling the initiateDownload(URL/pageid) method.
'''

import uuid
import requests
import json
Expand All @@ -21,6 +23,7 @@
from http.server import HTTPServer, SimpleHTTPRequestHandler
import decimal


# Weird hack
accessurls = []
SHOWCASE_INTERNAL_NAME = "showcase-internal.js"
Expand Down Expand Up @@ -229,12 +232,8 @@ def setAccessURLs(pageid):


def downloadInfo(pageid):
<<<<<<< Updated upstream
assets = [f"api/v1/jsonstore/model/highlights/{pageid}", f"api/v1/jsonstore/model/Labels/{pageid}", f"api/v1/jsonstore/model/mattertags/{pageid}", f"api/v1/jsonstore/model/measurements/{pageid}", f"api/v1/player/models/{pageid}/thumb?width=1707&dpr=1.5&disable=upscale", f"api/v1/player/models/{pageid}/", f"api/v2/models/{pageid}/sweeps", "api/v2/users/current", f"api/player/models/{pageid}/files"]
=======
assets = [f"api/v1/jsonstore/model/highlights/{pageid}", f"api/v1/jsonstore/model/Labels/{pageid}", f"api/v1/jsonstore/model/mattertags/{pageid}", f"api/v1/jsonstore/model/measurements/{pageid}",
f"api/v1/player/models/{pageid}/thumb?width=1707&dpr=1.5&disable=upscale", f"api/v1/player/models/{pageid}/", f"api/v2/models/{pageid}/sweeps", "api/v2/users/current", f"api/player/models/{pageid}/files", f"api/v1/jsonstore/model/trims/{pageid}"]
>>>>>>> Stashed changes
with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor:
for asset in assets:
local_file = asset
Expand Down Expand Up @@ -272,18 +271,6 @@ def downloadModel(pageid, accessurl):
downloadSweeps(accessurl, modeldata["sweeps"])


def progressbar(it, prefix="", size=60, out=sys.stdout): # Python3.6+
count = len(it)
def show(j):
x = int(size*j/count)
print(f"{prefix}[{u'█'*x}{('.'*(size-x))}] {j}/{count}", end='\r', file=out, flush=True)
show(0)
for i, item in enumerate(it):
yield item
show(i+1)
print("\n", flush=True, file=out)


# Patch showcase.js to fix expiration issue
def patchShowcase():
global SHOWCASE_INTERNAL_NAME
Expand Down Expand Up @@ -455,18 +442,12 @@ def downloadPage(pageid):


# Automatic redirect if GET param isn't correct
<<<<<<< Updated upstream
injectedjs = 'if (window.location.search != "?m=' + pageid + '") { document.location.search = "?m=' + pageid + '"; }'
content = r.text.replace(staticbase,".").replace('"https://cdn-1.matterport.com/','`${window.location.origin}${window.location.pathname}` + "').replace('"https://mp-app-prod.global.ssl.fastly.net/','`${window.location.origin}${window.location.pathname}` + "').replace("window.MP_PREFETCHED_MODELDATA",f"{injectedjs};window.MP_PREFETCHED_MODELDATA").replace('"https://events.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "')
content = re.sub(r"validUntil\":\s*\"20[\d]{2}-[\d]{2}-[\d]{2}T","validUntil\":\"2099-01-01T",content)
=======
injectedjs = 'if (window.location.search != "?m=' + pageid + \
'") { document.location.search = "?m=' + pageid + '"; }'
content = r.text.replace(staticbase, ".").replace('"https://cdn-1.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "').replace('"https://mp-app-prod.global.ssl.fastly.net/', '`${window.location.origin}${window.location.pathname}` + "').replace(
"window.MP_PREFETCHED_MODELDATA", f"{injectedjs};window.MP_PREFETCHED_MODELDATA").replace('"https://events.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "').replace('"https://cdn-2.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "')
content = re.sub(
r"validUntil\":\s*\"20[\d]{2}-[\d]{2}-[\d]{2}T", "validUntil\":\"2099-01-01T", content)
>>>>>>> Stashed changes
with open("index.html", "w", encoding="UTF-8") as f:
f.write(content)

Expand Down Expand Up @@ -644,4 +625,4 @@ def getCommandLineArg(name, has_value):
(sys.argv[2], int(sys.argv[3])), OurSimpleHTTPRequestHandler)
httpd.serve_forever()
else:
print(f"Usage:\n\tFirst Download: matterport-dl.py [url_or_page_id]\n\tThen launch the server 'matterport-dl.py [url_or_page_id] 127.0.0.1 8080' and open http://127.0.0.1:8080 in a browser\n\t--proxy 127.0.0.1:1234 -- to have it use this web proxy\n\t--advanced-download -- Use this option to try and download the cropped files for dollhouse/floorplan support")
print(f"Usage:\n\tFirst Download: matterport-dl.py [url_or_page_id]\n\tThen launch the server 'matterport-dl.py [url_or_page_id] 127.0.0.1 8080' and open http://127.0.0.1:8080 in a browser\n\t--proxy 127.0.0.1:1234 -- to have it use this web proxy\n\t--advanced-download -- Use this option to try and download the cropped files for dollhouse/floorplan support")

0 comments on commit 26bef76

Please sign in to comment.