-
Notifications
You must be signed in to change notification settings - Fork 8
/
spotify-tarball.py
executable file
·70 lines (55 loc) · 2.17 KB
/
spotify-tarball.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 Simone Caronni <[email protected]>
# Licensed under the GNU General Public License Version or later
import json
import re
import os
import shutil
import subprocess
import sys
import tarfile
from urllib.request import Request, urlopen
def main():
repo_url = "http://api.snapcraft.io/v2/snaps/info/spotify"
request = Request(repo_url)
request.add_header("Snap-Device-Series", "16")
response = urlopen(request).read()
repo_url_raw = json.loads(response)
# print(repo_url_raw['channel-map'][2]['version'])
for channel_map in repo_url_raw["channel-map"]:
if "edge" in channel_map["channel"]["name"]:
version = channel_map["version"]
snap_url = channel_map["download"]["url"]
with open("spotify-client.spec", "r") as file:
for line in file:
if re.search("^Version:.*" + version, line, re.I):
print("SPEC file already contains the latest version: " + version + ".")
sys.exit(0)
print("New version available: " + version + " (" + snap_url + ")")
print("Updating SPEC file...", end=" ")
rpmdev_bumpspec_comment = "Update to version " + version + "."
subprocess.run(["rpmdev-bumpspec", "-D", "-c", rpmdev_bumpspec_comment, "-n", version, "spotify-client.spec"])
print("done.")
tarball = "spotify-" + version
print("Downloading snap file " + tarball + ".snap" + "...", end=" ", flush=True)
request = Request(snap_url)
response = urlopen(request).read()
open(tarball + ".snap", "wb").write(response)
print("done.")
print("Unpacking " + tarball + ".snap" + "...", end=" ", flush=True)
subprocess.run(["unsquashfs", "-q", "-n", "-f", "-d", "temp", tarball + ".snap"])
shutil.move("temp/usr/share/spotify", tarball)
shutil.rmtree(tarball + "/apt-keys")
shutil.rmtree("temp")
os.remove(tarball + ".snap")
print("done.")
print("Creating tarball " + tarball + ".tar.xz...", end=" ", flush=True)
tar = tarfile.open(tarball + ".tar.xz", "w:xz")
tar.add(tarball)
tar.close()
shutil.rmtree(tarball)
print("done.")
if __name__ == "__main__":
main()