[WIP] Physical "Album" Surrogate

Idea:

Overview

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import evdev
import time
import sys
import re
import json
import subprocess

<<barcode_reader>>

<<dispatcher>>

Event Device Barcode Reader

Generator for barcode input events

def barcodes(device):
    dev = evdev.InputDevice(device)
    dev.grab()
    barcode = []
    for event in dev.read_loop():
        if event.type == evdev.ecodes.EV_KEY:
            key_event = evdev.util.categorize(event)
            print(key_event)
            if key_event.keystate == evdev.KeyEvent.key_down:
                if key_event.keycode == "KEY_ENTER":
                    yield "".join(barcode)
                    barcode = []
                elif re.match(r"^KEY_[A-Z0-9]$", key_event.keycode):
                    barcode.append(key_event.keycode[4:])

Device /dev/input/by-id/usb-Canmax_Technology_C-200_UsbKeyboard-event-kbd

Generate Barcode Sheet

for i in $(seq -w 0 100); do barcode -b"irq0:0$i" -E > $i.eps; done montage -mode concatenate -density 600 -tile 6x10 *.noprefix.svg out5.pdf

Mapping Table

Barcodes to actions

Barcode Action Argument
0 Spotify spotify:album:0wBiN0fKhy0ywx732SpgUs
1 Spotify spotify:album:063f8Ej8rLVTz9KkjQKEMa
2 Spotify spotify:album:3ovevgHuEfGJ370dPXbA9P
3 Spotify spotify:album:3VwpyeBEbVP9BPvkMXBRmZ
4 Spotify spotify:album:1Z2jkEtW5Sc9wWVxUgyG0E
5 Spotify spotify:album:1rMSF8WzsF016bhkREx45l
6 Spotify spotify:album:3bTLPtGMtHL72zQ1nOQ9lg
7 Spotify spotify:album:40zYO5yqr1fz0Yx5yNYf7q
8 Spotify spotify:album:1h4VM1Nsgav7liCdWBoGlC
9 Spotify spotify:album:12FIwaFCkHHdl2PSwhOD7t
10 Spotify spotify:album:4u4bk26XigxgwdVQqWUkqG
11 Spotify spotify:album:4VmfG1RPuVXZQlXX3gwkXT
12 Spotify spotify:album:6xPsiybBS0UiWQdAqIJryB
13 Spotify spotify:album:62Jzz74iTXzE9QmKwt9wNn
14 Spotify spotify:album:4bkefbf5iY3rgoMphecU4y
15 Spotify spotify:album:1U5x6wQtMJtbwM3NZRSvKT
16 Spotify spotify:album:7tMM2MIBklhAtmmsgbQrAq
17 Spotify spotify:album:4Z1BFX1oBckY8bhGEWMYmi
18 Spotify spotify:album:53gVVQed8eU0TRALmmmjSn
20 Spotify spotify:album:2VJjzepoONfEw3vfep2UNh
21 Spotify spotify:album:2XWyZeq1RItC1y5BdbGKB7
22 Spotify spotify:album:5zM399cy0hnRhmp9lH9iuY
23 Spotify spotify:album:0PeiGSI11Ym2KeXhIYjtf5
24 Spotify spotify:album:1xVP4eFcagXNtQMvEXfyeV
25 Spotify spotify:album:3xDa8phPJijprE5NqnhD0I
26 Spotify spotify:album:6jeIzUv8Bff4fFElZwwA4B
27 Spotify spotify:album:2cCL44jj1J9yIIBQ7rCsjr
28 Spotify spotify:album:4xHwAcx1rGRrmXJ19K7v6l
29 Spotify spotify:album:4Rti9CCEIh5I2ftLnojajm
30 Spotify spotify:album:6ApvW9zTP1h6Ez7fabS2OW
31 Spotify spotify:album:1v8NbwwYfEb6xklqeh8N7b
32 Spotify spotify:album:5D9GU1C0ECDaR8GW3FpXIi
33 Spotify spotify:album:17vHPMmoxN5B8cdhCDeMTe
34 Spotify spotify:album:0a2yGkTrEviUUZNBolAUXL
35 Spotify spotify:album:4LfeFpR0qvSE6GrzrtT6H8
36 Spotify spotify:album:6Iu8toVsvCc3I4INxYiVIy
37 Spotify spotify:album:1DtXzewBvv5vZBnl3ZmJqo
38 Spotify spotify:album:59hWFsFOPOrXQMeTiXYGLr
39 Spotify spotify:album:5mzjUmksmRKYZ3WvzAGaA1
40 Spotify spotify:album:3GzIvKYXNOBViT8TveArjx
41 Spotify spotify:album:32ba83vqMBeVwBSgojB6Qh
42 Spotify spotify:album:4TU8d9DGafZZiyN7peC4sl
43 Spotify spotify:album:6cHPEbPryLpH5VX5Eb1Vvo
44 Spotify spotify:album:4FQCkWPRIwL0mViQeCVzIP
45 Spotify spotify:album:6siM9Wpdrdlt5xQYohETIh
46 Spotify spotify:album:6vygseD1InhHomosteUnPU
47 Spotify spotify:album:15OVBQYlldnAnwLnEywCJA
48 Spotify spotify:album:35sSbw9dsgac2kWr28VRBK
50 Spotify spotify:album:2elMZGk2lTVphTWnIj6IBk
51 Spotify spotify:album:5sdyMR1K9FtdmanZnzb6Qx
52 Spotify spotify:album:3MFksXFSiUyvXluuSVo7vf
53 Spotify spotify:album:5QIf4hNIAksV1uMCXHVkAZ
54 Spotify spotify:album:3U1ZtC1Rb0zEbo2LnHRPEY
55 Spotify spotify:album:2linjQ8fQvdsrbGScOvwap
56 Spotify spotify:album:25dw2V4di8Wibx99F1jE5R
57 Spotify spotify:album:5n2o01hCa9UD1g8HXCrZmV
58 Spotify spotify:album:2Ua5hS8optZ2qKeGLWyhUt
59 Spotify spotify:album:0u9EF2bbsELJvn9ibBzUm7
60 Spotify spotify:album:5tiWSutt09Cqi6ty1dYzXJ
61 Spotify spotify:album:7wAP4Bb3vyXR6uV8lXv2VZ
62 Spotify spotify:album:0wBiN0fKhy0ywx732SpgUs
63 Spotify spotify:album:1vWnB0hYmluskQuzxwo25a
64 Spotify spotify:album:159ORixBSSemxiualv1Woj
import json
return json.dumps({r[0]: (r[1], r[2]) for r in actions})

Dispatcher


ACTIONS = json.load(open(sys.argv[2]))

for barcode in barcodes(sys.argv[1]):
    try:
        action, parameter = ACTIONS[str(int(barcode))]
        print(barcode, action)
        if action == "Spotify":
            subprocess.run(["spotify-cli", "start_playback", "0f485546c29815174e3dab22bdeabcfd2f08e677", parameter])
    except Exception as e:
        print("Fail:", barcode, e)