aboutsummaryrefslogtreecommitdiff
path: root/streamkeygen.py
diff options
context:
space:
mode:
Diffstat (limited to 'streamkeygen.py')
-rwxr-xr-xstreamkeygen.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/streamkeygen.py b/streamkeygen.py
new file mode 100755
index 0000000..bb61b07
--- /dev/null
+++ b/streamkeygen.py
@@ -0,0 +1,86 @@
+# This is free and unencumbered software released into the public domain.
+#
+# Anyone is free to copy, modify, publish, use, compile, sell, or
+# distribute this software, either in source code form or as a compiled
+# binary, for any purpose, commercial or non-commercial, and by any
+# means.
+#
+# In jurisdictions that recognize copyright laws, the author or authors
+# of this software dedicate any and all copyright interest in the
+# software to the public domain. We make this dedication for the benefit
+# of the public at large and to the detriment of our heirs and
+# successors. We intend this dedication to be an overt act of
+# relinquishment in perpetuity of all present and future rights to this
+# software under copyright law.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+import sys
+from urllib.parse import urlsplit, urlunsplit, quote
+if len(sys.argv) not in {2,3}:
+ print(f"Usage: {sys.argv[0]} absolute-url-of-midis-folder [outfile]")
+ exit(1)
+
+splitted=urlsplit(sys.argv[1])
+asciiurl=urlunsplit((
+ splitted.scheme,
+ splitted.netloc.encode('idna').decode('us-ascii').lower(),
+ quote(splitted.path,range(33,127)),
+ quote(splitted.query,range(33,127)),
+ ''
+))
+if asciiurl[-1]!='/': asciiurl+='/'
+if asciiurl!=sys.argv[1]: print(f"Using URL {asciiurl}.")
+binary=b'1\x00'+asciiurl.encode('us-ascii')+b'\x001299\x00'
+
+locmap=(
+ 503, 463, 203, 217, 314, 448, 7, 86, 470, 432, 482, 97, 85, 5, 163, 504,
+ 359, 360, 172, 122, 255, 72, 490, 48, 240, 205, 508, 212, 376, 187, 174, 510,
+ 346, 485, 349, 498, 333, 118, 297, 364, 227, 487, 71, 103, 433, 434, 8, 65,
+ 40, 361, 455, 324, 166, 20, 352, 190, 421, 331, 446, 53, 207, 396, 22, 211,
+ 188, 406, 335, 451, 59, 384, 107, 431, 310, 461, 245, 224, 110, 274, 253, 260,
+ 373, 251, 146, 89, 329, 234, 354, 100, 479, 392, 200, 0, 465, 265, 82, 105,
+ 248, 119, 298, 277, 128, 299, 13, 62, 148, 320, 341, 289, 4, 173, 507, 138,
+ 144, 230, 238, 250, 37, 252, 54, 66, 464, 447, 185, 11, 193, 104, 50, 459,
+ 216, 35, 204, 428, 219, 400, 339, 79, 317, 296, 483, 183, 368, 443, 502, 38,
+ 382, 93, 221, 30, 34, 210, 98, 383, 467, 292, 147, 236, 460, 6, 350, 270,
+ 229, 102, 156, 409, 304, 192, 155, 444, 367, 476, 303, 397, 52, 415, 178, 133,
+ 132, 412, 408, 506, 276, 24, 365, 111, 501, 140, 288, 278, 435, 474, 244, 120,
+ 186, 388, 159, 395, 427, 398, 83, 126, 452, 69, 67, 500, 264, 410, 378, 355,
+ 26, 23, 271, 106, 64, 454, 381, 125, 243, 509, 291, 468, 279, 466, 480, 70,
+ 152, 92, 27, 158, 231, 327, 481, 168, 127, 478, 429, 440, 342, 357, 14, 473,
+ 266, 306, 442, 195, 263, 290, 42, 46, 141, 74, 60, 39, 121, 115, 237, 436,
+ 390, 153, 209, 225, 108, 458, 49, 363, 486, 19, 456, 77, 43, 369, 445, 228,
+ 293, 99, 55, 380, 475, 130, 495, 246, 41, 218, 262, 145, 302, 416, 491, 420,
+ 417, 47, 422, 75, 371, 269, 308, 424, 201, 2, 239, 202, 113, 21, 78, 326,
+ 220, 87, 137, 430, 457, 418, 88, 272, 222, 256, 184, 337, 175, 453, 449, 161,
+ 345, 450, 387, 258, 131, 123, 340, 170, 358, 370, 95, 401, 394, 332, 268, 280,
+ 17, 404, 213, 413, 419, 391, 32, 295, 226, 139, 45, 33, 134, 176, 492, 25,
+ 284, 143, 484, 12, 305, 150, 488, 301, 489, 469, 44, 402, 135, 10, 28, 136,
+ 344, 414, 351, 112, 325, 18, 362, 109, 215, 81, 167, 233, 9, 191, 267, 160,
+ 96, 377, 16, 356, 177, 257, 223, 197, 343, 477, 311, 124, 169, 3, 423, 182,
+ 441, 15, 232, 162, 497, 275, 259, 157, 76, 196, 399, 471, 322, 411, 91, 151,
+ 321, 318, 36, 374, 73, 31, 80, 1, 347, 494, 56, 164, 405, 273, 499, 393,
+ 282, 180, 348, 247, 29, 116, 90, 287, 472, 84, 117, 300, 179, 425, 68, 149,
+ 328, 511, 51, 208, 242, 336, 94, 294, 198, 313, 241, 214, 283, 386, 281, 389,
+ 142, 129, 379, 462, 57, 438, 338, 165, 114, 199, 366, 181, 319, 407, 285, 316,
+ 323, 154, 437, 375, 334, 286, 254, 194, 385, 261, 353, 493, 206, 61, 249, 307,
+ 496, 189, 58, 312, 439, 330, 309, 505, 403, 235, 101, 372, 315, 426, 63, 171)
+if len(binary)>len(locmap):
+ print('URL is too long (maximum is 504 bytes)',file=sys.stderr)
+ exit(1)
+
+keyloc=sys.argv[2] if len(sys.argv)==3 else 'stream.key'
+key=open(keyloc,'wb')
+for i,loc in enumerate(locmap):
+ if loc<len(binary):
+ key.write(binary[loc:loc+1])
+ else:
+ key.write(b' ')
+key.close()
+print(f'Created {keyloc}.')