Python Forum
How to get a removable disc type in drive
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get a removable disc type in drive
#9
(Feb-07-2024, 01:32 PM)Gribouillis Wrote:
(Feb-07-2024, 03:34 AM)Daring_T Wrote: I am not seeing a way to see the disc's type.
I had some success on my linux computer with the command

Output:
udevadm info -q property /dev/cdrom
When a DVD is inserted, the output contains a line
Output:
ID_CDROM_MEDIA_DVD=1
When a CD is inserted, or an audio CD, there is a line
Output:
ID_CDROM_MEDIA_CD=1
When there is nothing in the CD drive, there is no ID_CDROM_MEDIA... line in the output. I don't have a blue ray disk to see what it does.

EDIT: after some tests, I was able to get the information with pyudev
import pyudev


def main():
    context = pyudev.Context()
    a = context.list_devices(sys_name="sr0")
    dev = next(iter(a))
    # print(dev)
    # print(dict(dev.properties))
    if dev.properties.get("ID_CDROM_MEDIA_CD", False):
        print("CD drive contains a CD")
    elif dev.properties.get("ID_CDROM_MEDIA_DVD", False):
        print("CD drive contains a DVD")


if __name__ == "__main__":
    main()
Output:
λ python paillasse/pf/cdrom.py CD drive contains a DVD
It seems that for blue ray, the property is ID_CDROM_MEDIA_BD

Thanks Gribouillis for the code snippet, worked like a charm. I just need to figure out blue-ray's. Unfortunately dict(dev.properties) does not show or add an different var for blue-rays from what I can see. I need to do some more digging with udev rules and dd but I have ran out of time today. I will post if I find a solution for blue-rays.

Thanks both for your help,
Daring_T

Also here is what a blue-ray looks like with running dict(dev.properties):

Output:
{'CURRENT_TAGS': ':uaccess:systemd:seat:', 'DEVLINKS': '/dev/disk/by-path/pci-0000:00:14.0-usb-0:4.4:1.0-scsi-0:0:0:0 ' '/dev/disk/by-id/usb-ASUS_BW-16D1HT_20201230-0:0 ' '/dev/disk/by-uuid/8cd94d0851963909 ' '/dev/disk/by-label/INCREDIBLES_D2', 'DEVNAME': '/dev/sr1', 'DEVPATH': '/devices/pci0000:00/0000:00:14.0/usb3/3-4/3-4.4/3-4.4:1.0/host5/target5:0:0/5:0:0:0/block/sr1', 'DEVTYPE': 'disk', 'DISKSEQ': '82', 'ID_BUS': 'usb', 'ID_CDROM': '1', 'ID_CDROM_BD': '1', 'ID_CDROM_BD_R': '1', 'ID_CDROM_BD_RE': '1', 'ID_CDROM_BD_R_RRM': '1', 'ID_CDROM_BD_R_SRM': '1', 'ID_CDROM_CD': '1', 'ID_CDROM_CD_R': '1', 'ID_CDROM_CD_RW': '1', 'ID_CDROM_DVD': '1', 'ID_CDROM_DVD_PLUS_R': '1', 'ID_CDROM_DVD_PLUS_RW': '1', 'ID_CDROM_DVD_PLUS_R_DL': '1', 'ID_CDROM_DVD_R': '1', 'ID_CDROM_DVD_RAM': '1', 'ID_CDROM_DVD_RW': '1', 'ID_CDROM_DVD_RW_RO': '1', 'ID_CDROM_DVD_RW_SEQ': '1', 'ID_CDROM_DVD_R_DL': '1', 'ID_CDROM_DVD_R_DL_JR': '1', 'ID_CDROM_DVD_R_DL_SEQ': '1', 'ID_CDROM_MEDIA': '1', 'ID_CDROM_MEDIA_BD': '1', 'ID_CDROM_MEDIA_SESSION_COUNT': '1', 'ID_CDROM_MEDIA_STATE': 'complete', 'ID_CDROM_MEDIA_TRACK_COUNT': '1', 'ID_CDROM_MEDIA_TRACK_COUNT_DATA': '1', 'ID_CDROM_MRW': '1', 'ID_CDROM_MRW_W': '1', 'ID_CDROM_RW_REMOVABLE': '1', 'ID_FOR_SEAT': 'block-pci-0000_00_14_0-usb-0_4_4_1_0-scsi-0_0_0_0', 'ID_FS_APPLICATION_ID': 'APPLICATION_ID', 'ID_FS_LABEL': 'INCREDIBLES_D2', 'ID_FS_LABEL_ENC': 'INCREDIBLES_D2', 'ID_FS_LOGICAL_VOLUME_ID': 'INCREDIBLES_D2', 'ID_FS_TYPE': 'udf', 'ID_FS_USAGE': 'filesystem', 'ID_FS_UUID': '8cd94d0851963909', 'ID_FS_UUID_ENC': '8cd94d0851963909', 'ID_FS_VERSION': '2.50', 'ID_FS_VOLUME_ID': 'INCREDIBLES_D2', 'ID_FS_VOLUME_SET_ID': '8CD94D0851963909_VOLUME_SET_ID', 'ID_INSTANCE': '0:0', 'ID_MODEL': 'BW-16D1HT', 'ID_MODEL_ENC': 'BW-16D1HT\\x20\\x20\\x20\\x20\\x20\\x20\\x20', 'ID_MODEL_ID': '0611', 'ID_PATH': 'pci-0000:00:14.0-usb-0:4.4:1.0-scsi-0:0:0:0', 'ID_PATH_TAG': 'pci-0000_00_14_0-usb-0_4_4_1_0-scsi-0_0_0_0', 'ID_REVISION': '3.00', 'ID_SERIAL': 'ASUS_BW-16D1HT_20201230-0:0', 'ID_SERIAL_SHORT': '01234567', 'ID_TYPE': 'cd', 'ID_USB_DRIVER': 'usb-storage', 'ID_USB_INTERFACES': ':080650:', 'ID_USB_INTERFACE_NUM': '00', 'ID_VENDOR': 'ASUS', 'ID_VENDOR_ENC': 'ASUS\\x20\\x20\\x20\\x20', 'ID_VENDOR_ID': '1f75', 'MAJOR': '11', 'MINOR': '1', 'SUBSYSTEM': 'block', 'SYSTEMD_MOUNT_DEVICE_BOUND': '1', 'TAGS': ':uaccess:systemd:seat:', 'USEC_INITIALIZED': '1989315471'}
Reply


Messages In This Thread
RE: How to get a removable disc type in drive - by Daring_T - Feb-08-2024, 05:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  open python files in other drive akbarza 1 850 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  Integrating Google Drive in App Lahearle 0 551 Jul-19-2023, 05:51 PM
Last Post: Lahearle
  code to send attachments contained on the drive. stefanoste78 1 980 Oct-12-2022, 02:16 AM
Last Post: Larz60+
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,938 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Cant Access D: Drive kucingkembar 4 1,519 Jul-28-2022, 04:53 PM
Last Post: kucingkembar
  Calling exe on network drive GrahamL 4 2,768 Jan-21-2022, 12:01 PM
Last Post: GrahamL
  Failing to copy file from a network to a local drive tester_V 4 7,467 Jan-20-2021, 07:40 AM
Last Post: tester_V
  Type hinting - return type based on parameter micseydel 2 2,614 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Nested Subdirectory within current sub on shared network drive Agregware 1 2,030 Jun-19-2019, 10:07 PM
Last Post: Gribouillis
  trouble with os.listdir on a network drive lconner 10 19,551 Jun-04-2019, 07:16 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020