]>
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__
))))
9 import xml
.etree
.ElementTree
10 from test
.helper
import get_params
, is_download_test
, try_rm
12 import yt_dlp
.extractor
13 import yt_dlp
.YoutubeDL
16 class YoutubeDL(yt_dlp
.YoutubeDL
):
17 def __init__(self
, *args
, **kwargs
):
18 super().__init
__(*args
, **kwargs
)
19 self
.to_stderr
= self
.to_screen
23 'writeannotations': True,
24 'skip_download': True,
25 'writeinfojson': False,
30 TEST_ID
= 'gr51aVj-mLg'
31 ANNOTATIONS_FILE
= TEST_ID
+ '.annotations.xml'
32 EXPECTED_ANNOTATIONS
= ['Speech bubble', 'Note', 'Title', 'Spotlight', 'Label']
36 class TestAnnotations(unittest
.TestCase
):
41 def test_info_json(self
):
42 expected
= list(EXPECTED_ANNOTATIONS
) # Two annotations could have the same text.
43 ie
= yt_dlp
.extractor
.YoutubeIE()
44 ydl
= YoutubeDL(params
)
45 ydl
.add_info_extractor(ie
)
46 ydl
.download([TEST_ID
])
47 self
.assertTrue(os
.path
.exists(ANNOTATIONS_FILE
))
49 with open(ANNOTATIONS_FILE
, encoding
='utf-8') as annof
:
50 annoxml
= xml
.etree
.ElementTree
.parse(annof
)
51 self
.assertTrue(annoxml
is not None, 'Failed to parse annotations XML')
52 root
= annoxml
.getroot()
53 self
.assertEqual(root
.tag
, 'document')
54 annotationsTag
= root
.find('annotations')
55 self
.assertEqual(annotationsTag
.tag
, 'annotations')
56 annotations
= annotationsTag
.findall('annotation')
58 # Not all the annotations have TEXT children and the annotations are returned unsorted.
60 self
.assertEqual(a
.tag
, 'annotation')
61 if a
.get('type') == 'text':
62 textTag
= a
.find('TEXT')
64 self
.assertTrue(text
in expected
) # assertIn only added in python 2.7
65 # remove the first occurrence, there could be more than one annotation with the same text
67 # We should have seen (and removed) all the expected annotation texts.
68 self
.assertEqual(len(expected
), 0, 'Not all expected annotations were found.')
71 try_rm(ANNOTATIONS_FILE
)
74 if __name__
== '__main__':