Skip to content

Commit 6752dc8

Browse files
committed
Add functions to set DVDCSS_VERBOSE and DVDCSS_METHOD
1 parent d75ef03 commit 6752dc8

File tree

4 files changed

+81
-24
lines changed

4 files changed

+81
-24
lines changed

HISTORY.md

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

55
N/A
66

7+
## 1.0.6
8+
9+
**Improvements**
10+
11+
- Add functions to set DVDCSS_VERBOSE and DVDCSS_METHOD environment variables.
12+
- Reset DVDCSS_VERBOSE and DVDCSS_METHOD on dispose.
13+
714
## 1.0.5
815

916
**Bugfixes**

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
# check if dvd is scrambled
3333
if dvdcss.is_scrambled():
3434
print("The DVD is scrambled!")
35-
35+
3636
# read volume id from sector 16
3737
dvdcss.seek(16) # seek to sector 16
3838
dvdcss.read(1) # read only one sector
3939
data = dvdcss.buffer # access the latest read data
4040
volume_label = data[40:72].strip().decode()
4141
print(f"{dev}: {volume_label}")
4242
# >> eg. `'/dev/sr0: THE_IT_CROWD_DISC_1'`
43-
43+
4444
# make sure you dispose when your done if you didn't
4545
# use `with`, otherwise stuff will get stuck in memory.
4646
# usage of `with` on pydvdcss automatically handles disposing.
@@ -103,28 +103,28 @@ or
103103
cd pydvdcss
104104
python -m pip install --user .
105105

106-
*Note: with the second method you will need to handle updating yourself by re-cloning and installing it again.*
106+
_Note: with the second method you will need to handle updating yourself by re-cloning and installing it again._
107107

108108
<p>&nbsp;</p><p>&nbsp;</p>
109109

110110
# To-do
111111

112-
- [X] Implement dvdcss_open
113-
- [X] Implement dvdcss_close
114-
- [X] Implement dvdcss_seek
115-
- [X] Implement dvdcss_read
116-
- [X] Implement dvdcss_error
117-
- [X] Implement dvdcss_is_scrambled
118-
- [X] Implement `__enter__` and `__exit__` for proper disposing
119-
- [X] Add handlers for failed find_library calls
120-
- [X] Add instructions for installing libdvdcss
121-
- [X] Add and test support for Windows
122-
- [X] Add and test support for Mac OS
123-
- [X] Add and test support for Linux
124-
- [ ] Implement dvdcss_readv
125-
- [ ] Add handlers for failed cdll calls
126-
- [ ] Add function to set DVDCSS_VERBOSE
127-
- [ ] Add function to set DVDCSS_METHOD
112+
- [x] Implement dvdcss_open
113+
- [x] Implement dvdcss_close
114+
- [x] Implement dvdcss_seek
115+
- [x] Implement dvdcss_read
116+
- [x] Implement dvdcss_error
117+
- [x] Implement dvdcss_is_scrambled
118+
- [x] Implement `__enter__` and `__exit__` for proper disposing
119+
- [x] Add handlers for failed find_library calls
120+
- [x] Add instructions for installing libdvdcss
121+
- [x] Add and test support for Windows
122+
- [x] Add and test support for Mac OS
123+
- [x] Add and test support for Linux
124+
- [x] Add function to set DVDCSS_VERBOSE
125+
- [x] Add function to set DVDCSS_METHOD
126+
- [ ] Implement dvdcss_readv, not sure how this would be used or implemented
127+
- [ ] Handle errors for failed cdll calls if any?
128128

129129
<p>&nbsp;</p><p>&nbsp;</p>
130130

@@ -161,10 +161,10 @@ happened.
161161
Tips:
162162

163163
> Use SEEK_MPEG flag when seeking throughout VOB data sectors. It isn't needed
164-
on the first sector.
164+
> on the first sector.
165165
166-
> Use SEEK_KEY flag the first time you enter a TITLE. You *can* always call it
167-
in VOB data sectors, however it will be unnecessary and cause slowdowns.
166+
> Use SEEK_KEY flag the first time you enter a TITLE. You _can_ always call it
167+
> in VOB data sectors, however it will be unnecessary and cause slowdowns.
168168
169169
- **i_blocks**: absolute block offset to seek to.
170170
- **i_flags**: NOFLAGS by default, or you can specify SEEK_KEY or SEEK_MPEG flags.
@@ -214,4 +214,4 @@ Returns True if it's scrambled.
214214

215215
## [CONTRIBUTORS](https://github.com/rlaPHOENiX/pydvdcss/graphs/contributors)
216216

217-
</span>
217+
</span>

pydvdcss/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ctypes, ctypes.util
22
import platform
3+
import os
34

45

56
class PyDvdCss:
@@ -129,6 +130,9 @@ def dispose(self):
129130
self.buffer_len = 0
130131
if self.handle:
131132
self.close()
133+
# reset verbosity and cracking mode environment variables
134+
self.set_verbosity(None)
135+
self.set_cracking_mode(None)
132136

133137
def open(self, psz_target):
134138
"""
@@ -214,3 +218,49 @@ def is_scrambled(self):
214218
Check if the DVD is scrambled.
215219
"""
216220
return self._is_scrambled(self.handle) == 1
221+
222+
def set_verbosity(self, verbosity=0):
223+
"""
224+
Set libdvdcss's verbosity (DVDCSS_VERBOSE environment variable).
225+
226+
Available options are int 0..2
227+
None: Unset/Remove/Reset the cracking mode.
228+
0: no error messages, no debug messages (this is the default)
229+
1: only error messages
230+
2: error and debug messages
231+
232+
Returns the now current value of DVDCSS_VERBOSE, expected value should be
233+
the same as the verbosity int provided.
234+
"""
235+
if verbosity is None:
236+
os.unsetenv("DVDCSS_VERBOSE")
237+
return None
238+
os.environ["DVDCSS_VERBOSE"] = str(verbosity)
239+
return os.environ["DVDCSS_VERBOSE"]
240+
241+
def set_cracking_mode(self, mode="key"):
242+
"""
243+
Set libdvdcss's cracking mode (DVDCSS_METHOD environment variable).
244+
245+
Available options:
246+
None: Unset/Remove/Reset the cracking mode.
247+
'title': By default the decrypted title key is guessed from the encrypted
248+
sectors of the stream. Thus it should work with a file as well as
249+
the DVD device. But decrypting a title key may take too much time
250+
or even fail. With the title method, the key is only checked at
251+
the beginning of each title, so it will not work if the key
252+
changes in the middle of a title.
253+
'disc': The disc key is cracked first. Afterwards all title keys can be
254+
decrypted instantly, which allows checking them often.
255+
'key': The same as the "disc" method if you do not have a file with player
256+
keys at compile time. If you do, disc key decryption will be faster.
257+
This is the default method also employed by libcss.
258+
259+
Returns the now current value of DVDCSS_METHOD, expected value should be
260+
the same as the mode string provided.
261+
"""
262+
if mode is None:
263+
os.unsetenv("DVDCSS_METHOD")
264+
return None
265+
os.environ["DVDCSS_METHOD"] = mode
266+
return os.environ["DVDCSS_METHOD"]

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.5",
8+
version="1.0.6",
99
author="PHOENiX",
1010
author_email="rlaphoenix@pm.me",
1111
description="Python wrapper for VideoLAN's libdvdcss.",

0 commit comments

Comments
 (0)