]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/postprocessor/common.py
debian/copyright: Fix lintian's dep5-copyright-license-name-not-unique.
[youtubedl] / youtube_dl / postprocessor / common.py
1 from __future__ import unicode_literals
2
3 import os
4
5 from ..utils import (
6 PostProcessingError,
7 encodeFilename,
8 )
9
10
11 class PostProcessor(object):
12 """Post Processor class.
13
14 PostProcessor objects can be added to downloaders with their
15 add_post_processor() method. When the downloader has finished a
16 successful download, it will take its internal chain of PostProcessors
17 and start calling the run() method on each one of them, first with
18 an initial argument and then with the returned value of the previous
19 PostProcessor.
20
21 The chain will be stopped if one of them ever returns None or the end
22 of the chain is reached.
23
24 PostProcessor objects follow a "mutual registration" process similar
25 to InfoExtractor objects.
26 """
27
28 _downloader = None
29
30 def __init__(self, downloader=None):
31 self._downloader = downloader
32
33 def set_downloader(self, downloader):
34 """Sets the downloader for this PP."""
35 self._downloader = downloader
36
37 def run(self, information):
38 """Run the PostProcessor.
39
40 The "information" argument is a dictionary like the ones
41 composed by InfoExtractors. The only difference is that this
42 one has an extra field called "filepath" that points to the
43 downloaded file.
44
45 This method returns a tuple, the first element is a list of the files
46 that can be deleted, and the second of which is the updated
47 information.
48
49 In addition, this method may raise a PostProcessingError
50 exception if post processing fails.
51 """
52 return [], information # by default, keep file and do nothing
53
54 def try_utime(self, path, atime, mtime, errnote='Cannot update utime of file'):
55 try:
56 os.utime(encodeFilename(path), (atime, mtime))
57 except Exception:
58 self._downloader.report_warning(errnote)
59
60
61 class AudioConversionError(PostProcessingError):
62 pass