Created
March 27, 2019 21:20
-
-
Save marczellm/822b4f953b388c61118768e4fc7029ec to your computer and use it in GitHub Desktop.
Open Youtube links (vnd-youtube:) from Messenger on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
import webbrowser | |
import json | |
from urllib.parse import urlparse, unquote, parse_qs | |
vndurl = sys.argv[1].replace('vnd.youtube', 'https') | |
if vndurl.startswith('https://www.youtu') or vndurl.startswith('https://youtu'): | |
webbrowser.open(vndurl) | |
else: | |
[scheme, netloc, path, params, query, fragment] = urlparse(vndurl) | |
queryDict = parse_qs(query) | |
if 'al_applink_data' in queryDict: | |
applinkData = json.loads(queryDict['al_applink_data'][0]) | |
if 'target_url' in applinkData: | |
webbrowser.open(applinkData['target_url']) | |
# See https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914(v=vs.85) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment