2017-07-22 22 views
0

多くのビデオファイルから一部のメタデータを読み込む必要があります。いくつかの研究の後、私はhttp://www.scikit-video.orgにぶつかった。私はskvideo.io.ffprobeを使って、私が望む結果を私に与えました。それは私が探している情報で辞書を返します。Python辞書の特定のキーを特定する方法。

それは次のようになります。私の質問は、私は日付分離することができる方法である

{ 
    "@index": "0", 
    "@codec_name": "mjpeg", 
    "@nb_frames": "2880", 
    "disposition": { 
     "@default": "1", 
     "@dub": "0", 
     "@timed_thumbnails": "0" 
    }, 
    "tag": [ 
     { 
      "@key": "creation_time", 
      "@value": "2006-11-22T23:10:06.000000Z" 
     }, 
     { 
      "@key": "language", 
      "@value": "eng" 
     }, 
     { 
      "@key": "encoder", 
      "@value": "Photo - JPEG" 
     } 
    ] 
} 

":10:2006-11-22T23を:06.000000Z"

{ "@index": "0", "@codec_name": "mjpeg", "@nb_frames": "2880", "disposition": {"@default": "1", "@dub": "0", "@timed_thumbnails": "0"}, "tag": [{"@key": "creation_time", "@value": "2006-11-22T23:10:06.000000Z"}, {"@key": "language", "@value": "eng"}, {"@key": "encoder", "@value": "Photo - JPEG"}]} 

それともかなりの印刷で。私はいくつかのことを試しましたが、私は立ち往生しました。キーや値を取得できません。私は何かが欠けていると信じています。

本当に助けていただきありがとうございます。

おかげ

+0

'' 'によって' '' '' 'を隔離するという意味ですか? – wwii

答えて

1

でそれをすべて行うことができます、あなたは CREATION_TIMEが指定されているを見つけることがあります...

data = {"@index": "0", "@codec_name": "mjpeg", "@nb_frames": "2880", "disposition": {"@default": "1", "@dub": "0", "@timed_thumbnails": "0"}, 
     "tag": [{"@key": "creation_time", "@value": "2006-11-22T23:10:06.000000Z"}, {"@key": "language", "@value": "eng"}, {"@key": "encoder", "@value": "Photo - JPEG"}]} 

def get_creation_time(data): 
    for inner_dict in data["tag"]: 
     if inner_dict['@key'] == 'creation_time': 
      return inner_dict['@value'] 
    raise ValueError('creation_time key value is not in tag information') 

これは、タグ内のすべての「内部dict」に@keyと@valueが含まれていることも前提としています。

1

は、あなたはほど辞書のうちのリストを取得する必要がありますので、それをアクセスするために、キー"tag"のリストを値として持っています。

your_dict = #The code you're using to get that dictionary 
internal_list = your_dict["tag"] 
correct_dict = internal_list[0] #Because it's at the first position of the list 
print(correct_dict["@value"]) #This prints the value of that dictionary from within the list at value of key "tag" 

それとも、タグリストの最初の要素は、作成時間が含まれていることを任意の仮定がなければ一歩

your_dict = #The code you're using to get that dictionary 
print(your_dict["tag"][0]["@value"]) 
関連する問題