ssstktok-url-parser 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ssstktok_url_parser-1.0.1/LICENSE +21 -0
- ssstktok_url_parser-1.0.1/PKG-INFO +105 -0
- ssstktok_url_parser-1.0.1/README.md +75 -0
- ssstktok_url_parser-1.0.1/pyproject.toml +51 -0
- ssstktok_url_parser-1.0.1/setup.cfg +4 -0
- ssstktok_url_parser-1.0.1/ssstktok_url_parser/__init__.py +162 -0
- ssstktok_url_parser-1.0.1/ssstktok_url_parser.egg-info/PKG-INFO +105 -0
- ssstktok_url_parser-1.0.1/ssstktok_url_parser.egg-info/SOURCES.txt +9 -0
- ssstktok_url_parser-1.0.1/ssstktok_url_parser.egg-info/dependency_links.txt +1 -0
- ssstktok_url_parser-1.0.1/ssstktok_url_parser.egg-info/entry_points.txt +2 -0
- ssstktok_url_parser-1.0.1/ssstktok_url_parser.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ssstktok (https://ssstktok.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ssstktok-url-parser
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Zero-dependency Python utility to parse, normalize, strip tracking parameters, and extract 19-digit media IDs from short-form video, story, and photo carousel URLs.
|
|
5
|
+
Author-email: ssstktok Engineering <asemalatif@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://ssstktok.com
|
|
8
|
+
Project-URL: Documentation, https://ssstktok.com/add-on
|
|
9
|
+
Project-URL: Repository, https://github.com/ssstktok/tiktok-video-downloader-ssstktok
|
|
10
|
+
Project-URL: Android App, https://ssstktok.com/apk
|
|
11
|
+
Keywords: url-parser,media-id,video-url,slideshow-parser,ssstktok,shortlink-normalizer
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
|
+
Classifier: Topic :: Multimedia :: Video
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# ssstktok-url-parser (Python SDK)
|
|
32
|
+
|
|
33
|
+
Lightweight, zero-dependency Python 3 library and CLI utility to parse, normalize, strip tracking query parameters, and extract 19-digit media IDs (`video`, `photo` carousel, `story`, and shortlinks) from raw mobile share strings and URLs.
|
|
34
|
+
|
|
35
|
+
Built and maintained by the engineering team at **[ssstktok — HD Video, Story & MP3 Downloader](https://ssstktok.com)** (companion to the official Node.js/TypeScript package `ssstktok-url-parser` on NPM).
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## ✨ Features
|
|
40
|
+
|
|
41
|
+
- **Zero External Dependencies**: Uses only Python's standard library (`urllib.parse`, `re`, `dataclasses`, `typing`).
|
|
42
|
+
- **Share-Text Extraction**: Automatically locates and extracts URLs embedded inside dirty mobile clipboard copy strings.
|
|
43
|
+
- **Tracking Parameter Sanitization**: Strips UTM and device query strings (`?is_from_webapp=1&sender_device=pc`) to produce canonical URLs.
|
|
44
|
+
- **Multi-Format Classification**: Identifies standard `video` streams, multi-image `photo` carousels (supported by the **[Photo Slideshow & Carousel Downloader](https://ssstktok.com/slide-downloader)**), 24-hour `story` posts, and audio extraction endpoints via the **[TikTok to MP3 Audio Extractor](https://ssstktok.com/download-tiktok-mp3)**.
|
|
45
|
+
- **Full Type Hints (`PEP 561`)**: Returns immutable `ParsedMediaUrl` dataclasses or JSON-serializable dictionaries.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 📦 Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install ssstktok-url-parser
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 🚀 Quick Start (Python)
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from ssstktok_url_parser import parse_media_url, extract_media_id, get_tool_endpoint
|
|
61
|
+
|
|
62
|
+
# 1. Parse raw mobile clipboard text containing tracking parameters
|
|
63
|
+
raw_share = "Check out this clip! https://www.tiktok.com/@creator/video/7391827364519283746?is_from_webapp=1&sender_device=pc"
|
|
64
|
+
res = parse_media_url(raw_share)
|
|
65
|
+
|
|
66
|
+
print(res.is_valid) # True
|
|
67
|
+
print(res.clean_url) # "https://www.tiktok.com/@creator/video/7391827364519283746"
|
|
68
|
+
print(res.item_id) # "7391827364519283746"
|
|
69
|
+
print(res.media_type) # "video"
|
|
70
|
+
print(res.username) # "creator"
|
|
71
|
+
|
|
72
|
+
# 2. Quickly extract only the 19-digit numeric ID
|
|
73
|
+
photo_id = extract_media_id("https://www.tiktok.com/@artist/photo/7399999999999999999")
|
|
74
|
+
print(photo_id) # "7399999999999999999"
|
|
75
|
+
|
|
76
|
+
# 3. Resolve the matching web utility endpoint
|
|
77
|
+
print(get_tool_endpoint("mp3")) # "https://ssstktok.com/download-tiktok-mp3"
|
|
78
|
+
print(get_tool_endpoint("photo")) # "https://ssstktok.com/slide-downloader"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🖥️ Command-Line Interface (CLI)
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
ssstktok-parse "https://www.tiktok.com/@creator/video/7391827364519283746?is_from_webapp=1"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Output:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"is_valid": true,
|
|
94
|
+
"clean_url": "https://www.tiktok.com/@creator/video/7391827364519283746",
|
|
95
|
+
"item_id": "7391827364519283746",
|
|
96
|
+
"media_type": "video",
|
|
97
|
+
"username": "creator"
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 📄 License
|
|
104
|
+
|
|
105
|
+
MIT License © ssstktok Engineering
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# ssstktok-url-parser (Python SDK)
|
|
2
|
+
|
|
3
|
+
Lightweight, zero-dependency Python 3 library and CLI utility to parse, normalize, strip tracking query parameters, and extract 19-digit media IDs (`video`, `photo` carousel, `story`, and shortlinks) from raw mobile share strings and URLs.
|
|
4
|
+
|
|
5
|
+
Built and maintained by the engineering team at **[ssstktok — HD Video, Story & MP3 Downloader](https://ssstktok.com)** (companion to the official Node.js/TypeScript package `ssstktok-url-parser` on NPM).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **Zero External Dependencies**: Uses only Python's standard library (`urllib.parse`, `re`, `dataclasses`, `typing`).
|
|
12
|
+
- **Share-Text Extraction**: Automatically locates and extracts URLs embedded inside dirty mobile clipboard copy strings.
|
|
13
|
+
- **Tracking Parameter Sanitization**: Strips UTM and device query strings (`?is_from_webapp=1&sender_device=pc`) to produce canonical URLs.
|
|
14
|
+
- **Multi-Format Classification**: Identifies standard `video` streams, multi-image `photo` carousels (supported by the **[Photo Slideshow & Carousel Downloader](https://ssstktok.com/slide-downloader)**), 24-hour `story` posts, and audio extraction endpoints via the **[TikTok to MP3 Audio Extractor](https://ssstktok.com/download-tiktok-mp3)**.
|
|
15
|
+
- **Full Type Hints (`PEP 561`)**: Returns immutable `ParsedMediaUrl` dataclasses or JSON-serializable dictionaries.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install ssstktok-url-parser
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Start (Python)
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from ssstktok_url_parser import parse_media_url, extract_media_id, get_tool_endpoint
|
|
31
|
+
|
|
32
|
+
# 1. Parse raw mobile clipboard text containing tracking parameters
|
|
33
|
+
raw_share = "Check out this clip! https://www.tiktok.com/@creator/video/7391827364519283746?is_from_webapp=1&sender_device=pc"
|
|
34
|
+
res = parse_media_url(raw_share)
|
|
35
|
+
|
|
36
|
+
print(res.is_valid) # True
|
|
37
|
+
print(res.clean_url) # "https://www.tiktok.com/@creator/video/7391827364519283746"
|
|
38
|
+
print(res.item_id) # "7391827364519283746"
|
|
39
|
+
print(res.media_type) # "video"
|
|
40
|
+
print(res.username) # "creator"
|
|
41
|
+
|
|
42
|
+
# 2. Quickly extract only the 19-digit numeric ID
|
|
43
|
+
photo_id = extract_media_id("https://www.tiktok.com/@artist/photo/7399999999999999999")
|
|
44
|
+
print(photo_id) # "7399999999999999999"
|
|
45
|
+
|
|
46
|
+
# 3. Resolve the matching web utility endpoint
|
|
47
|
+
print(get_tool_endpoint("mp3")) # "https://ssstktok.com/download-tiktok-mp3"
|
|
48
|
+
print(get_tool_endpoint("photo")) # "https://ssstktok.com/slide-downloader"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 🖥️ Command-Line Interface (CLI)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ssstktok-parse "https://www.tiktok.com/@creator/video/7391827364519283746?is_from_webapp=1"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Output:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"is_valid": true,
|
|
64
|
+
"clean_url": "https://www.tiktok.com/@creator/video/7391827364519283746",
|
|
65
|
+
"item_id": "7391827364519283746",
|
|
66
|
+
"media_type": "video",
|
|
67
|
+
"username": "creator"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 📄 License
|
|
74
|
+
|
|
75
|
+
MIT License © ssstktok Engineering
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ssstktok-url-parser"
|
|
7
|
+
version = "1.0.1"
|
|
8
|
+
description = "Zero-dependency Python utility to parse, normalize, strip tracking parameters, and extract 19-digit media IDs from short-form video, story, and photo carousel URLs."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "ssstktok Engineering", email = "asemalatif@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"url-parser",
|
|
17
|
+
"media-id",
|
|
18
|
+
"video-url",
|
|
19
|
+
"slideshow-parser",
|
|
20
|
+
"ssstktok",
|
|
21
|
+
"shortlink-normalizer"
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 5 - Production/Stable",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Operating System :: OS Independent",
|
|
28
|
+
"Programming Language :: Python :: 3",
|
|
29
|
+
"Programming Language :: Python :: 3.8",
|
|
30
|
+
"Programming Language :: Python :: 3.9",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
35
|
+
"Topic :: Multimedia :: Video",
|
|
36
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
37
|
+
"Typing :: Typed"
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://ssstktok.com"
|
|
42
|
+
Documentation = "https://ssstktok.com/add-on"
|
|
43
|
+
Repository = "https://github.com/ssstktok/tiktok-video-downloader-ssstktok"
|
|
44
|
+
"Android App" = "https://ssstktok.com/apk"
|
|
45
|
+
|
|
46
|
+
[project.scripts]
|
|
47
|
+
ssstktok-parse = "ssstktok_url_parser:main"
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.packages.find]
|
|
50
|
+
where = ["."]
|
|
51
|
+
include = ["ssstktok_url_parser*"]
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ssstktok_url_parser
|
|
3
|
+
Zero-dependency Python library to parse, normalize, strip tracking parameters,
|
|
4
|
+
and extract 19-digit media IDs from short-form video, photo slideshow, and story URLs.
|
|
5
|
+
Official Web Platform: https://ssstktok.com
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass, asdict
|
|
9
|
+
import json
|
|
10
|
+
import re
|
|
11
|
+
import sys
|
|
12
|
+
from typing import Optional, Dict, Any
|
|
13
|
+
from urllib.parse import urlparse
|
|
14
|
+
|
|
15
|
+
__version__ = "1.0.1"
|
|
16
|
+
__all__ = [
|
|
17
|
+
"ParsedMediaUrl",
|
|
18
|
+
"parse_media_url",
|
|
19
|
+
"parse_tiktok_url",
|
|
20
|
+
"extract_media_id",
|
|
21
|
+
"get_tool_endpoint",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
SUPPORTED_HOSTS = {
|
|
25
|
+
"tiktok.com",
|
|
26
|
+
"www.tiktok.com",
|
|
27
|
+
"m.tiktok.com",
|
|
28
|
+
"vm.tiktok.com",
|
|
29
|
+
"vt.tiktok.com",
|
|
30
|
+
"douyin.com",
|
|
31
|
+
"www.douyin.com",
|
|
32
|
+
"v.douyin.com",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_URL_EXTRACT_RE = re.compile(r"https?://[^\s\"'<>]+", re.IGNORECASE)
|
|
36
|
+
_CANONICAL_PATH_RE = re.compile(r"^/@([^/]+)/(video|photo|story)/(\d+)", re.IGNORECASE)
|
|
37
|
+
_MOBILE_VIDEO_RE = re.compile(r"^/v/(\d+)", re.IGNORECASE)
|
|
38
|
+
_SHARE_ITEM_RE = re.compile(r"^/(?:share/)?(?:video|photo)/(\d+)", re.IGNORECASE)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class ParsedMediaUrl:
|
|
43
|
+
is_valid: bool
|
|
44
|
+
clean_url: Optional[str] = None
|
|
45
|
+
item_id: Optional[str] = None
|
|
46
|
+
media_type: Optional[str] = None
|
|
47
|
+
username: Optional[str] = None
|
|
48
|
+
|
|
49
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
50
|
+
return asdict(self)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def parse_media_url(raw_input: str) -> ParsedMediaUrl:
|
|
54
|
+
"""
|
|
55
|
+
Extracts and normalizes a short-form video, photo carousel, or story URL
|
|
56
|
+
from raw clipboard or mobile share text.
|
|
57
|
+
"""
|
|
58
|
+
if not raw_input or not isinstance(raw_input, str):
|
|
59
|
+
return ParsedMediaUrl(is_valid=False)
|
|
60
|
+
|
|
61
|
+
match = _URL_EXTRACT_RE.search(raw_input)
|
|
62
|
+
candidate = match.group(0) if match else raw_input.strip()
|
|
63
|
+
|
|
64
|
+
try:
|
|
65
|
+
parsed = urlparse(candidate)
|
|
66
|
+
except ValueError:
|
|
67
|
+
return ParsedMediaUrl(is_valid=False)
|
|
68
|
+
|
|
69
|
+
if parsed.scheme not in ("http", "https") or not parsed.hostname:
|
|
70
|
+
return ParsedMediaUrl(is_valid=False)
|
|
71
|
+
|
|
72
|
+
host = parsed.hostname.lower()
|
|
73
|
+
is_supported = (
|
|
74
|
+
host in SUPPORTED_HOSTS
|
|
75
|
+
or host.endswith(".tiktok.com")
|
|
76
|
+
or host.endswith(".douyin.com")
|
|
77
|
+
)
|
|
78
|
+
if not is_supported:
|
|
79
|
+
return ParsedMediaUrl(is_valid=False)
|
|
80
|
+
|
|
81
|
+
canonical = _CANONICAL_PATH_RE.match(parsed.path)
|
|
82
|
+
if canonical:
|
|
83
|
+
username, m_type, item_id = (
|
|
84
|
+
canonical.group(1),
|
|
85
|
+
canonical.group(2).lower(),
|
|
86
|
+
canonical.group(3),
|
|
87
|
+
)
|
|
88
|
+
return ParsedMediaUrl(
|
|
89
|
+
is_valid=True,
|
|
90
|
+
clean_url=f"https://www.tiktok.com/@{username}/{m_type}/{item_id}",
|
|
91
|
+
item_id=item_id,
|
|
92
|
+
media_type=m_type,
|
|
93
|
+
username=username,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
mobile = _MOBILE_VIDEO_RE.match(parsed.path)
|
|
97
|
+
if mobile:
|
|
98
|
+
item_id = mobile.group(1)
|
|
99
|
+
return ParsedMediaUrl(
|
|
100
|
+
is_valid=True,
|
|
101
|
+
clean_url=f"https://www.tiktok.com/v/{item_id}",
|
|
102
|
+
item_id=item_id,
|
|
103
|
+
media_type="video",
|
|
104
|
+
username=None,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
share_item = _SHARE_ITEM_RE.match(parsed.path)
|
|
108
|
+
if share_item:
|
|
109
|
+
item_id = share_item.group(1)
|
|
110
|
+
return ParsedMediaUrl(
|
|
111
|
+
is_valid=True,
|
|
112
|
+
clean_url=f"https://www.tiktok.com/v/{item_id}",
|
|
113
|
+
item_id=item_id,
|
|
114
|
+
media_type="video",
|
|
115
|
+
username=None,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
clean_short = f"{parsed.scheme}://{host}{parsed.path}".rstrip("/")
|
|
119
|
+
return ParsedMediaUrl(
|
|
120
|
+
is_valid=True,
|
|
121
|
+
clean_url=clean_short,
|
|
122
|
+
item_id=None,
|
|
123
|
+
media_type="shortlink",
|
|
124
|
+
username=None,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def parse_tiktok_url(raw_input: str) -> Dict[str, Any]:
|
|
129
|
+
"""Alias returning a dictionary matching the JavaScript ssstktok-url-parser API."""
|
|
130
|
+
res = parse_media_url(raw_input)
|
|
131
|
+
return {
|
|
132
|
+
"isValid": res.is_valid,
|
|
133
|
+
"cleanUrl": res.clean_url,
|
|
134
|
+
"itemId": res.item_id,
|
|
135
|
+
"type": res.media_type,
|
|
136
|
+
"username": res.username,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def extract_media_id(raw_input: str) -> Optional[str]:
|
|
141
|
+
"""Quickly extracts the 19-digit numeric media ID if present in the URL."""
|
|
142
|
+
return parse_media_url(raw_input).item_id
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def get_tool_endpoint(media_type: str = "video") -> str:
|
|
146
|
+
"""Returns the corresponding ssstktok.com web endpoint for a media type."""
|
|
147
|
+
kind = (media_type or "video").lower()
|
|
148
|
+
if kind == "mp3":
|
|
149
|
+
return "https://ssstktok.com/download-tiktok-mp3"
|
|
150
|
+
if kind == "story":
|
|
151
|
+
return "https://ssstktok.com/download-tiktok-stories"
|
|
152
|
+
if kind == "photo":
|
|
153
|
+
return "https://ssstktok.com/slide-downloader"
|
|
154
|
+
return "https://ssstktok.com/"
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def main() -> None:
|
|
158
|
+
if len(sys.argv) < 2:
|
|
159
|
+
print("Usage: ssstktok-parse <url-or-share-text>")
|
|
160
|
+
sys.exit(1)
|
|
161
|
+
result = parse_media_url(" ".join(sys.argv[1:]))
|
|
162
|
+
print(json.dumps(result.to_dict(), indent=2))
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ssstktok-url-parser
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Zero-dependency Python utility to parse, normalize, strip tracking parameters, and extract 19-digit media IDs from short-form video, story, and photo carousel URLs.
|
|
5
|
+
Author-email: ssstktok Engineering <asemalatif@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://ssstktok.com
|
|
8
|
+
Project-URL: Documentation, https://ssstktok.com/add-on
|
|
9
|
+
Project-URL: Repository, https://github.com/ssstktok/tiktok-video-downloader-ssstktok
|
|
10
|
+
Project-URL: Android App, https://ssstktok.com/apk
|
|
11
|
+
Keywords: url-parser,media-id,video-url,slideshow-parser,ssstktok,shortlink-normalizer
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
|
+
Classifier: Topic :: Multimedia :: Video
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# ssstktok-url-parser (Python SDK)
|
|
32
|
+
|
|
33
|
+
Lightweight, zero-dependency Python 3 library and CLI utility to parse, normalize, strip tracking query parameters, and extract 19-digit media IDs (`video`, `photo` carousel, `story`, and shortlinks) from raw mobile share strings and URLs.
|
|
34
|
+
|
|
35
|
+
Built and maintained by the engineering team at **[ssstktok — HD Video, Story & MP3 Downloader](https://ssstktok.com)** (companion to the official Node.js/TypeScript package `ssstktok-url-parser` on NPM).
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## ✨ Features
|
|
40
|
+
|
|
41
|
+
- **Zero External Dependencies**: Uses only Python's standard library (`urllib.parse`, `re`, `dataclasses`, `typing`).
|
|
42
|
+
- **Share-Text Extraction**: Automatically locates and extracts URLs embedded inside dirty mobile clipboard copy strings.
|
|
43
|
+
- **Tracking Parameter Sanitization**: Strips UTM and device query strings (`?is_from_webapp=1&sender_device=pc`) to produce canonical URLs.
|
|
44
|
+
- **Multi-Format Classification**: Identifies standard `video` streams, multi-image `photo` carousels (supported by the **[Photo Slideshow & Carousel Downloader](https://ssstktok.com/slide-downloader)**), 24-hour `story` posts, and audio extraction endpoints via the **[TikTok to MP3 Audio Extractor](https://ssstktok.com/download-tiktok-mp3)**.
|
|
45
|
+
- **Full Type Hints (`PEP 561`)**: Returns immutable `ParsedMediaUrl` dataclasses or JSON-serializable dictionaries.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 📦 Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install ssstktok-url-parser
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 🚀 Quick Start (Python)
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from ssstktok_url_parser import parse_media_url, extract_media_id, get_tool_endpoint
|
|
61
|
+
|
|
62
|
+
# 1. Parse raw mobile clipboard text containing tracking parameters
|
|
63
|
+
raw_share = "Check out this clip! https://www.tiktok.com/@creator/video/7391827364519283746?is_from_webapp=1&sender_device=pc"
|
|
64
|
+
res = parse_media_url(raw_share)
|
|
65
|
+
|
|
66
|
+
print(res.is_valid) # True
|
|
67
|
+
print(res.clean_url) # "https://www.tiktok.com/@creator/video/7391827364519283746"
|
|
68
|
+
print(res.item_id) # "7391827364519283746"
|
|
69
|
+
print(res.media_type) # "video"
|
|
70
|
+
print(res.username) # "creator"
|
|
71
|
+
|
|
72
|
+
# 2. Quickly extract only the 19-digit numeric ID
|
|
73
|
+
photo_id = extract_media_id("https://www.tiktok.com/@artist/photo/7399999999999999999")
|
|
74
|
+
print(photo_id) # "7399999999999999999"
|
|
75
|
+
|
|
76
|
+
# 3. Resolve the matching web utility endpoint
|
|
77
|
+
print(get_tool_endpoint("mp3")) # "https://ssstktok.com/download-tiktok-mp3"
|
|
78
|
+
print(get_tool_endpoint("photo")) # "https://ssstktok.com/slide-downloader"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🖥️ Command-Line Interface (CLI)
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
ssstktok-parse "https://www.tiktok.com/@creator/video/7391827364519283746?is_from_webapp=1"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Output:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"is_valid": true,
|
|
94
|
+
"clean_url": "https://www.tiktok.com/@creator/video/7391827364519283746",
|
|
95
|
+
"item_id": "7391827364519283746",
|
|
96
|
+
"media_type": "video",
|
|
97
|
+
"username": "creator"
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 📄 License
|
|
104
|
+
|
|
105
|
+
MIT License © ssstktok Engineering
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ssstktok_url_parser/__init__.py
|
|
5
|
+
ssstktok_url_parser.egg-info/PKG-INFO
|
|
6
|
+
ssstktok_url_parser.egg-info/SOURCES.txt
|
|
7
|
+
ssstktok_url_parser.egg-info/dependency_links.txt
|
|
8
|
+
ssstktok_url_parser.egg-info/entry_points.txt
|
|
9
|
+
ssstktok_url_parser.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ssstktok_url_parser
|