cocorum.utils
This module provides various functions that stand by themselves and are used by a lot of different classes in the package. While most of these functions aren't usually meant to be used directly, you might find some of them handy. At least one function is not currently used by the rest of the package at all, but I figured it might be useful in the future.
Rumble API utilities
This submodule provides some utilities for working with the APIs.
Copyright 2026 Wilbur Jaywright d.b.a. Marswide BGL.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
S.D.G.
MD5Ex
MD5 extended hashing utilities
Source code in src/cocorum/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
hash(message)
staticmethod
Hash a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Message to hash. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Hash |
str
|
The hex digest hash result. |
Source code in src/cocorum/utils.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
hash_stretch(password, salt, iterations=1024)
staticmethod
Stretch-hash a password with a salt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
The password to hash. |
required |
salt
|
str
|
The salt to add to the password. |
required |
iterations
|
int
|
Number of times to stretch the hashing. |
1024
|
Returns:
| Name | Type | Description |
|---|---|---|
Hash |
str
|
The completed stretched hash. |
Source code in src/cocorum/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
badges_to_glyph_string(badges)
Convert a list of badges into a string of glyphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
badges
|
list[str]
|
A list of str or objects with str method that are valid badge slugs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Glyphs |
str
|
The badge list as a UTF-8 glyph string, uses ? for unknown badges. |
Source code in src/cocorum/utils.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
base_10_to_36(b10)
Convert a base 10 number to base 36.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b10
|
SupportsInt
|
The base 10 number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
B36 |
str
|
The same number in base 36. |
Source code in src/cocorum/utils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
base_36_and_10(num, assume_10=False)
Take a base 36 or base 10 number, and return both base 36 and 10.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
SupportsInt | str
|
The number in either base 10 or 36. |
required |
assume_10
|
bool
|
If the number is a string but looks like base 10, should we assume it is? Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
B36 |
str
|
The number in base 36. |
B10 |
int
|
The number in base 10. |
Source code in src/cocorum/utils.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
base_36_to_10(b36)
Convert a base 36 number to base 10.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b36
|
str
|
The base 36 number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
B10 |
int
|
The same number in base 10. |
Source code in src/cocorum/utils.py
124 125 126 127 128 129 130 131 132 133 134 | |
calc_password_hashes(password, salts)
Hash a password for Rumble authentication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
The password to hash. |
required |
salts
|
Sequence[str]
|
The three salts to use for hashing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Hashes |
(str, str, str)
|
The three results of hashing. |
Source code in src/cocorum/utils.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
ensure_b10(num, assume_10=False)
No matter wether a number is base 36 or 10, return 10.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
SupportsInt | str
|
The number in either base 10 or 36. |
required |
assume_10
|
bool
|
If the number is a string but looks like base 10, should we assume it is? Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Number |
int
|
The number in base 10. |
Source code in src/cocorum/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
ensure_b36(num, assume_10=False)
No matter wether a number is base 36 or 10, return 36.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
SupportsInt | str
|
The number in either base 10 or 36. |
required |
assume_10
|
bool
|
If the number is a string but looks like base 10, should we assume it is? Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Number |
str
|
The number in base 36. |
Source code in src/cocorum/utils.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
form_timestamp(seconds, tz=timezone.utc)
Form a Rumble timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Timestamp in seconds since Epoch, UTC. |
required |
tz
|
timezone
|
Time zone to put the stamp in. Defaults to UTC. |
utc
|
Returns: Timestamp (str): The same timestamp value, in the ISO 8601 format Rumble's API uses.
Source code in src/cocorum/utils.py
90 91 92 93 94 95 96 97 98 99 100 101 | |
generate_request_id()
Generate a UUID for API requests
Returns:
| Name | Type | Description |
|---|---|---|
UUID |
str
|
Random base64 encoded UUID. |
Source code in src/cocorum/utils.py
298 299 300 301 302 303 304 305 306 307 308 | |
parse_timestamp(timestamp)
Parse a Rumble timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
str
|
Timestamp in the ISO 8601 format Rumble's API uses. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Timestamp |
float
|
The same timestamp value, in seconds since Epoch, UTC. |
Source code in src/cocorum/utils.py
77 78 79 80 81 82 83 84 85 86 87 | |
video_id_from_url(url)
Get the real video ID (base 36) from a watch-page URL, a v-slug, or an embed URL.
The ID in a watch-page URL is NOT the video ID. For example, https://rumble.com/v2o2oe5-title.html is video 157009049, which is 2lh8yh in base 36, and int("2o2oe5", 36) is a different number. Embed URLs (https://rumble.com/embed/v2lh8yh/) do carry the real ID and are read directly. For watch URLs and slugs, this asks Rumble's oEmbed endpoint, which returns JSON (no HTML page scraping).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
https://rumble.com/v2o2oe5-title.html, https://rumble.com/v2o2oe5, v2o2oe5, v2o2oe5-title.html, https://rumble.com/shorts/v5d871x, or https://rumble.com/embed/v2lh8yh/ (auto detects and trims). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Video ID (str): The real video ID in base 36, e.g. "2lh8yh". |
Raises:
| Type | Description |
|---|---|
ValueError
|
The input is not a Rumble watch URL, slug, or embed URL. |
LookupError
|
Rumble has no video at that watch URL, or its reply had no embed ID. |
Source code in src/cocorum/utils.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
S.D.G.