Skip to content

Commit 49a39a7

Browse files
committed
Simplify URI to file path conversion
1 parent f568407 commit 49a39a7

File tree

2 files changed

+13
-53
lines changed

2 files changed

+13
-53
lines changed

auto_editor/formats/fcp7.py

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import xml.etree.ElementTree as ET
44
from fractions import Fraction
5-
from io import StringIO
65
from math import ceil
76
from typing import TYPE_CHECKING
87
from xml.etree.ElementTree import Element
@@ -29,59 +28,20 @@
2928

3029

3130
def uri_to_path(uri: str) -> str:
32-
def de_norm(s: str) -> str:
33-
uri_escape = {
34-
"3C": "<",
35-
"3E": ">",
36-
"23": "#",
37-
"25": "%",
38-
"2B": "+",
39-
"7B": "{",
40-
"7D": "}",
41-
"7C": "|",
42-
"5C": "\\",
43-
"5E": "^",
44-
"7E": "~",
45-
"5B": "[",
46-
"5D": "]",
47-
"60": "`",
48-
"3F": "?",
49-
"3A": ":",
50-
"40": "@",
51-
"3D": "=",
52-
"2A": "*",
53-
"29": ")",
54-
"28": "(",
55-
"27": "'",
56-
"26": "&",
57-
"24": "$",
58-
"22": '"',
59-
"21": "!",
60-
"20": " ",
61-
}
62-
buf = StringIO()
63-
i = 0
64-
while i < len(s):
65-
if s[i] == "%" and len(s) > i + 3:
66-
tag = s[i + 1 : i + 3]
67-
if tag in uri_escape:
68-
buf.write(uri_escape[tag])
69-
i += 3
70-
else:
71-
buf.write(s[i])
72-
i += 1
73-
else:
74-
buf.write(s[i])
75-
i += 1
76-
return buf.getvalue()
31+
urllib = __import__("urllib.parse", fromlist=["parse"])
7732

7833
if uri.startswith("file://localhost/"):
79-
return de_norm(uri[16:])
80-
if uri.startswith("file://"):
81-
if uri[9] == ":": # Handle Windows-style paths
82-
return de_norm(uri[8:])
83-
return de_norm(uri[7:])
84-
return uri
34+
uri = uri[16:]
35+
elif uri.startswith("file://"):
36+
# Windows-style paths
37+
if len(uri) > 8 and uri[9] == ":":
38+
uri = uri[8:]
39+
else:
40+
uri = uri[7:]
41+
else:
42+
return uri
43+
44+
return urllib.parse.unquote(uri)
8545

8646
# /Users/wyattblue/projects/auto-editor/example.mp4
8747
# file:///Users/wyattblue/projects/auto-editor/example.mp4

docs/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ app.get("/blog/{*splat}", (req, res) => {
1515
});
1616

1717
app.get("/options", (req, res) => {
18-
res.redirect(301, "https://basswood-io.com/ref/options");
18+
res.redirect(301, "https://auto-editor.com/ref/options");
1919
});
2020

2121
app.use(express.static("public", {

0 commit comments

Comments
 (0)