-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexamples.py
More file actions
executable file
·41 lines (31 loc) · 1.2 KB
/
examples.py
File metadata and controls
executable file
·41 lines (31 loc) · 1.2 KB
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
#!/usr/bin/env python
# Copyright (C) 2013 Johannes Dewender
# This example is free. You can redistribute and/or modify it at will.
# this will load Libdiscid
import discid
def simple_example():
disc = discid.read() # use default device
print(f"id: {disc.id}")
print(f"used {discid.get_default_device()} as device")
print(f"submit with:\n{disc.submission_url}")
def _length_str(seconds, sectors):
hours = seconds // 3600
seconds = seconds % 3600
if hours:
return f"{hours}:{seconds // 60:>02}:{seconds % 60:>02} ({sectors:>6})"
else:
return f" {seconds // 60:>2}:{seconds % 60:>02} ({sectors:>6})"
def complex_example():
device_name = discid.get_default_device()
disc = discid.read(device_name, ["mcn", "isrc"])
print(f"device:\t{device_name}")
print(f"id:\t{disc.id}")
print(f"MCN:\t{disc.mcn}")
print(f"length:\t{_length_str(disc.seconds, disc.sectors)}")
for track in disc.tracks:
length = _length_str(track.seconds, track.sectors)
print(f"{track.number:>2}: {track.offset:>6} {length}\tISRC: {track.isrc}")
if __name__ == "__main__":
# simple_example()
complex_example()
# vim:set shiftwidth=4 smarttab expandtab: