I am making a DVD ripping script with MakeMKV & Handbrake and I was getting drive info and was wondering if there's a better & cleaner way of getting the Drive id?
from collections import namedtuple
import win32api
Drive = namedtuple(typename="Drive",
field_names=["title", "id", "maxfilenamlen", "sysflags", "filesystemtype"])
def get_drive_info(drive_path, new_id=None):
Drive_list = list(win32api.GetVolumeInformation(drive_path))
if new_id:
Drive_list[1] = new_id
return Drive(*Drive_list)
def get_all_cd_drives() -> list:
cd_drives = []
drives = win32api.GetLogicalDriveStrings()
# filtering the raw string
for drive_id, drive in enumerate(list(filter(None, drives.split('\000')))):
# print(f"{drive=}")
drive_info = get_drive_info(drive_path=drive)
# Getting all DVD Drives
if drive_info.filesystemtype == "UDF":
cd_drives.append(get_drive_info(drive, drive_id))
return cd_drives
# print(get_all_cd_drives()[0])
print(get_drive_info("c:\\"))
Results
Drive(title='Test-DVD-Title', id=1, maxfilenamlen=254, sysflags=21496327, filesystemtype='UDF')