]>
Commit | Line | Data |
---|---|---|
dcddc10a PH |
1 | from __future__ import unicode_literals |
2 | ||
dd29eb7f S |
3 | import os |
4 | ||
5 | from ..utils import ( | |
6 | PostProcessingError, | |
6270239a | 7 | cli_configuration_args, |
dd29eb7f S |
8 | encodeFilename, |
9 | ) | |
496c1923 PH |
10 | |
11 | ||
12 | class PostProcessor(object): | |
13 | """Post Processor class. | |
14 | ||
15 | PostProcessor objects can be added to downloaders with their | |
16 | add_post_processor() method. When the downloader has finished a | |
17 | successful download, it will take its internal chain of PostProcessors | |
18 | and start calling the run() method on each one of them, first with | |
19 | an initial argument and then with the returned value of the previous | |
20 | PostProcessor. | |
21 | ||
22 | The chain will be stopped if one of them ever returns None or the end | |
23 | of the chain is reached. | |
24 | ||
25 | PostProcessor objects follow a "mutual registration" process similar | |
e35b23f5 S |
26 | to InfoExtractor objects. |
27 | ||
28 | Optionally PostProcessor can use a list of additional command-line arguments | |
29 | with self._configuration_args. | |
496c1923 PH |
30 | """ |
31 | ||
32 | _downloader = None | |
33 | ||
aa5d9a79 | 34 | def __init__(self, downloader=None): |
496c1923 PH |
35 | self._downloader = downloader |
36 | ||
37 | def set_downloader(self, downloader): | |
38 | """Sets the downloader for this PP.""" | |
39 | self._downloader = downloader | |
40 | ||
41 | def run(self, information): | |
42 | """Run the PostProcessor. | |
43 | ||
44 | The "information" argument is a dictionary like the ones | |
45 | composed by InfoExtractors. The only difference is that this | |
46 | one has an extra field called "filepath" that points to the | |
47 | downloaded file. | |
48 | ||
592e97e8 JMF |
49 | This method returns a tuple, the first element is a list of the files |
50 | that can be deleted, and the second of which is the updated | |
51 | information. | |
496c1923 PH |
52 | |
53 | In addition, this method may raise a PostProcessingError | |
54 | exception if post processing fails. | |
55 | """ | |
592e97e8 | 56 | return [], information # by default, keep file and do nothing |
496c1923 | 57 | |
dd29eb7f S |
58 | def try_utime(self, path, atime, mtime, errnote='Cannot update utime of file'): |
59 | try: | |
60 | os.utime(encodeFilename(path), (atime, mtime)) | |
61 | except Exception: | |
62 | self._downloader.report_warning(errnote) | |
63 | ||
e35b23f5 | 64 | def _configuration_args(self, default=[]): |
3026164b | 65 | return cli_configuration_args(self._downloader.params, 'postprocessor_args', default) |
e35b23f5 | 66 | |
496c1923 PH |
67 | |
68 | class AudioConversionError(PostProcessingError): | |
69 | pass |