123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #
- # This file is part of stov, written by Helmut Pozimski in 2012.
- #
- # 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 <http://www.gnu.org/licenses/>.
- # -*- coding: utf8 -*-
- 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('<title>', '').replace('</title>', '')
- channel.title = channel.title.replace('&', '&').replace('"', '"')
- else:
- video_title = xmlTag.replace('<title>', '').replace('</title>', '')
- video_title = video_title.replace('&', '&').replace('"', '"')
- xmlTag = dom.getElementsByTagName('media:description')[i-1].toxml()
- video_description = xmlTag.replace('<media:description type="plain">',
- '').replace('</media:description>', '')
- video_id = dom.getElementsByTagName('yt:videoid')[i-1].toxml()
- video_id = video_id.replace('<yt:videoid>', '').replace('</yt:videoid>',
- '')
- channel.videos.append(YtVideo(video_title, video_description, video_id))
- i = i + 1
- return channel
- class YtChannel(object):
- def __init__(self):
- self.title = u""
- self.videos = []
- class YtVideo(object):
- def __init__(self, title, description, ytid):
- self.title = title
- self.description = description
- self.ytid = ytid
|