annotate updatechromium.py @ 133:0d8eabdd12ab default tip

create: write H:MM:SS timestamps, add option to fill with gaussian-blur instead of black many albums are longer than one hour so writing H:MM:SS is a necessity. if anything there will just be verbose info that isn't important for my use-case. however the gaussian-blur is simply broken. It works, and it plays locally just fine, but YouTube in particular elongates the video to fit the full width. I'm not entirely sure why it does this, but it makes it useless and ugly.
author Paper <paper@tflc.us>
date Sat, 03 Jan 2026 20:25:38 -0500
parents 2aa9614cb39a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
1 #!/usr/bin/python
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
2 # Binaries from
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
3 # https://github.com/ungoogled-software/ungoogled-chromium-archlinux/
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
4 import urllib.request
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
5 import os
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
6 import json
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
7 import sys
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
8 import subprocess
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
9 from tqdm import tqdm
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
10
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
11
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
12 # Decodes subprocess stdouts, made into a function because why not
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
13 def decode_line(line):
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
14 decodeline = []
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
15 for i in line:
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
16 decodeline.append(i.decode("utf-8").rstrip())
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
17 return decodeline
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
18
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
19
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
20 # Checks current version against installed version
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
21 def check_version(version):
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
22 pacman = subprocess.Popen(["pacman", "-Qm"], stdout=subprocess.PIPE,
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
23 stderr=subprocess.STDOUT)
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
24 decodeline = decode_line(pacman.stdout.readlines())
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
25 for i in decodeline:
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
26 if i.split(" ")[0] == "ungoogled-chromium":
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
27 if i.split(" ")[1] == version:
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
28 print("You are on the latest version!")
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
29 sys.exit(0)
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
30
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
31
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
32 # Checks for any Chromium processes currently running
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
33 # Returns 0 if running, 1 if not running, and 2 if it doesn't exist
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
34 def check_for_file(files):
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
35 process = subprocess.Popen(["which", files], stdout=subprocess.DEVNULL,
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
36 stderr=subprocess.STDOUT)
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
37 process.wait()
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
38
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
39 if process.returncode == 0:
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
40 pgrep = subprocess.Popen(["pidof", files], stdout=subprocess.PIPE,
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
41 stderr=subprocess.STDOUT)
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
42 decodeline = decode_line(pgrep.stdout.readlines())
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
43 if len(decodeline) > 0:
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
44 return 0
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
45 else:
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
46 return 1
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
47 else:
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
48 return 2
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
49
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
50
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
51 # Progress bar, copied from stackoverflow :pngtroll:
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
52 class DownloadProgressBar(tqdm):
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
53 def update_to(self, b=1, bsize=1, tsize=None):
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
54 if tsize is not None:
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
55 self.total = tsize
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
56 self.update(b * bsize - self.n)
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
57
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
58
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
59 def download_url(url, output_path):
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
60 with DownloadProgressBar(unit='B', unit_scale=True,
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
61 miniters=1, desc=url.split('/')[-1]) as t:
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
62 urllib.request.urlretrieve(url, filename=output_path,
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
63 reporthook=t.update_to)
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
64
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
65
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
66 if check_for_file("chromium") == 0:
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
67 print("Chromium is still running! Exiting...")
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
68 sys.exit(1)
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
69 owner = "ungoogled-software"
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
70 repo = "ungoogled-chromium-archlinux"
40
Paper <mrpapersonic@gmail.com>
parents: 39
diff changeset
71 json = json.loads(urllib.request.urlopen(
Paper <mrpapersonic@gmail.com>
parents: 39
diff changeset
72 f"https://api.github.com/repos/{owner}/{repo}/releases").read())
39
a93c352af05e Update updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
73 check_version(json[0]["tag_name"])
36
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
74 for i in json[0]["assets"]:
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
75 if i["content_type"] == "application/octet-stream":
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
76 download_url(f"{i['browser_download_url']}", "/tmp/chromium.tar.zst")
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
77 os.system("sudo pacman -U /tmp/chromium.tar.zst")
8e49e6662429 Add updatechromium.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
78 os.remove("/tmp/chromium.tar.zst")