Skip to content

Instantly share code, notes, and snippets.

@louisroyer
Last active February 20, 2023 17:52
Show Gist options
  • Save louisroyer/7002619daf1313f6ea62dfd1e4c50281 to your computer and use it in GitHub Desktop.
Save louisroyer/7002619daf1313f6ea62dfd1e4c50281 to your computer and use it in GitHub Desktop.
Update voe player domain on MALSync playerUrls.js
#!/usr/bin/env python3
import requests
import os
filename = os.path.expanduser(f'src/pages/playerUrls.js')
proto = 'https'
fake_video_id = '0123456789ab'
r = requests.head(f'{proto}://voe.sx/e/{fake_video_id}')
if r.status_code == 302:
location = r.headers["Location"]
domain = f'*{location[len(proto):-len(fake_video_id)]}*'
else:
raise Exception('No redirection to VOE player domain')
in_voe_block = None
voe_end_line = None
try:
with open(filename, 'r') as f:
for linenum, line in enumerate(f):
if 'voe: {' in line:
in_voe_block = True
if in_voe_block and not voe_end_line and '],' in line:
voe_end_line = linenum
if domain in line:
raise Exception(f'Domain {domain} is already present in file {filename}.')
except FileNotFoundError:
raise Exception('This script must be run from MALSync git repository')
if in_voe_block is None:
raise Exception(f'No VOE block in file {filename}.')
if voe_end_line is None:
raise Exception(f'No end of VOE block in file {filename}.')
try:
with open(filename, 'r+') as f:
contents = f.readlines()
contents.insert(voe_end_line, f"{' '*6}'{domain}',{os.linesep}")
f.seek(0)
f.truncate()
f.writelines(contents)
except FileNotFoundError:
raise Exception('This script must be run from MALSync git repository')
print(f'{domain} added to {filename}.')
print('Now run the command below, then commit:')
print('npm run build:missingPermissions')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment