def test_dfxp2srt(self):
    dfxp_data = '<?xml version="1.0" encoding="UTF-8"?>\n            <tt xmlns="http://www.w3.org/ns/ttml" xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter">\n            <body>\n                <div xml:lang="en">\n                    <p begin="0" end="1">The following line contains Chinese characters and special symbols</p>\n                    <p begin="1" end="2">第二行<br/>♪♪</p>\n                    <p begin="2" dur="1"><span>Third<br/>Line</span></p>\n                    <p begin="3" end="-1">Lines with invalid timestamps are ignored</p>\n                    <p begin="-1" end="-1">Ignore, two</p>\n                    <p begin="3" dur="-1">Ignored, three</p>\n                </div>\n            </body>\n            </tt>'.encode()
    srt_data = '1\n00:00:00,000 --> 00:00:01,000\nThe following line contains Chinese characters and special symbols\n\n2\n00:00:01,000 --> 00:00:02,000\n第二行\n♪♪\n\n3\n00:00:02,000 --> 00:00:03,000\nThird\nLine\n\n'
    self.assertEqual(dfxp2srt(dfxp_data), srt_data)
    dfxp_data_no_default_namespace = b'<?xml version="1.0" encoding="UTF-8"?>\n            <tt xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter">\n            <body>\n                <div xml:lang="en">\n                    <p begin="0" end="1">The first line</p>\n                </div>\n            </body>\n            </tt>'
    srt_data = '1\n00:00:00,000 --> 00:00:01,000\nThe first line\n\n'
    self.assertEqual(dfxp2srt(dfxp_data_no_default_namespace), srt_data)
    dfxp_data_with_style = b'<?xml version="1.0" encoding="utf-8"?>\n<tt xmlns="http://www.w3.org/2006/10/ttaf1" xmlns:ttp="http://www.w3.org/2006/10/ttaf1#parameter" ttp:timeBase="media" xmlns:tts="http://www.w3.org/2006/10/ttaf1#style" xml:lang="en" xmlns:ttm="http://www.w3.org/2006/10/ttaf1#metadata">\n  <head>\n    <styling>\n      <style id="s2" style="s0" tts:color="cyan" tts:fontWeight="bold" />\n      <style id="s1" style="s0" tts:color="yellow" tts:fontStyle="italic" />\n      <style id="s3" style="s0" tts:color="lime" tts:textDecoration="underline" />\n      <style id="s0" tts:backgroundColor="black" tts:fontStyle="normal" tts:fontSize="16" tts:fontFamily="sansSerif" tts:color="white" />\n    </styling>\n  </head>\n  <body tts:textAlign="center" style="s0">\n    <div>\n      <p begin="00:00:02.08" id="p0" end="00:00:05.84">default style<span tts:color="red">custom style</span></p>\n      <p style="s2" begin="00:00:02.08" id="p0" end="00:00:05.84"><span tts:color="lime">part 1<br /></span><span tts:color="cyan">part 2</span></p>\n      <p style="s3" begin="00:00:05.84" id="p1" end="00:00:09.56">line 3<br />part 3</p>\n      <p style="s1" tts:textDecoration="underline" begin="00:00:09.56" id="p2" end="00:00:12.36"><span style="s2" tts:color="lime">inner<br /> </span>style</p>\n    </div>\n  </body>\n</tt>'
    srt_data = '1\n00:00:02,080 --> 00:00:05,840\n<font color="white" face="sansSerif" size="16">default style<font color="red">custom style</font></font>\n\n2\n00:00:02,080 --> 00:00:05,840\n<b><font color="cyan" face="sansSerif" size="16"><font color="lime">part 1\n</font>part 2</font></b>\n\n3\n00:00:05,840 --> 00:00:09,560\n<u><font color="lime">line 3\npart 3</font></u>\n\n4\n00:00:09,560 --> 00:00:12,360\n<i><u><font color="yellow"><font color="lime">inner\n </font>style</font></u></i>\n\n'
    self.assertEqual(dfxp2srt(dfxp_data_with_style), srt_data)
    dfxp_data_non_utf8 = '<?xml version="1.0" encoding="UTF-16"?>\n            <tt xmlns="http://www.w3.org/ns/ttml" xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter">\n            <body>\n                <div xml:lang="en">\n                    <p begin="0" end="1">Line 1</p>\n                    <p begin="1" end="2">第二行</p>\n                </div>\n            </body>\n            </tt>'.encode('utf-16')
    srt_data = '1\n00:00:00,000 --> 00:00:01,000\nLine 1\n\n2\n00:00:01,000 --> 00:00:02,000\n第二行\n\n'
    self.assertEqual(dfxp2srt(dfxp_data_non_utf8), srt_data)
def test_dfxp2srt(self):
    dfxp_data = '<?xml version="1.0" encoding="UTF-8"?>\n            <tt xmlns="http://www.w3.org/ns/ttml" xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter">\n            <body>\n                <div xml:lang="en">\n                    <p begin="0" end="1">The following line contains Chinese characters and special symbols</p>\n                    <p begin="1" end="2">第二行<br/>♪♪</p>\n                    <p begin="2" dur="1"><span>Third<br/>Line</span></p>\n                    <p begin="3" end="-1">Lines with invalid timestamps are ignored</p>\n                    <p begin="-1" end="-1">Ignore, two</p>\n                    <p begin="3" dur="-1">Ignored, three</p>\n                </div>\n            </body>\n            </tt>'.encode()
    srt_data = '1\n00:00:00,000 --> 00:00:01,000\nThe following line contains Chinese characters and special symbols\n\n2\n00:00:01,000 --> 00:00:02,000\n第二行\n♪♪\n\n3\n00:00:02,000 --> 00:00:03,000\nThird\nLine\n\n'
    self.assertEqual(dfxp2srt(dfxp_data), srt_data)
    dfxp_data_no_default_namespace = b'<?xml version="1.0" encoding="UTF-8"?>\n            <tt xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter">\n            <body>\n                <div xml:lang="en">\n                    <p begin="0" end="1">The first line</p>\n                </div>\n            </body>\n            </tt>'
    srt_data = '1\n00:00:00,000 --> 00:00:01,000\nThe first line\n\n'
    self.assertEqual(dfxp2srt(dfxp_data_no_default_namespace), srt_data)
    dfxp_data_with_style = b'<?xml version="1.0" encoding="utf-8"?>\n<tt xmlns="http://www.w3.org/2006/10/ttaf1" xmlns:ttp="http://www.w3.org/2006/10/ttaf1#parameter" ttp:timeBase="media" xmlns:tts="http://www.w3.org/2006/10/ttaf1#style" xml:lang="en" xmlns:ttm="http://www.w3.org/2006/10/ttaf1#metadata">\n  <head>\n    <styling>\n      <style id="s2" style="s0" tts:color="cyan" tts:fontWeight="bold" />\n      <style id="s1" style="s0" tts:color="yellow" tts:fontStyle="italic" />\n      <style id="s3" style="s0" tts:color="lime" tts:textDecoration="underline" />\n      <style id="s0" tts:backgroundColor="black" tts:fontStyle="normal" tts:fontSize="16" tts:fontFamily="sansSerif" tts:color="white" />\n    </styling>\n  </head>\n  <body tts:textAlign="center" style="s0">\n    <div>\n      <p begin="00:00:02.08" id="p0" end="00:00:05.84">default style<span tts:color="red">custom style</span></p>\n      <p style="s2" begin="00:00:02.08" id="p0" end="00:00:05.84"><span tts:color="lime">part 1<br /></span><span tts:color="cyan">part 2</span></p>\n      <p style="s3" begin="00:00:05.84" id="p1" end="00:00:09.56">line 3<br />part 3</p>\n      <p style="s1" tts:textDecoration="underline" begin="00:00:09.56" id="p2" end="00:00:12.36"><span style="s2" tts:color="lime">inner<br /> </span>style</p>\n    </div>\n  </body>\n</tt>'
    srt_data = '1\n00:00:02,080 --> 00:00:05,840\n<font color="white" face="sansSerif" size="16">default style<font color="red">custom style</font></font>\n\n2\n00:00:02,080 --> 00:00:05,840\n<b><font color="cyan" face="sansSerif" size="16"><font color="lime">part 1\n</font>part 2</font></b>\n\n3\n00:00:05,840 --> 00:00:09,560\n<u><font color="lime">line 3\npart 3</font></u>\n\n4\n00:00:09,560 --> 00:00:12,360\n<i><u><font color="yellow"><font color="lime">inner\n </font>style</font></u></i>\n\n'
    self.assertEqual(dfxp2srt(dfxp_data_with_style), srt_data)
    dfxp_data_non_utf8 = '<?xml version="1.0" encoding="UTF-16"?>\n            <tt xmlns="http://www.w3.org/ns/ttml" xml:lang="en" xmlns:tts="http://www.w3.org/ns/ttml#parameter">\n            <body>\n                <div xml:lang="en">\n                    <p begin="0" end="1">Line 1</p>\n                    <p begin="1" end="2">第二行</p>\n                </div>\n            </body>\n            </tt>'.encode('utf-16')
    srt_data = '1\n00:00:00,000 --> 00:00:01,000\nLine 1\n\n2\n00:00:01,000 --> 00:00:02,000\n第二行\n\n'
    self.assertEqual(dfxp2srt(dfxp_data_non_utf8), srt_data)