2

VLM telnet サービスからいくつかのデータがあります。

show
    media : ( 1 broadcast - 0 vod )
        cam1
            type : broadcast
            enabled : yes
            loop : no
            inputs
                1 : rtsp://xxx:xxx@xxx.xxx.xxx.xxx:xxx/xxxx/xxx.xxx
            output : #transcode{vcodec="h264"}:standard{access=http,mux=ts,dst=xxx.xxx.xxx.xxx:6690/cam1}
            options
            instances
                instance
                    name : default
                    state : playing
                    position : 0,000000
                    time : 0
                    length : -1
                    rate : 1,000000
                    title : 0
                    chapter : 0
                    can-seek : 0
                    playlistindex : 1
    schedule

このデータを XML または JSON または他の Perl がサポートする形式 (ハッシュテーブルなど) に変換する方法はありますか?

4

2 に答える 2

2

このデータはYAMLに非常に近く、おそらく意図的にそうです。あなたがする必要があるのは

  • ---コンテンツの開始をマークする最初の行を追加します

  • のようなコメントをすべて削除します( 1 broadcast - 0 vod )

  • 現在1つを含まないすべての行に末尾のコロンを追加します

mediaノードをコメントとノードのコンテナの両方に等しくすることはできないことを除いて、既存のコメントは問題ありませんcam1

このプログラムは、データを編集して適切なYAMLを形成し、それをPerlハッシュにロードして、結果をダンプします。

use strict;
use warnings;

use YAML 'Load';

open my $fh, '<', 'VLM.txt' or die $!;

my $yaml = "---\n";

while (<$fh>) {
  s/\s*\(.*//;
  s/$/ :/ unless /:/;
  $yaml .= $_;
}

my $data = Load($yaml);

use Data::Dump;
dd $data;

出力

{
  show => {
    media => {
      cam1 => {
        enabled   => "yes",
        inputs    => { 1 => "rtsp://xxx:xxx\@xxx.xxx.xxx.xxx:xxx/xxxx/xxx.xxx" },
        instances => {
                       instance => {
                         "can-seek"      => 0,
                         "chapter"       => 0,
                         "length"        => -1,
                         "name"          => "default",
                         "playlistindex" => 1,
                         "position"      => "0,000000",
                         "rate"          => "1,000000",
                         "state"         => "playing",
                         "time"          => 0,
                         "title"         => 0,
                       },
                     },
        loop      => "no",
        options   => undef,
        output    => "#transcode{vcodec=\"h264\"}:standard{access=http,mux=ts,dst=xxx.xxx.xxx.xxx:6690/cam1}",
        type      => "broadcast",
      },
    },
    schedule => undef,
  },
}
于 2012-07-21T13:51:13.930 に答える
1

あなたはおそらくすでに行われていることを試みています-このSFプロジェクトをチェックしてください:

http://sourceforge.net/projects/p5vlc/files/latest/download?source=files

于 2012-07-21T02:35:39.330 に答える