Skip to content

Commit 76540a0

Browse files
author
Slyke
committed
Added gitkeep in clones directory
Added requirements.txt and Dockerfile Merge branch 'main' into add-docker Refactored dockerfile and created entrypoint script for using env vars Updated docker run examples. Refactored bootstrap code Added error for moving downloaded matterport to correct directory Remnoved show_case from js files, updated readme to run detatched mode added missing js files to aray Merge branch 'main' of github.com:rebane2001/matterport-dl into add-docker fixed uncaught merge conflict Made requested changes from PR
1 parent f9f1a12 commit 76540a0

File tree

7 files changed

+108
-14
lines changed

7 files changed

+108
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
clones/

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.10.1
2+
WORKDIR /matterport-dl
3+
4+
COPY requirements.txt requirements.txt
5+
RUN pip3 install -r requirements.txt
6+
7+
COPY docker-entrypoint.sh docker-entrypoint.sh
8+
COPY graph_posts graph_posts
9+
COPY matterport-dl.py matterport-dl.py
10+
11+
CMD [ "/bin/sh", "docker-entrypoint.sh" ]

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ A tool to download/archive [Matterport](https://matterport.com) virtual tours.
1414
- Add `--proxy 127.0.0.1:1234` to a download run to use a proxy for requests
1515
- Add `--advanced-download` to a download run to try and download the needed textures and files for supporting dollhouse/floorplan views. NOTE: Must use built in webserver to host content for this to work.
1616

17+
# Docker
18+
## Docker params
19+
```
20+
docker build -t matterport-dl .
21+
docker run -v $(pwd)/clones:/matterport-dl/clones -e M_ID=[url_or_page_id] matterport-dl
22+
docker run -p 8080:8080 -v $(pwd)/clones:/matterport-dl/clones -e M_ID=[url_or_page_id] -e BIND_IP=0.0.0.0 -e BIND_PORT=8080 -e ADV_DL=true -e PROXY=127.0.0.1:1234 -e BASE_FOLDER="./clones" matterport-dl
23+
```
24+
25+
* M_ID Matterport ID or URL
26+
* BIND_PORT Defaults to 8080 if not set
27+
* BIND_IP IP address to bind to. Use `0.0.0.0` unless setting docker network to host.
28+
* ADV_DL is for the --advanced-download flag, and is off by default. Setting this to anything will activate it.
29+
* PROXY is for the --proxy flag, and is off by default.
30+
* BASE_FOLDER is where the downloads go. Defaults to "./clones"
31+
32+
## Docker example
33+
```
34+
docker build -t matterport-dl .
35+
docker run -v $(pwd)/clones:/matterport-dl/clones -e M_ID="https://my.matterport.com/show/?m=roWLLMMmPL8" -e ADV_DL=true matterport-dl
36+
docker run -p 8080:8080 -v $(pwd)/clones:/matterport-dl/clones -e M_ID=roWLLMMmPL8 -e BIND_IP=0.0.0.0 -d matterport-dl
37+
```
38+
39+
## Docker debugging
40+
```
41+
docker build --no-cache -t matterport-dl .
42+
docker run -t -i -p 8080:8080 -v $(pwd)/clones:/matterport-dl/clones -e M_ID=roWLLMMmPL8 -e BIND_IP=0.0.0.0 matterport-dl /bin/bash
43+
```
1744

1845
# Additional Notes
1946
* It is possible to host these Matterport archives using standard web servers however: 1) Certain features beyond the tour itself may not work. 2) #1 may be fixable by specific rewrite rules for apache/nginx. These are not currently provided but if you look at `OurSimpleHTTPRequestHandler` class near the bottom of the source file you can likely figure out what redirects we do.

clones/.gitkeep

Whitespace-only changes.

docker-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [[ -z "${BIND_PORT}" ]] && [[ -n "$BIND_IP" ]]; then
5+
echo "Defaulting to port 8080"
6+
BIND_PORT=8080
7+
fi
8+
9+
if [[ -n "${PROXY}" ]]; then
10+
echo "Using proxy: '$PROXY'"
11+
PROXYARG="--proxy $PROXY"
12+
fi
13+
14+
if [[ -n "${BASE_FOLDER}" ]]; then
15+
echo "Using base folder: '$BASE_FOLDER'"
16+
BASEFOLDERARG="--base-folder $BASE_FOLDER"
17+
fi
18+
19+
if [[ -n "${ADV_DL}" ]]; then
20+
ADVDLARG="--advanced-download"
21+
fi
22+
23+
cd /matterport-dl
24+
/usr/local/bin/python3 matterport-dl.py $M_ID $BIND_IP $BIND_PORT $ADVDLARG $PROXYARG $BASEFOLDERARG

matterport-dl.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'''
77

88
import requests
9+
import functools
910
import json
1011
import threading
1112
import concurrent.futures
@@ -22,7 +23,9 @@
2223
from http.server import HTTPServer, SimpleHTTPRequestHandler
2324
import decimal
2425

26+
print = functools.partial(print, flush=True)
2527

28+
baseCloneDir = "clones/"
2629

2730
# Weird hack
2831
accessurls = []
@@ -136,7 +139,7 @@ def downloadGraphModels(pageid):
136139
def downloadAssets(base):
137140
js_files = ["browser-check",
138141
"30","47","66","79","134","136","143","164","250","251","316","321","356","371","376","383","386","423",
139-
"464","524","525","539","584","606","614","666","718","721","726","764","828","833","838","932","947"]
142+
"464","524","525","539","580","584","606","614","666","718","721","726","764","828","833","838","932","947"]
140143
language_codes = ["af", "sq", "ar-SA", "ar-IQ", "ar-EG", "ar-LY", "ar-DZ", "ar-MA", "ar-TN", "ar-OM",
141144
"ar-YE", "ar-SY", "ar-JO", "ar-LB", "ar-KW", "ar-AE", "ar-BH", "ar-QA", "eu", "bg",
142145
"be", "ca", "zh-TW", "zh-CN", "zh-HK", "zh-SG", "hr", "cs", "da", "nl", "nl-BE", "en",
@@ -291,8 +294,10 @@ def downloadPage(pageid):
291294
}
292295
]
293296

294-
295-
logging.basicConfig(filename='run_report.log', encoding='utf-8', level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
297+
try:
298+
logging.basicConfig(filename='run_report.log', encoding='utf-8', level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
299+
except ValueError:
300+
logging.basicConfig(filename='run_report.log', level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
296301
logging.debug(f'Started up a download run')
297302
page_root_dir = os.path.abspath('.')
298303
print("Downloading base page...")
@@ -304,6 +309,7 @@ def downloadPage(pageid):
304309
accessurl = f'{match.group(1)}~/{{filename}}{match.group(3)}'
305310
print(accessurl)
306311
else:
312+
print('Requesting', pageid)
307313
raise Exception("Can't find urls")
308314

309315

@@ -388,6 +394,10 @@ def getPageId(url):
388394
return url.split("m=")[-1].split("&")[0]
389395

390396
class OurSimpleHTTPRequestHandler(SimpleHTTPRequestHandler):
397+
def __init__(self, *args, **kwargs):
398+
SERVEDIR=pageId
399+
super().__init__(*args, directory=SERVEDIR, **kwargs)
400+
391401
def send_error(self, code, message=None):
392402
if code == 404:
393403
logging.warning(f'404 error: {self.path} may not be downloading everything right')
@@ -402,7 +412,7 @@ def do_GET(self):
402412
self.path = f"/js/{SHOWCASE_INTERNAL_NAME}"
403413

404414
if self.path.startswith("/locale/messages/strings_") and not os.path.exists(f".{self.path}"):
405-
redirect_msg = "original request was for a locale we do not have downloaded"
415+
redirect_msg = "original request was for a locale that is not downloaded"
406416
self.path = "/locale/strings.json"
407417
raw_path, _, query = self.path.partition('?')
408418
if "crop=" in query and raw_path.endswith(".jpg"):
@@ -498,21 +508,40 @@ def getCommandLineArg(name, has_value):
498508

499509
if __name__ == "__main__":
500510
ADVANCED_DOWNLOAD_ALL = getCommandLineArg("--advanced-download", False)
511+
customBaseCloneDir = getCommandLineArg("--base-folder", True)
512+
if customBaseCloneDir:
513+
baseCloneDir = customBaseCloneDir
501514
PROXY = getCommandLineArg("--proxy", True)
502515
OUR_OPENER = getUrlOpener(PROXY)
503516
urllib.request.install_opener(OUR_OPENER)
504-
pageId = ""
505-
if len(sys.argv) > 1:
506-
pageId = getPageId(sys.argv[1])
507-
openDirReadGraphReqs("graph_posts",pageId)
508-
if len(sys.argv) == 2:
517+
pageId = getPageId(sys.argv[1])
518+
if len(sys.argv) == 2: # Download mode
519+
os.chdir(baseCloneDir)
520+
openDirReadGraphReqs("graph_posts",pageId)
509521
initiateDownload(pageId)
510-
elif len(sys.argv) == 4:
511-
os.chdir(getPageId(pageId))
512-
logging.basicConfig(filename='server.log', encoding='utf-8', level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
513-
logging.info("Server started up")
514-
print ("View in browser: http://" + sys.argv[2] + ":" + sys.argv[3])
522+
elif len(sys.argv) == 4: # Serve mode
523+
if os.path.isdir(pageId) and not os.path.isdir(os.path.join(baseCloneDir, pageId)):
524+
print("WARNING:")
525+
print("The folder '" + pageId + "' does not exist in the '" + baseCloneDir + "' directory, but does exist in the root directory.")
526+
print("If you recently updated matterport-dl, then please move the '" + pageId + "' folder into the '" + baseCloneDir + "' directory")
527+
print("For the time being, this will continue to work, but eventually all downloads need to be moved")
528+
print(" ")
529+
time.sleep(2)
530+
else:
531+
os.chdir(baseCloneDir)
532+
if not os.path.isdir(pageId):
533+
print("The folder '" + pageId + "' does not exist. Please download it using the download command. See the readme for more details")
534+
sys.exit()
535+
try:
536+
logging.basicConfig(filename='server.log', encoding='utf-8', level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
537+
except ValueError:
538+
logging.basicConfig(filename='server.log', level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
515539
httpd = HTTPServer((sys.argv[2], int(sys.argv[3])), OurSimpleHTTPRequestHandler)
540+
logging.info("Server started up")
541+
if sys.argv[2] == '0.0.0.0':
542+
print ("View in browser: http://localhost:" + sys.argv[3])
543+
else:
544+
print ("View in browser: http://" + sys.argv[2] + ":" + sys.argv[3])
516545
httpd.serve_forever()
517546
else:
518547
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")

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tqdm>=4.62.3
2+
requests>=2.26.0

0 commit comments

Comments
 (0)