Spaces:
Running
Running
Create ingestion/classifiers.py
Browse files- ingestion/classifiers.py +29 -0
ingestion/classifiers.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from urllib.parse import urlparse
|
| 3 |
+
|
| 4 |
+
def classify_source(source: str):
|
| 5 |
+
|
| 6 |
+
if not source:
|
| 7 |
+
raise Exception("Empty source")
|
| 8 |
+
|
| 9 |
+
if os.path.exists(source):
|
| 10 |
+
return "local"
|
| 11 |
+
|
| 12 |
+
if source.endswith(".mp4"):
|
| 13 |
+
return "direct"
|
| 14 |
+
|
| 15 |
+
domain = urlparse(source).netloc.lower()
|
| 16 |
+
|
| 17 |
+
if "youtube" in domain or "youtu.be" in domain:
|
| 18 |
+
return "youtube"
|
| 19 |
+
|
| 20 |
+
if "tiktok" in domain:
|
| 21 |
+
return "tiktok"
|
| 22 |
+
|
| 23 |
+
if "instagram" in domain:
|
| 24 |
+
return "instagram"
|
| 25 |
+
|
| 26 |
+
if "facebook" in domain:
|
| 27 |
+
return "facebook"
|
| 28 |
+
|
| 29 |
+
return "unknown"
|