Total Complexity | 12 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """ |
||
2 | ffmpeg_streaming.streams |
||
3 | ~~~~~~~~~~~~ |
||
4 | |||
5 | Parse streams that is the output of the FFProbe |
||
6 | |||
7 | |||
8 | :copyright: (c) 2020 by Amin Yazdanpanah. |
||
9 | :website: https://www.aminyazdanpanah.com |
||
10 | :email: [email protected] |
||
11 | :license: MIT, see LICENSE for more details. |
||
12 | """ |
||
13 | |||
14 | |||
15 | class Streams: |
||
16 | def __init__(self, streams): |
||
17 | self.streams = streams |
||
18 | |||
19 | def video(self): |
||
20 | return self._get_stream('video') |
||
21 | |||
22 | def audio(self): |
||
23 | return self._get_stream('audio') |
||
24 | |||
25 | def first_stream(self): |
||
26 | return self.streams[0] |
||
27 | |||
28 | def all(self): |
||
29 | return self.streams |
||
30 | |||
31 | def videos(self): |
||
32 | return self._get_streams('video') |
||
33 | |||
34 | def audios(self): |
||
35 | return self._get_streams('audio') |
||
36 | |||
37 | def _get_stream(self, media): |
||
38 | media_attr = next((stream for stream in self.streams if stream['codec_type'] == media), None) |
||
|
|||
39 | if media_attr is None: |
||
40 | raise ValueError('No ' + str(media) + ' stream found') |
||
41 | return media_attr |
||
42 | |||
43 | def _get_streams(self, media): |
||
44 | for stream in self.streams: |
||
45 | if stream['codec_type'] == media: |
||
46 | yield stream |
||
47 |