1322-python 0.1.0__py3-none-any.whl
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.
- 1322_python-0.1.0.dist-info/METADATA +273 -0
- 1322_python-0.1.0.dist-info/RECORD +18 -0
- 1322_python-0.1.0.dist-info/WHEEL +4 -0
- 1322_python-0.1.0.dist-info/licenses/LICENSE +21 -0
- client1322/__init__.py +48 -0
- client1322/_backoff.py +76 -0
- client1322/_merge.py +199 -0
- client1322/client.py +114 -0
- client1322/exceptions.py +40 -0
- client1322/platforms/__init__.py +1 -0
- client1322/platforms/_base.py +191 -0
- client1322/platforms/binance.py +219 -0
- client1322/platforms/instagram.py +146 -0
- client1322/platforms/news.py +150 -0
- client1322/platforms/truth.py +189 -0
- client1322/platforms/x.py +577 -0
- client1322/platforms/youtube.py +155 -0
- client1322/py.typed +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""YouTube: triple event model (upload, upgrade, deletion).
|
|
2
|
+
|
|
3
|
+
Ground truth: https://1322.io/docs ("YouTube" reference, "Event architecture").
|
|
4
|
+
|
|
5
|
+
Unlike the other five platforms, 1322's public docs describe the YouTube
|
|
6
|
+
*event payload contract* in full (upload / upgrade / deletion messages
|
|
7
|
+
below) but, as of this writing, do not publish a fixed WebSocket URL
|
|
8
|
+
pattern or a customer-facing REST tracked-account API for YouTube the way
|
|
9
|
+
they do for X, Truth Social, Instagram, News, and Binance Square. Rather
|
|
10
|
+
than guess at an undocumented endpoint, :class:`YouTubeAdapter` requires you
|
|
11
|
+
to supply the full ``ws_url`` from your dashboard configuration, and it only
|
|
12
|
+
implements event parsing -- no track/untrack/list REST helpers, because
|
|
13
|
+
1322's docs don't define them for this platform. Check
|
|
14
|
+
https://1322.io/docs directly if that changes.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from typing import Any, Literal, TypedDict, Union
|
|
21
|
+
|
|
22
|
+
from ..exceptions import ConfigurationError, UnknownEventError
|
|
23
|
+
from ._base import BaseAdapter
|
|
24
|
+
|
|
25
|
+
#: Host per 1322's published REST host list (https://1322.io/llms.txt).
|
|
26
|
+
#: No documented WebSocket path pattern exists for YouTube; ws_url is
|
|
27
|
+
#: mandatory (see module docstring).
|
|
28
|
+
REST_BASE = "https://youtube.1322.io"
|
|
29
|
+
|
|
30
|
+
VideoSubtype = Literal["video", "short"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class YouTubeChannelRef(TypedDict):
|
|
34
|
+
id: str | None
|
|
35
|
+
name: str
|
|
36
|
+
url: str | None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class YouTubeVideoMetadata(TypedDict, total=False):
|
|
40
|
+
duration_seconds: int
|
|
41
|
+
category: str
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class YouTubeVideoRef(TypedDict):
|
|
45
|
+
id: str
|
|
46
|
+
url: str
|
|
47
|
+
title: str | None
|
|
48
|
+
metadata: YouTubeVideoMetadata | None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class YouTubeImages(TypedDict):
|
|
52
|
+
seed: str | None
|
|
53
|
+
chosen: str | None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class YouTubeUpgrade(TypedDict):
|
|
57
|
+
kind: Literal["image"]
|
|
58
|
+
video_id: str
|
|
59
|
+
url: str
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class YouTubeDeletedVideoRef(TypedDict):
|
|
63
|
+
id: str
|
|
64
|
+
url: str
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(slots=True)
|
|
68
|
+
class UploadMessage:
|
|
69
|
+
type: Literal["upload"]
|
|
70
|
+
subtype: VideoSubtype
|
|
71
|
+
channel: YouTubeChannelRef
|
|
72
|
+
video: YouTubeVideoRef
|
|
73
|
+
images: YouTubeImages
|
|
74
|
+
raw: dict[str, Any]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@dataclass(slots=True)
|
|
78
|
+
class UpgradeMessage:
|
|
79
|
+
type: Literal["upgrade"]
|
|
80
|
+
upgrade: YouTubeUpgrade
|
|
81
|
+
raw: dict[str, Any]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@dataclass(slots=True)
|
|
85
|
+
class DeletionMessage:
|
|
86
|
+
type: Literal["deletion"]
|
|
87
|
+
video: YouTubeDeletedVideoRef
|
|
88
|
+
channel: YouTubeChannelRef
|
|
89
|
+
raw: dict[str, Any]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
YouTubeEvent = Union[UploadMessage, UpgradeMessage, DeletionMessage]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def parse_youtube_event(raw: dict[str, Any]) -> YouTubeEvent:
|
|
96
|
+
"""Parse one decoded YouTube tracker frame (upload/upgrade/deletion)."""
|
|
97
|
+
event_type = raw.get("type")
|
|
98
|
+
if event_type == "upload":
|
|
99
|
+
return UploadMessage(
|
|
100
|
+
type=event_type,
|
|
101
|
+
subtype=raw.get("subtype", "video"),
|
|
102
|
+
channel=raw.get("channel", {}),
|
|
103
|
+
video=raw.get("video", {}),
|
|
104
|
+
images=raw.get("images", {}),
|
|
105
|
+
raw=raw,
|
|
106
|
+
)
|
|
107
|
+
if event_type == "upgrade":
|
|
108
|
+
return UpgradeMessage(type=event_type, upgrade=raw.get("upgrade", {}), raw=raw)
|
|
109
|
+
if event_type == "deletion":
|
|
110
|
+
return DeletionMessage(
|
|
111
|
+
type=event_type,
|
|
112
|
+
video=raw.get("video", {}),
|
|
113
|
+
channel=raw.get("channel", {}),
|
|
114
|
+
raw=raw,
|
|
115
|
+
)
|
|
116
|
+
raise UnknownEventError(f"Unrecognized YouTube event type: {event_type!r}")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class YouTubeAdapter(BaseAdapter):
|
|
120
|
+
"""YouTube connection. REST helpers are intentionally not provided (see module docstring)."""
|
|
121
|
+
|
|
122
|
+
rest_base = REST_BASE
|
|
123
|
+
|
|
124
|
+
def __init__(self, api_key: str, *, ws_url: str, **kwargs: Any) -> None:
|
|
125
|
+
super().__init__(api_key, **kwargs)
|
|
126
|
+
if not ws_url:
|
|
127
|
+
raise ConfigurationError(
|
|
128
|
+
"YouTube requires an explicit ws_url. 1322's public docs do not "
|
|
129
|
+
"publish a fixed YouTube WebSocket path (unlike the other five "
|
|
130
|
+
"platforms) -- copy the connection URL from your 1322 dashboard "
|
|
131
|
+
"and pass it as ws_url=. See https://1322.io/docs."
|
|
132
|
+
)
|
|
133
|
+
self._ws_url_value = ws_url
|
|
134
|
+
|
|
135
|
+
def _ws_url(self) -> str:
|
|
136
|
+
return self._ws_url_value
|
|
137
|
+
|
|
138
|
+
def _ws_headers(self) -> dict[str, str]:
|
|
139
|
+
return {"X-API-Key": self.api_key}
|
|
140
|
+
|
|
141
|
+
def _rest_headers(self) -> dict[str, str]:
|
|
142
|
+
return {"X-API-Key": self.api_key}
|
|
143
|
+
|
|
144
|
+
def _parse(self, raw: dict[str, Any]) -> YouTubeEvent:
|
|
145
|
+
return parse_youtube_event(raw)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
__all__ = [
|
|
149
|
+
"YouTubeAdapter",
|
|
150
|
+
"YouTubeEvent",
|
|
151
|
+
"UploadMessage",
|
|
152
|
+
"UpgradeMessage",
|
|
153
|
+
"DeletionMessage",
|
|
154
|
+
"parse_youtube_event",
|
|
155
|
+
]
|
client1322/py.typed
ADDED
|
File without changes
|