2017-03-26 66 views
1

나는 현재 팟 캐스트 플레이어를 만들 스위프트 3을 사용하고 있는데 나는 팟 캐스트 파일과 관련된 모든 '숨겨진'데이터 (메타 데이터)에 액세스하는 데 문제가.어떻게 스위프트를 사용하여 팟 캐스트의 모든 관련 데이터 또는 메타 데이터를 얻으려면?

특히, 애플의 팟 캐스트 응용 프로그램에서 그들은 오히려 '의견'또는 자세한 설명을 보여줍니다. 내가 지금까지 내 전체 응용 프로그램을 작성했습니다 방법이다 MPMediaPlayer 를 사용하는 경우이 정보를 사용할 수 없습니다.

내가 스위프트 사용하여 충분히 나를 위해 특정 바른 길에 수 있지만 보이는이 게시물을 발견했습니다 : Getting podcast metadata from from iPodLibrary

가 어떻게이 추가 정보에 액세스 할 수 있습니까?

또는 내 좋아 스위트 3 응용 프로그램에 링크 된 코드 OBJ (-C)를 구현하는 방법은 무엇입니까?

편집 :

좋아, 나는 해결책에 가까이 다가 가고있다. 그러나 이제는 다음 구조에서 특정 키를 얻는 방법을 알 수 없습니다.

는 여기에 내가이 함수에 팟 캐스트 (항목)를 전송하는 내 현재 코드의 첫 번째 :

format:org.id3 
metadata description:[<AVMetadataItem: 0x174005f40, identifier=id3/TIT2, keySpace=org.id3, key class = NSTaggedPointerString, key=TIT2, commonKey=title, extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=FriComedy: The News Quiz 3rd Feb 2017>, <AVMetadataItem: 0x174006160, identifier=id3/TPE1, keySpace=org.id3, key class = NSTaggedPointerString, key=TPE1, commonKey=artist, extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=BBC Radio 4>, <AVMetadataItem: 0x174006310, identifier=id3/TALB, keySpace=org.id3, key class = NSTaggedPointerString, key=TALB, commonKey=albumName, extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=Friday Night Comedy from BBC Radio 4>, <AVMetadataItem: 0x174006130, identifier=id3/TCON, keySpace=org.id3, key class = NSTaggedPointerString, key=TCON, commonKey=type, extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=Podcast>, <AVMetadataItem: 0x174006320, identifier=id3/USLT, keySpace=org.id3, key class = NSTaggedPointerString, key=USLT, commonKey=(null), extendedLanguageTag= , dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
    info = ""; 
}, value=Susan Calman, Andy Hamilton, Katy Brand and Lloyd Langford are amongst Miles' esteemed guests for this week's round of news-wrangling. 



Theresa May won a vote, Donald Trump won a vote and François Fillon might have to drop out of a vote. Orangutans can't vote but still feature in the programme. 



Producer: Richard Morris 

A BBC Studios Production>, <AVMetadataItem: 0x174006330, identifier=id3/COMM, keySpace=org.id3, key class = NSTaggedPointerString, key=COMM, commonKey=(null), extendedLanguageTag=en, dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
    info = ""; 
}, value=Susan Calman, Andy Hamilton, Katy Brand and Lloyd Langford are amongst Miles' esteemed guests for this week's round of news-wrangling. 



Theresa May won a vote, Donald Trump won a vote and François Fillon might have to drop out of a vote. Orangutans can't vote but still feature in the programme. 



Producer: Richard Morris 

A BBC Studios Production>, <AVMetadataItem: 0x174006340, identifier=id3/TCOP, keySpace=org.id3, key class = NSTaggedPointerString, key=TCOP, commonKey=copyrights, extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=(c) BBC 2017>, <AVMetadataItem: 0x174006350, identifier=id3/APIC, keySpace=org.id3, key class = NSTaggedPointerString, key=APIC, commonKey=artwork, extendedLanguageTag=(null), dataType=com.apple.metadata.datatype.JPEG, time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
    dataType = "image/jpeg"; 
    dataTypeNamespace = "org.iana.media-type"; 
    info = ""; 
    pictureType = "Cover (front)"; 
}, value length=50551>, <AVMetadataItem: 0x174006360, identifier=id3/TIT3, keySpace=org.id3, key class = NSTaggedPointerString, key=TIT3, commonKey=description, extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=A satirical review of the week's news, chaired by Miles Jupp>, <AVMetadataItem: 0x174006370, identifier=id3/TYER, keySpace=org.id3, key class = NSTaggedPointerString, key=TYER, commonKey=(null), extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=2017>, <AVMetadataItem: 0x174006380, identifier=id3/TDRL, keySpace=org.id3, key class = NSTaggedPointerString, key=TDRL, commonKey=(null), extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=2017-02-03T18:57:00Z>, <AVMetadataItem: 0x174006390, identifier=id3/COMM, keySpace=org.id3, key class = NSTaggedPointerString, key=COMM, commonKey=(null), extendedLanguageTag=en, dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
    info = iTunPGAP; 
}, value=0>, <AVMetadataItem: 0x1740063a0, identifier=id3/PCST, keySpace=org.id3, key class = NSTaggedPointerString, key=PCST, commonKey=(null), extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value length=4>, <AVMetadataItem: 0x1740063b0, identifier=id3/TDES, keySpace=org.id3, key class = NSTaggedPointerString, key=TDES, commonKey=(null), extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=Susan Calman, Andy Hamilton, Katy Brand and Lloyd Langford are amongst Miles' esteemed guests for this week's round of news-wrangling. 



Theresa May won a vote, Donald Trump won a vote and François Fillon might have to drop out of a vote. Orangutans can't vote but still feature in the programme. 



Producer: Richard Morris 

A BBC Studios Production>, <AVMetadataItem: 0x1740063c0, identifier=id3/TGID, keySpace=org.id3, key class = NSTaggedPointerString, key=TGID, commonKey=(null), extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=urn:bbc:podcast:p04rt97d>, <AVMetadataItem: 0x1740063d0, identifier=id3/WFED, keySpace=org.id3, key class = NSTaggedPointerString, key=WFED, commonKey=(null), extendedLanguageTag=(null), dataType=(null), time={INVALID}, duration={INVALID}, startDate=(null), extras={ 
}, value=%00http://www.bbc.co.uk/programmes/p02pc9pj/episodes/downloads.rss%00>] 

내가 분리하려고 : 주어진 팟 캐스트이 출력을 생성

///////// key=TDS 
func getMeta(_ item: MPMediaItem){ 
    print("") 
    print("--------- GETMETA ---------") 
    let url = item.value(forProperty:MPMediaItemPropertyAssetURL) as? NSURL 
    let asset = AVURLAsset(url: url as! URL, options: nil) 

    let formatsKey = "availableMetadataFormats" 
    asset.loadValuesAsynchronously(forKeys: [formatsKey]) { 
     var error: NSError? = nil 
     let status = asset.statusOfValue(forKey: formatsKey, error: &error) 
     if status == .loaded { 
      for format in asset.availableMetadataFormats { 
       let metadata = asset.metadata(forFormat: format) 
       print("format:\(format)") 
       print("metadata description:\(metadata.description)") 
      } 
     } 
    } 
} 
///////// 

key=TDES 및/또는 identifier=id3/TDES

답변

0

에 대한 텍스트/값 OK, 많은 파고 및 질문을 한 후, 여기에 내가 가장 짧은 코드 Podcast를 포함하여 MPMediaItem의 모든/모든 메타 데이터를 루프 할 수 있습니다. 코드 스위프트 3

// Use this function to get and search through all the metadata from an MPMediaItem 
      func getMeta(_ item: MPMediaItem)->String{ 
       let url = item.value(forProperty:MPMediaItemPropertyAssetURL) as? NSURL 
       let asset = AVURLAsset(url: url! as URL, options: nil) 

       var sMetaValue: String = "" 

       // If you want to parse metadata based on a specific format or key space, 
       // uncomment the line below and comment the line 2 below 
       // let metaArray = asset.metadata(forFormat: "org.id3") 
       let metaArray = asset.metadata 
       for metadata in metaArray{ 
        // Uncomment this print to see all the metadata 
        //print("----- metadata:\(metadata)") 
        let sKey = returnKeyString(metadata.identifier!) 
        // See if the returned key matches your intent 
        if (sKey == "tdes"){ 
         if let sVal = metadata.stringValue{ 
          sMetaValue = sVal 
         } 
        } 
       } 
      } 

    // Helper function to parse the identifier - easier than working with keys 
      func returnKeyString(_ inVal: String)->String{ 
       // expecting the metadata for "identifier" as input - returns key value 
       // eg "itsk/ldes" -> "ldes" 
       // or "id3/%00WFD" etc. -> "wfd" 
       var sFinal:String = "" 

       if (inVal.contains("/")){ 
        sFinal = (inVal.components(separatedBy: "/")[1]) 
       } 
       if sFinal.contains("%"){ 
        sFinal = sFinal.components(separatedBy: "%")[1] 
        let index1 = sFinal.index(sFinal.startIndex, offsetBy: 2) 
        sFinal = sFinal.substring(from: index1) 
       } 
       return sFinal.lowercased() 
      }