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
  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