Code Monkey home page Code Monkey logo

m3u8's Introduction

PConfig

PConfig is a PHP library for parsing configuration. It is lightweight and easy to use.

Supported formats

  • php
  • json
  • xml
  • yaml
  • ini

Installation

composer require oopsguy/pconfig

Usage

<?php
use pconfig\PConfig;
use pconfig\provider\impl\FileProvider;
use pconfig\serializer\impl\JSONSerializer;

$config = new PConfig('config-file.json');

$config = new PConfig([
    'file' => 'config-file.json'
]);

$config = new PConfig([
    'data' => [
        'key' => 'value'
        // more...
    ]
]);
$config->setSerializer(new JSONSerializer());
$config->setProvider(new FileProvider('config/a.json'));

$config = new PConfig([
   'file' => 'config-file.json',
   'serializer' => new JSONSerializer(),
]);

$config = new PConfig([
    'serializer' => new JSONSerializer(),
    'provider' => new FileProvider('config-file.json'),
]);
<?php
use pconfig\PConfig;
use pconfig\serializer\impl\YAMLSerializer;
use pconfig\provider\impl\FileProvider;

// PHP array
// Automatically detect file extension and select a suitable serializer
$config = new PConfig("config/config.php");
echo $config->get("app");
$config->delete("version");
$config->set('debug', false);
$config->set("settings.key", "new value");
$config->save();

// handle JSON
$jsonConfig = new PConfig('config/config.json');
$jsonConfig->set('homepage', 'https://github.com');
// Save as temp.json file
$jsonConfig->setFile('config/temp.json');
$jsonConfig->save();

// Parsing YAML
// Explicitly specify a YAML serializer
$serializer = new YAMLSerializer();
$provider = new FileProvider('config/settings.yaml');
$extConfig = new PConfig([
        'provider' => $provider,
        'serializer' => $serializer
    ]);
$extConfig->set('type', 'yaml');
$extConfig->save();

The default key separator is a dot-notation ..

key1.key2.key3

You can use PConfig::CONFIG_KEY_EXTRACT_SEPARATOR to custom your own separator.

PConfig::CONFIG_KEY_EXTRACT_SEPARATOR => '-',
key1-key2-key3
<?php
use pconfig\PConfig;
use pconfig\provider\impl\FileProvider;
use pconfig\serializer\impl\JSONSerializer;

$config = new PConfig([
        // Specify the serializer
        'serializer' => new JSONSerializer(),
        'provider' => new FileProvider('config/config.php'),
        'config' => [
                // Set the key separator
                PConfig::CONFIG_KEY_EXTRACT_SEPARATOR => '-', 
            ]
    ]);

ArrayAccess

PConfig has implemented ArrayAccess interface, you can access configuration by array operations.

<?php
use pconfig\PConfig;

// Access by index
$json = new PConfig('./config/arrayaccess.json');
$json['status'] = true;
$json['data'] = [
    'page' => 1,
    'pageSize' => 10,
    'pages' => 2,
    'total' => 13,
    'list' => [
        [
            'username' => 'oopsguy',
            'gender' => '男'
        ]
    ]
];
$json['msg'] = 'ok';
$json['delData'] = 'XHSYSYSDkoksoada8dsaidsa9d8adsa';

// unset and isset API
var_dump(isset($json['delData']));
unset($json['delData']);
var_dump(isset($json['delData']));

// Save to file
$json->save();

Nested configuration.

$config->set('level1.level2.level3', "Level end");
$config->delete('level1.level2');

APIs

  • set($key, $value)
  • get($key[, $defult])
  • delete($key)
  • exists($key)
  • getConfig($key)
  • setConfig($key, $value)
  • setProvider($provider)
  • setSerializer($serializer)
  • setFile($path)
  • reload()
  • clear()
  • save()

Licence

MIT Licence

m3u8's People

Contributors

oopsguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

m3u8's Issues

功能建议: 下载进度

我在dl库中未找到视频总的ts数量,以及已下载的ts数量。如果可以,希望添加这两个接口

Parse url failed: request m3u8 URL failed: http error: status code 403

Hello, I'm trying to download a SiriusXM stream and got the following error:

.\m3u8-windows-10-x64 -u="https://siriusxm-priprodlive.akamaized.net/AAC_Data/metropolitanopera/metropolitanopera_variant_large_v3.m3u8?token=1587734244_df40af36598eb6b72bd08d0470d1f78d&consumer=k2&gupId=3BDA15C5F23ADEEFE7B02D01A66968D4" -o="C:\downloads" Panic: parse url failed: request m3u8 URL failed: http error: status code 403

Is it related to the wrong master.m3u8 parsed?

To try it by yourself please go here with USA Vpn:
https://player.siriusxm.com/home/foryou > start free preview > all channels > and choose channel 75 (Met Opera Radio).

Thanks for looking into this!

Stuttering final TS file [bug]

First off want to thank you for building this! Took me so long to find a m3u8 downloader in Go. Anyways I am converting m3u8 to mp3/mp4. I've noticed in the final file that gets generated there are small stutters after each sequence. Possibly due to a merging issue. I've provide an audio file so you can hear exactly what I am trying to explain. If I manage to fix this I'll open a pull request.

file

parse url with '..' error

It seems that m3u8 can not parse ../a/b/c.ts of https://e/f/g.m3u8 correctly to https://e/a/b/c.ts

cannot find package

go run main.go -u=https://xxx.m3u8  -o=~/Downloads/xxx.mp4  

main.go:8:2: cannot find package "github.com/oopsguy/m3u8/dl" in any of:
	/usr/local/Cellar/go/1.15.1/libexec/src/github.com/oopsguy/m3u8/dl (from $GOROOT)
	/Users/alpha/go/src/github.com/oopsguy/m3u8/dl (from $GOPATH)

git clone的代码, 在项目根目录运行, 报这个错

directory not found

seriously why is there no documention? also the Mohave build doesn't even have a file ending

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.