]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/postprocessor/common.py
debian/changelog: Annotate with bug being closed.
[youtubedl] / youtube_dl / postprocessor / common.py
1 from __future__ import unicode_literals
2
3 import os
4
5 from ..utils import (
6 PostProcessingError,
7 cli_configuration_args,
8 encodeFilename,
9 )
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
26 to InfoExtractor objects.
27
28 Optionally PostProcessor can use a list of additional command-line arguments
29 with self._configuration_args.
30 """
31
32 _downloader = None
33
34 def __init__(self, downloader=None):
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
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.
52
53 In addition, this method may raise a PostProcessingError
54 exception if post processing fails.
55 """
56 return [], information # by default, keep file and do nothing
57
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
64 def _configuration_args(self, default=[]):
65 return cli_configuration_args(self._downloader.params, 'postprocessor_args', default)
66
67
68 class AudioConversionError(PostProcessingError):
69 pass