当前位置: 首页>>代码示例>>Python>>正文


Python mbxml.parse_message函数代码示例

本文整理汇总了Python中musicbrainzngs.mbxml.parse_message函数的典型用法代码示例。如果您正苦于以下问题:Python parse_message函数的具体用法?Python parse_message怎么用?Python parse_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testTrackLength

    def testTrackLength(self):
        """
        Test that if there is a track length, then `track_or_recording_length` has
        that, but if not then fill the value from the recording length
        """
        fn = os.path.join(self.datadir, "b66ebe6d-a577-4af8-9a2e-a029b2147716-recordings.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]

        # No track length and recording length
        t1 = tracks[0]
        self.assertTrue("length" not in t1)
        self.assertEqual("180000", t1["recording"]["length"])
        self.assertEqual("180000", t1["track_or_recording_length"])

        # Track length and recording length same
        t2 = tracks[1]
        self.assertEqual("279000", t2["length"])
        self.assertEqual("279000", t2["recording"]["length"])
        self.assertEqual("279000", t2["track_or_recording_length"])

        # Track length and recording length different
        t3 = tracks[2]
        self.assertEqual("60000", t3["length"])
        self.assertEqual("80000", t3["recording"]["length"])
        self.assertEqual("60000", t3["track_or_recording_length"])

        # No track lengths
        t4 = tracks[3]
        self.assertTrue("length" not in t4["recording"])
        self.assertTrue("length" not in t4)
        self.assertTrue("track_or_recording_length" not in t4)
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:32,代码来源:test_mbxml_release.py

示例2: testTypesExist

 def testTypesExist(self):
     fn = os.path.join(self.datadir,
                       "f52bc6a1-c848-49e6-85de-f8f53459a624.xml")
     res = mbxml.parse_message(open(fn))["release-group"]
     self.assertTrue("type" in res)
     self.assertTrue("primary-type" in res)
     self.assertTrue("secondary-type-list" in res)
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:7,代码来源:test_mbxml_release_group.py

示例3: testFields

 def testFields(self):
     fn = os.path.join(os.path.dirname(__file__), "data", "search-recording.xml")
     res = mbxml.parse_message(open(fn))
     self.assertEqual(25, len(res["recording-list"]))
     self.assertEqual(1258, res["recording-count"])
     one = res["recording-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:ChrisNolan1992,项目名称:python-musicbrainzngs,代码行数:7,代码来源:test_mbxml_search.py

示例4: testTypesResult

 def testTypesResult(self):
     fn = os.path.join(self.datadir,
                       "f52bc6a1-c848-49e6-85de-f8f53459a624.xml")
     res = mbxml.parse_message(open(fn))["release-group"]
     self.assertEqual("Soundtrack", res["type"])
     self.assertEqual("Album", res["primary-type"])
     self.assertEqual(["Soundtrack"], res["secondary-type-list"])
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:7,代码来源:test_mbxml_release_group.py

示例5: testFields

 def testFields(self):
     fn = os.path.join(os.path.dirname(__file__), "data", "search-label.xml")
     with open(fn) as msg:
         res = mbxml.parse_message(msg)
     self.assertEqual(1, len(res["label-list"]))
     self.assertEqual(1, res["label-count"])
     one = res["label-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:JonnyJD,项目名称:python-musicbrainzngs,代码行数:8,代码来源:test_mbxml_search.py

示例6: testFields

 def testFields(self):
     fn = os.path.join(DATA_DIR, "search-recording.xml")
     with open(fn, 'rb') as msg:
         res = mbxml.parse_message(msg)
     self.assertEqual(25, len(res["recording-list"]))
     self.assertEqual(1258, res["recording-count"])
     one = res["recording-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:alastair,项目名称:python-musicbrainzngs,代码行数:8,代码来源:test_mbxml_search.py

示例7: testFields

 def testFields(self):
     fn = os.path.join(DATA_DIR, "search-work.xml")
     with open(fn) as msg:
         res = mbxml.parse_message(msg)
     self.assertEqual(25, len(res["work-list"]))
     self.assertEqual(174, res["work-count"])
     one = res["work-list"][0]
     self.assertEqual("100", one["ext:score"])
开发者ID:EliotBerriot,项目名称:python-musicbrainzngs,代码行数:8,代码来源:test_mbxml_search.py

示例8: testTrackNumber

    def testTrackNumber(self):
        """
        Test that track number (number or text) and track position (always an increasing number)
        are both read properly
        """
        fn = os.path.join(self.datadir, "212895ca-ee36-439a-a824-d2620cd10461-recordings.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        # This release doesn't number intro tracks as numbered tracks,
        # so position and number get 'out of sync'
        self.assertEqual(['1', '2', '3'], [t["position"] for t in tracks[:3]])
        self.assertEqual(['', '1', '2'], [t["number"] for t in tracks[:3]])

        fn = os.path.join(self.datadir, "a81f3c15-2f36-47c7-9b0f-f684a8b0530f-recordings.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        self.assertEqual(['1', '2'], [t["position"] for t in tracks])
        self.assertEqual(['A', 'B'], [t["number"] for t in tracks])
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:18,代码来源:test_mbxml_release.py

示例9: testFields

 def testFields(self):
     fn = os.path.join(os.path.dirname(__file__), "data", "search-artist.xml")
     res = mbxml.parse_message(open(fn))
     self.assertEqual(25, len(res["artist-list"]))
     one = res["artist-list"][0]
     self.assertEqual(9, len(one.keys()))
     # Score is a key that is only in search results -
     # so check for it here
     self.assertEqual("100", one["ext:score"])
开发者ID:krbaker,项目名称:python-musicbrainz-ngs,代码行数:9,代码来源:test_mbxml_search.py

示例10: testArtistAliases

    def testArtistAliases(self):
        fn = os.path.join(self.datadir, "0e43fe9d-c472-4b62-be9e-55f971a023e1-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["artist"]["alias-list"]
        self.assertEqual(len(aliases), 28)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "Prokofief")
        self.assertEqual(a0["sort-name"], "Prokofief")

        a17 = aliases[17]
        self.assertEqual(a17["alias"], "Sergei Sergeyevich Prokofiev")
        self.assertEqual(a17["sort-name"], "Prokofiev, Sergei Sergeyevich")
        self.assertEqual(a17["locale"], "en")
        self.assertEqual(a17["primary"], "primary")

        fn = os.path.join(self.datadir, "2736bad5-6280-4c8f-92c8-27a5e63bbab2-aliases.xml")
        res = mbxml.parse_message(open(fn))
        self.assertFalse("alias-list" in res["artist"])
开发者ID:sampsyo,项目名称:python-musicbrainz-ngs,代码行数:19,代码来源:test_mbxml_artist.py

示例11: mb_parser_xml

def mb_parser_xml(resp):
    """Return a Python dict representing the XML response"""
    # Parse the response.
    try:
        return mbxml.parse_message(resp)
    except UnicodeError as exc:
        raise ResponseError(cause=exc)
    except Exception as exc:
        if isinstance(exc, ETREE_EXCEPTIONS):
            raise ResponseError(cause=exc)
        else:
            raise
开发者ID:mojie126,项目名称:mythtv,代码行数:12,代码来源:musicbrainz.py

示例12: testWorkAliases

    def testWorkAliases(self):
        fn = os.path.join(self.datadir, "80737426-8ef3-3a9c-a3a6-9507afb93e93-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["work"]["alias-list"]
        self.assertEqual(len(aliases), 2)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], 'Symphonie Nr. 3 Es-Dur, Op. 55 "Eroica"')
        self.assertEqual(a0["sort-name"], 'Symphonie Nr. 3 Es-Dur, Op. 55 "Eroica"')

        a1 = aliases[1]
        self.assertEqual(a1["alias"], 'Symphony No. 3, Op. 55 "Eroica"')
        self.assertEqual(a1["sort-name"], 'Symphony No. 3, Op. 55 "Eroica"')

        fn = os.path.join(self.datadir, "3d7c7cd2-da79-37f4-98b8-ccfb1a4ac6c4-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["work"]["alias-list"]
        self.assertEqual(len(aliases), 10)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "Adagio from Symphony No. 2 in E minor, Op. 27")
        self.assertEqual(a0["sort-name"], "Adagio from Symphony No. 2 in E minor, Op. 27")
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:22,代码来源:test_mbxml_work.py

示例13: testArtistCredit

    def testArtistCredit(self):
        """
        If the artist credit is the same in the track and recording, make sure that
        the information is replicated in both objects, otherwise have distinct ones.
        """

        # If no artist-credit in the track, copy in the recording one
        fn = os.path.join(self.datadir, "833d4c3a-2635-4b7a-83c4-4e560588f23a-recordings+artist-credits.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        t1 = tracks[1]
        self.assertEqual(t1["artist-credit"], t1["recording"]["artist-credit"])
        self.assertEqual("JT Bruce", t1["artist-credit-phrase"])
        self.assertEqual(t1["recording"]["artist-credit-phrase"], t1["artist-credit-phrase"])

        # Recording AC is different to track AC
        fn = os.path.join(self.datadir, "fbe4490e-e366-4da2-a37a-82162d2f41a9-recordings+artist-credits.xml")
        res = mbxml.parse_message(open(fn))
        tracks = res["release"]["medium-list"][0]["track-list"]
        t1 = tracks[1]
        self.assertNotEqual(t1["artist-credit"], t1["recording"]["artist-credit"])
        self.assertEqual("H. Lichner", t1["artist-credit-phrase"])
        self.assertNotEqual(t1["recording"]["artist-credit-phrase"], t1["artist-credit-phrase"])
开发者ID:TestingCI,项目名称:python-musicbrainzngs,代码行数:23,代码来源:test_mbxml_release.py

示例14: testLabelAliases

    def testLabelAliases(self):
        fn = os.path.join(self.datadir, "022fe361-596c-43a0-8e22-bad712bb9548-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["label"]["alias-list"]
        self.assertEqual(len(aliases), 4)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "EMI")
        self.assertEqual(a0["sort-name"], "EMI")

        a1 = aliases[1]
        self.assertEqual(a1["alias"], "EMI Records (UK)")
        self.assertEqual(a1["sort-name"], "EMI Records (UK)")

        fn = os.path.join(self.datadir, "e72fabf2-74a3-4444-a9a5-316296cbfc8d-aliases.xml")
        res = mbxml.parse_message(open(fn))
        aliases = res["label"]["alias-list"]
        self.assertEqual(len(aliases), 1)

        a0 = aliases[0]
        self.assertEqual(a0["alias"], "Ki/oon Records Inc.")
        self.assertEqual(a0["sort-name"], "Ki/oon Records Inc.")
        self.assertEqual(a0["begin-date"], "2001-10")
        self.assertEqual(a0["end-date"], "2012-04")
开发者ID:sampsyo,项目名称:python-musicbrainz-ngs,代码行数:24,代码来源:test_mbxml_label.py

示例15: getMetaData

    def getMetaData(self, releaseId):
        """Load metadata from disk"""
        xmlPath = self._get_xml_path(releaseId)
        if (not os.path.isfile(xmlPath)):
            logging.error("No XML metadata for %s", releaseId)
            return None
        with open(xmlPath, 'r') as xmlf:
            metaxml = xmlf.read()

        try:
            metadata = mbxml.parse_message(metaxml)
        except UnicodeError as exc:
            raise ResponseError(cause=exc)
        except Exception as exc:
            if isinstance(exc, ETREE_EXCEPTIONS):
                logging.error("Got some bad XML for %s!", releaseId)
                return 
            else:
                raise

        return metadata
开发者ID:JonnyJD,项目名称:musicbrainz-catalog,代码行数:21,代码来源:catalog.py


注:本文中的musicbrainzngs.mbxml.parse_message函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。