This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturn_dict_of_ISO_tracks.py
47 lines (40 loc) · 1.63 KB
/
return_dict_of_ISO_tracks.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
# -*- coding: utf-8 -*-
##############################################################################################
# This file is deprecated because Python 2.x is deprecated #
# A Python 3.x version of this file can be found at: #
# #
# https://github.com/Guymer/PyGuymer3/blob/master/return_dict_of_ISO_tracks.py #
##############################################################################################
def return_dict_of_ISO_tracks(fname):
# Import modules ...
import subprocess
import xml.etree.ElementTree
# Find track info ...
proc = subprocess.Popen(
[
"lsdvd",
"-x",
"-Ox",
fname
],
stderr = subprocess.PIPE,
stdout = subprocess.PIPE
)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
raise Exception(u"\"lsdvd\" command failed")
# Clean up ...
# NOTE: "lsdvd" sometimes returns invalid XML as it does not:
# * escape characters; or
# * remove invalid characters.
stdout = unicode(stdout, "utf-8", "ignore").replace(u"&", u"&")
# Create empty dictionary ...
ans = {}
# Loop over all tracks ...
for track in xml.etree.ElementTree.fromstring(stdout).findall(u"track"):
# Append information ...
ans[track.find(u"ix").text] = {
u"length" : float(track.find(u"length").text) # [s]
}
# Return dictionary ...
return ans