Commit f9b825fe by Peter Fogg

Fix failing acceptance tests and allow videos to be imported from XML.

parent 115ae42b
...@@ -9,9 +9,8 @@ def i_see_the_correct_settings_and_values(step): ...@@ -9,9 +9,8 @@ def i_see_the_correct_settings_and_values(step):
world.verify_all_setting_entries([['.75x', 'JMD_ifUUfsU', False], world.verify_all_setting_entries([['.75x', 'JMD_ifUUfsU', False],
['1.25x', 'AKqURZnYqpk', False], ['1.25x', 'AKqURZnYqpk', False],
['1.5x', 'DYpADpL7jAY', False], ['1.5x', 'DYpADpL7jAY', False],
['Display Name', "default", True], ['Display Name', 'default', True],
['External Source', '', False],
['External Track', '', False],
['Normal Speed', 'OEoXaMPEzfM', False], ['Normal Speed', 'OEoXaMPEzfM', False],
['Show Captions', 'True', False], ['Show Captions', 'True', False],
]) ['Source', '', False],
['Track', '', False]])
...@@ -13,8 +13,6 @@ from xblock.core import Integer, Scope, String, Boolean, Float ...@@ -13,8 +13,6 @@ from xblock.core import Integer, Scope, String, Boolean, Float
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
YOUTUBE_SPEEDS = ['.75', '1.0', '1.25', '1.5']
class VideoFields(object): class VideoFields(object):
position = Integer(help="Current position in the video", scope=Scope.user_state, default=0) position = Integer(help="Current position in the video", scope=Scope.user_state, default=0)
...@@ -91,13 +89,7 @@ class VideoModule(VideoFields, XModule): ...@@ -91,13 +89,7 @@ class VideoModule(VideoFields, XModule):
'end': self.end_time 'end': self.end_time
}) })
# TODO: (pfogg) I am highly uncertain about inheriting from
# RawDescriptor for the xml-related methods. This makes LMS unit tests
# pass, but this really shouldn't be a RawDescriptor if users can't
# see raw xml.
# also if it's just return super(...)... then we can just remove these methods, ha
class VideoDescriptor(VideoFields, class VideoDescriptor(VideoFields,
MetadataOnlyEditingDescriptor, MetadataOnlyEditingDescriptor,
RawDescriptor): RawDescriptor):
...@@ -124,42 +116,62 @@ class VideoDescriptor(VideoFields, ...@@ -124,42 +116,62 @@ class VideoDescriptor(VideoFields,
org and course are optional strings that will be used in the generated modules org and course are optional strings that will be used in the generated modules
url identifiers url identifiers
""" """
return super(RawDescriptor, cls).from_xml(xml_data, system, org, course) video = super(RawDescriptor, cls).from_xml(xml_data, system, org, course)
xml = etree.fromstring(xml_data)
def export_to_xml(self, resource_fs): video.display_name = xml.get('display_name')
""" youtube = xml.get('youtube')
Returns an xml string representign this module, and all modules if youtube:
underneath it. May also write required resources out to resource_fs speeds = _parse_youtube(youtube)
if speeds['0.75']:
Assumes that modules have single parentage (that no module appears twice video.youtube_id_0_75 = speeds['0.75']
in the same course), and that it is thus safe to nest modules as xml if speeds['1.00']:
children as appropriate. video.youtube_id_1_0 = speeds['1.00']
if speeds['1.25']:
The returned XML should be able to be parsed back into an identical video.youtube_id_1_25 = speeds['1.25']
XModuleDescriptor using the from_xml method with the same system, org, if speeds['1.50']:
and course video.youtube_id_1_5 = speeds['1.50']
video.show_captions = True if xml.get('show_captions') == 'true' else False
resource_fs is a pyfilesystem object (from the fs package) source = _get_first_external(xml, 'source')
""" if source:
return super(RawDescriptor, self).export_to_xml(resource_fs) video.source = source
# xml = etree.Element('video') tag = _get_first_external(xml, 'tag')
# xml.set('youtube', self.video_list()) if tag:
# xml.set('show_captions', self.show_captions) video.tag = tag
# xml.set('from', self.start_time) start_time = xml.get('from')
# xml.set('to', self.end_time) if start_time:
video.start_time = start_time
# source_tag = etree.SubElement(xml, 'source') end_time = xml.get('to')
# source_tag.set('src', self.source) if end_time:
video.end_time = end_time
# track_tag = etree.SubElement(xml, 'track') return video
# track_tag.set('src', self.track)
# return etree.tostring(xml, pretty_print=True, encoding='utf-8') def _get_first_external(xmltree, tag):
'''
# def video_list(self): Returns the src attribute of the nested `tag` in `xmltree`, if it
# videos = [self.youtube_id_0_75, self.youtube_id_1_0, exists.
# self.youtube_id_1_25, self.youtube_id_1_5] '''
# streams = [':'.join((video, youtube_id)) for element in xmltree.findall(tag):
# for video, youtube_id src = element.get('src')
# in zip(YOUTUBE_SPEEDS, videos)] if src:
# return ','.join(streams) return src
return None
def _parse_youtube(data):
'''
Parses a string of Youtube IDs into a dictionary.
'''
ret = {'0.75': None, '1.00': None, '1.25': None, '1.50': None}
videos = data.split(',')
for video in videos:
pieces = video.split(':')
# HACK
# To elaborate somewhat: in many LMS tests, the keys for
# Youtube IDs are inconsistent. Sometimes a particular
# speed isn't present, and formatting is also inconsistent
# ('1.0' versus '1.00'). So it's necessary to either do
# something like this or update all the tests to work
# properly.
ret['%.2f' % float(pieces[0])] = pieces[1]
return ret
<chapter> <chapter>
<video url_name="toyvideo" youtube="blahblah"/> <video url_name="toyvideo" youtube="1.00:OEoXaMPEzfM"/>
</chapter> </chapter>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment