'Generates and writes ep_obj\'s metadata under the given path with the
given filename root. Uses the episode\'s name with the extension in
_ep_nfo_extension.
ep_obj: TVEpisode object for which to create the metadata
file_name_path: The file name to use for this metadata. Note that the extension
will be automatically added based on _ep_nfo_extension. This should
include an absolute path.
Note that this method expects that _ep_data will return an ElementTree
object. If your _ep_data returns data in another format yo\'ll need to
override this method.'

def write_ep_file(self, ep_obj):

    data = self._ep_data(ep_obj)
    if (not data):
        return False
    nfo_file_path = self.get_episode_file_path(ep_obj)
    nfo_file_dir = os.path.dirname(nfo_file_path)
    try:
        if (not os.path.isdir(nfo_file_dir)):
            sickrage.srCore.srLogger.debug((u"Metadata    dir    didn't    exist,    creating    it    at    " + nfo_file_dir))
            os.makedirs(nfo_file_dir)
            chmodAsParent(nfo_file_dir)
        sickrage.srCore.srLogger.debug((u'Writing    episode    nfo    file    to    ' + nfo_file_path))
        nfo_file = io.open(nfo_file_path, u'wb')
        data.write(nfo_file, encoding=u'UTF-8')
        nfo_file.close()
        chmodAsParent(nfo_file_path)
    except IOError as e:
        sickrage.srCore.srLogger.error(((u'Unable    to    write    file    to    ' + nfo_file_path) + u'    -    are    you    sure    the    folder    is    writable?    {}'.format(e.message)))
        return False
    return True
