Passed
Push — master ( 7bc1c2...5b857f )
by Amin
03:31
created

Streams.first_stream()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 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)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable stream does not seem to be defined.
Loading history...
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