Skip to content

Commit 05f7332

Browse files
committed
1.0.7: Add handler for failed ctypes find_library call
1 parent efd79f4 commit 05f7332

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
N/A
66

7+
## 1.0.7
8+
9+
**Improvements**
10+
11+
- Add handler for failed ctypes cdll call
12+
713
## 1.0.6
814

915
**Improvements**

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ _Note: with the second method you will need to handle updating yourself by re-cl
114114
- [x] Implement dvdcss_is_scrambled
115115
- [x] Implement `__enter__` and `__exit__` for proper disposing
116116
- [x] Add handlers for failed find_library calls
117+
- [X] Add handlers for failed cdll calls
117118
- [x] Add instructions for installing libdvdcss
118119
- [x] Add and test support for Windows
119120
- [x] Add and test support for Mac OS
120121
- [x] Add and test support for Linux
121122
- [x] Add function to set DVDCSS_VERBOSE
122123
- [x] Add function to set DVDCSS_METHOD
123124
- [ ] Implement dvdcss_readv, not sure how this would be used or implemented
124-
- [ ] Handle errors for failed cdll calls if any?
125125

126126
<p>&nbsp;</p><p>&nbsp;</p>
127127

pydvdcss/__init__.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,12 @@ class PyDvdCss:
7272
if LIB:
7373
break
7474
if not LIB:
75-
err = "PyDvdCss: Unable to locate libdvdcss library, please install it.\n"
76-
if platform.system() == "Windows":
77-
dll = f"https://github.com/allienx/libdvdcss-dll/raw/master/1.4.2/{platform.architecture()[0].replace('b', '-b')}/libdvdcss-2.dll"
78-
err += "\n".join([
79-
"On Windows, the installation process is a bit annoying, so I calculated it all for you:",
80-
f"Download the following file: `{dll}``",
81-
f"Place the file in: `C:/Windows/{'SysWOW64' if platform.machine().endswith('64') else 'System32'}``",
82-
f"Done!"
83-
])
84-
elif platform.system() == "Darwin":
85-
err += "\n".join([
86-
"On Mac, the installation process is easiest when using `brew`.",
87-
"If you don't have brew installed, follow the instructions at `https://brew.sh`",
88-
"Once installed, open terminal and type: `brew install libdvdcss`",
89-
"Done!"
90-
])
91-
elif platform.system() == "Linux":
92-
err += "\n".join([
93-
"On Linux, the installation process is very simple.",
94-
"Just check your Package Distro for `libdvdcss` or possibly `libdvdcss-2` or the alike.",
95-
"If it's not found, check it's User Repository or compile it yourself.",
96-
"If you compile it yourself, make sure it's somewhere in PATH for pydvdcss to find it.",
97-
"pydvdcss uses ctypes.util.find_library to search for the library.",
98-
"It uses `/sbin/ldconfig`, `gcc`, `objdump` and `ld` to try find the library.",
99-
"Good luck!"
100-
])
101-
raise EnvironmentError(err)
102-
LIB = ctypes.CDLL(LIB)
103-
# todo ; it's assuming find_library and cdll were successful
75+
_libdvdcss_installation()
76+
try:
77+
LIB = ctypes.CDLL(LIB)
78+
except OSError:
79+
_libdvdcss_installation()
80+
10481
_open = ctypes.CFUNCTYPE(ctypes.c_long, ctypes.c_char_p)(("dvdcss_open", LIB))
10582
_close = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_long)(("dvdcss_close", LIB))
10683
_seek = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_long, ctypes.c_int, ctypes.c_int)(
@@ -133,6 +110,35 @@ def dispose(self):
133110
# reset verbosity and cracking mode environment variables
134111
self.set_verbosity(None)
135112
self.set_cracking_mode(None)
113+
114+
def _libdvdcss_installation(self):
115+
err = "PyDvdCss: Unable to locate libdvdcss library, please install it.\n"
116+
if platform.system() == "Windows":
117+
dll = f"https://github.com/allienx/libdvdcss-dll/raw/master/1.4.2/{platform.architecture()[0].replace('b', '-b')}/libdvdcss-2.dll"
118+
err += "\n".join([
119+
"On Windows, the installation process is a bit annoying, so I calculated it all for you:",
120+
f"Download the following file: `{dll}``",
121+
f"Place the file in: `C:/Windows/{'SysWOW64' if platform.machine().endswith('64') else 'System32'}``",
122+
f"Done!"
123+
])
124+
elif platform.system() == "Darwin":
125+
err += "\n".join([
126+
"On Mac, the installation process is easiest when using `brew`.",
127+
"If you don't have brew installed, follow the instructions at `https://brew.sh`",
128+
"Once installed, open terminal and type: `brew install libdvdcss`",
129+
"Done!"
130+
])
131+
elif platform.system() == "Linux":
132+
err += "\n".join([
133+
"On Linux, the installation process is very simple.",
134+
"Just check your Package Distro for `libdvdcss` or possibly `libdvdcss-2` or the alike.",
135+
"If it's not found, check it's User Repository or compile it yourself.",
136+
"If you compile it yourself, make sure it's somewhere in PATH for pydvdcss to find it.",
137+
"pydvdcss uses ctypes.util.find_library to search for the library.",
138+
"It uses `/sbin/ldconfig`, `gcc`, `objdump` and `ld` to try find the library.",
139+
"Good luck!"
140+
])
141+
raise EnvironmentError(err)
136142

137143
def open(self, psz_target):
138144
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="pydvdcss",
8-
version="1.0.6",
8+
version="1.0.7",
99
author="PHOENiX",
1010
author_email="rlaphoenix@pm.me",
1111
description="Python wrapper for VideoLAN's libdvdcss.",

0 commit comments

Comments
 (0)