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
#7
(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
Daring_T likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: How to get a removable disc type in drive - by Gribouillis - Feb-07-2024, 01:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create dual folder on different path/drive based on the date agmoraojr 2 1,442 Jan-21-2024, 10:02 AM
Last Post: snippsat
  open python files in other drive akbarza 1 1,573 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  Integrating Google Drive in App Lahearle 0 1,116 Jul-19-2023, 05:51 PM
Last Post: Lahearle
  code to send attachments contained on the drive. stefanoste78 1 1,684 Oct-12-2022, 02:16 AM
Last Post: Larz60+
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 2,973 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Cant Access D: Drive kucingkembar 4 2,781 Jul-28-2022, 04:53 PM
Last Post: kucingkembar
  Deploy Python to Cloud and save output to Google Drive chandrabr80 2 2,527 Jan-25-2022, 06:56 AM
Last Post: ndc85430
  Calling exe on network drive GrahamL 4 4,140 Jan-21-2022, 12:01 PM
Last Post: GrahamL
  string.format() suddenly causing errors with google drive API zwitrader 0 2,437 Jun-28-2021, 11:38 PM
Last Post: zwitrader
  Failing to copy file from a network to a local drive tester_V 4 10,571 Jan-20-2021, 07:40 AM
Last Post: tester_V

Forum Jump:

User Panel Messages

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