]>
jfr.im git - yt-dlp.git/blob - test/test_write_annotations.py.disabled
2 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
10 import xml
.etree
.ElementTree
11 from test
.helper
import get_params
, is_download_test
, try_rm
13 import yt_dlp
.extractor
14 import yt_dlp
.YoutubeDL
17 class YoutubeDL(yt_dlp
.YoutubeDL
):
18 def __init__(self
, *args
, **kwargs
):
19 super().__init
__(*args
, **kwargs
)
20 self
.to_stderr
= self
.to_screen
24 'writeannotations': True,
25 'skip_download': True,
26 'writeinfojson': False,
31 TEST_ID
= 'gr51aVj-mLg'
32 ANNOTATIONS_FILE
= TEST_ID
+ '.annotations.xml'
33 EXPECTED_ANNOTATIONS
= ['Speech bubble', 'Note', 'Title', 'Spotlight', 'Label']
37 class TestAnnotations(unittest
.TestCase
):
42 def test_info_json(self
):
43 expected
= list(EXPECTED_ANNOTATIONS
) # Two annotations could have the same text.
44 ie
= yt_dlp
.extractor
.YoutubeIE()
45 ydl
= YoutubeDL(params
)
46 ydl
.add_info_extractor(ie
)
47 ydl
.download([TEST_ID
])
48 self
.assertTrue(os
.path
.exists(ANNOTATIONS_FILE
))
50 with open(ANNOTATIONS_FILE
, encoding
='utf-8') as annof
:
51 annoxml
= xml
.etree
.ElementTree
.parse(annof
)
52 self
.assertTrue(annoxml
is not None, 'Failed to parse annotations XML')
53 root
= annoxml
.getroot()
54 self
.assertEqual(root
.tag
, 'document')
55 annotationsTag
= root
.find('annotations')
56 self
.assertEqual(annotationsTag
.tag
, 'annotations')
57 annotations
= annotationsTag
.findall('annotation')
59 # Not all the annotations have TEXT children and the annotations are returned unsorted.
61 self
.assertEqual(a
.tag
, 'annotation')
62 if a
.get('type') == 'text':
63 textTag
= a
.find('TEXT')
65 self
.assertTrue(text
in expected
) # assertIn only added in python 2.7
66 # remove the first occurrence, there could be more than one annotation with the same text
68 # We should have seen (and removed) all the expected annotation texts.
69 self
.assertEqual(len(expected
), 0, 'Not all expected annotations were found.')
72 try_rm(ANNOTATIONS_FILE
)
75 if __name__
== '__main__':