2024-05-14 18:32:18 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Modify X-KDE-Protocols in the mpv.desktop file based on output from
|
|
|
|
# mpv --list-protocols.
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of mpv.
|
|
|
|
#
|
|
|
|
# mpv is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# mpv is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-09-15 12:08:30 +00:00
|
|
|
with open(sys.argv[1], encoding="UTF-8") as f:
|
2024-05-14 18:32:18 +00:00
|
|
|
next(f)
|
|
|
|
mpv_desktop = dict([line.split("=", 1) for line in f])
|
|
|
|
|
|
|
|
if not mpv_desktop["X-KDE-Protocols"]:
|
|
|
|
raise ValueError("Missing X-KDE-Protocols entry in mpv.desktop file")
|
|
|
|
|
2024-10-13 17:18:11 +00:00
|
|
|
with open(sys.argv[2], encoding="UTF-8") as mpv_protocols:
|
|
|
|
mpv_protocols = {
|
|
|
|
line.strip(" :/")
|
|
|
|
for line in mpv_protocols.read().splitlines()
|
|
|
|
if "://" in line
|
|
|
|
}
|
|
|
|
|
2024-05-14 18:32:18 +00:00
|
|
|
if len(mpv_protocols) == 0:
|
|
|
|
raise ValueError("Unable to parse any protocols from mpv '--list-protocols'")
|
|
|
|
|
|
|
|
protocol_list = set(mpv_desktop["X-KDE-Protocols"].strip().split(","))
|
2024-09-15 00:43:15 +00:00
|
|
|
compatible_protocols = sorted(mpv_protocols & protocol_list)
|
|
|
|
mpv_desktop["X-KDE-Protocols"] = ",".join(compatible_protocols) + "\n"
|
2024-05-14 18:32:18 +00:00
|
|
|
|
|
|
|
with open(sys.argv[3], "w", encoding="UTF-8") as f:
|
|
|
|
f.write("[Desktop Entry]" + "\n")
|
|
|
|
for key, value in mpv_desktop.items():
|
|
|
|
f.write(f"{key}={value}")
|