1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #
- # This file is part of stov, written by Helmut Pozimski 2012-2013.
- #
- # 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 __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('<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 = ""
- self.videos = []
- class YtVideo(object):
- def __init__(self, title, description, ytid):
- self.title = title
- self.description = description
- self.ytid = ytid
|