#
# This file is part of stov, written by Helmut Pozimski 2012-2014.
#
# stov is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# stov is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with stov. If not, see .
# -*- coding: utf8 -*-
from __future__ import unicode_literals
from xml.dom.minidom import parseString
class Parser(object):
def __init__(self, api_result):
self.__api_data = api_result
def parse(self):
"""Take the youtube API data and extract the important entries"""
dom = parseString(self.__api_data)
channel = YtChannel()
i = 0
for title in dom.getElementsByTagName('title'):
xmlTag = title.toxml()
if i == 0:
channel.title = xmlTag.replace('
', '')
channel.title = channel.title.replace('', '')
channel.title = channel.title.replace('&', '&')
channel.title = channel.title.replace('"', '"')
else:
video_title = xmlTag.replace('', '')
video_title = video_title.replace('', '')
video_title = video_title.replace('&', '&')
video_title = video_title.replace('"', '"')
try:
xmlTag = dom.getElementsByTagName('media:\
description')[i-1].toxml()
video_description = xmlTag.replace('',
'')
video_description = video_description.replace('', '')
except IndexError:
video_description = ""
video_id = dom.getElementsByTagName('yt:videoid')[i-1].toxml()
video_id = video_id.replace('', '').replace(
'', '')
channel.videos.append(YtVideo(video_title, video_description,
video_id))
i = i + 1
return channel
class YtChannel(object):
def __init__(self):
self.title = ""
self.videos = []
class YtVideo(object):
def __init__(self, title, description, ytid):
self.title = title
self.description = description
self.ytid = ytid