Passed
Push — master ( 67f2c8...68e9c9 )
by Amin
01:53
created

ExportHLSPlaylist::savePlayList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>.
5
 *
6
 * Licensed under the MIT License;
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      https://opensource.org/licenses/MIT
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace AYazdanpanah\FFMpegStreaming;
20
21
22
class ExportHLSPlaylist
23
{
24
    /**
25
     * @param $filename
26
     * @param $representations
27
     * @param $basename
28
     */
29
    public static function savePlayList($filename, $representations, $basename)
30
    {
31
        file_put_contents($filename, static::generateContents($representations, $basename));
32
    }
33
34
    /**
35
     * @param $representations
36
     * @param $basename
37
     * @return string
38
     */
39
    private static function generateContents($representations, $basename)
40
    {
41
        $content[] = "#EXTM3U";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$content was never initialized. Although not strictly required by PHP, it is generally a good practice to add $content = array(); before regardless.
Loading history...
42
        $content[] = "#EXT-X-VERSION:3";
43
44
        foreach ($representations as $representation) {
45
            if ($representation instanceof Representation) {
46
                $content[] = "#EXT-X-STREAM-INF:BANDWIDTH=" . $representation->getKiloBitrate() * 1024 . ",RESOLUTION=" . $representation->getResize();
47
                $content[] = $basename . "_" . $representation->getHeight() . "p.m3u8";
48
            }
49
        }
50
51
        return implode(PHP_EOL, $content);
52
    }
53
}