def __init__(self, filename, parent, item_url, results): """ Initialise the VPVideoItem class """ logger.log( 9, 'VPVideoItem.__init__(filename=%r, parent=%r, item_url=%r, results=%r)', filename, parent, item_url, results) VideoItem.__init__(self, filename, parent) self.item_url = item_url self.results = results
def play(self, arg=None, menuw=None): """ Play this Podcast""" # play the item. isYT = self.vp_url.find('youtube.com') #YouTube podcast isMC = self.vp_url.find('metacafe.com') #Metacafe podcast if isYT != -1: self.download_url = self.youtube(self.vp_url) elif isMC != -1: self.download_url = self.metacafe(self.vp_url) else: self.download_url = self.vp_url if not os.path.exists(self.filename): background = BGDownload(self.download_url, self.filename) background.start() popup = PopupBox(text=_('Buffering podcast...')) popup.show() time.sleep(20) # 20s. buffering time popup.destroy() # call the play funuction of VideoItem VideoItem.play(self, menuw=menuw, arg=arg)
def __init__(self, trailer, parent): VideoItem.__init__(self, trailer.preview_url, parent) self.trailer = trailer self.name = trailer.title self.type = 'video' self.mplayer_options = '-user-agent QuickTime/7.5' self.mode = '' self.files = '' self.image = trailer.poster self.description = trailer.description self.description += _('\n\nGenres: ') + ','.join(trailer.genres) if trailer.release_date: self.description += _( '\n\nDate: ') + trailer.release_date.strftime( config.APPLETRAILERS_DATE_FORMAT) else: self.description += _('\n\nDate: Unknown') if trailer.rating: self.description += ('\n\nRating: ') + trailer.rating if trailer.director: self.description += ('\n\nDirector: ') + trailer.director if trailer.runtime: self.description += ('\n\nRuntime: %d minutes') % trailer.runtime self.plot = self.description
def __init__(self, name, tv, parent): #VideoItem.__init__(self, url, parent) VideoItem.__init__(self, tv[1], parent) self.name = name self.description = 'Stream: ' + tv[2] self.description += '\nInformation: ' + tv[3] self.description += "\nURL: " + tv[1] self.is_playlist = True
def download_play(self, arg=None, menuw=None): pop = PopupBox("Descargando programa") pop.show() video = VideoItem(_fetch_image(arg["flv"]), self) pop.destroy() video.image = _fetch_image(arg["image"]) video.menuw = menuw video.play()
def __init__(self, name, tv, parent): # VideoItem.__init__(self, url, parent) VideoItem.__init__(self, tv[1], parent) self.name = name self.description = "Stream: " + tv[2] self.description += "\nInformation: " + tv[3] self.description += "\nURL: " + tv[1] self.is_playlist = True
def __init__(self, menu_entry, programa, parent): VideoItem.__init__(self, programa["flv"], parent) self.mode = "" self.files = "" self.image = _fetch_image(programa["image"]) if menu_entry == _("Reproducir a pantalla completa (16:9)"): self.mplayer_options = "-vf crop=624:351:0:58" self.name = menu_entry
def __init__(self, menu_entry, programa, parent): VideoItem.__init__(self, programa["flv"], parent) self.mode = '' self.files = '' self.image = _fetch_image(programa['image']) if menu_entry == _("Reproducir a pantalla completa (16:9)"): self.mplayer_options = "-vf crop=624:351:0:58" self.name = menu_entry
class Trailer(VideoItem): def __init__(self, trailer, parent): VideoItem.__init__(self, trailer['url'], parent) self.name = "%(type)s - %(speed)s" % trailer self.trailer = trailer self.type = 'video' def play(self, arg=None, menuw=None, alternateplayer=False): """ Check url before playing """ # Check to see if there's some intermediate file... try: trailerdata = urllib2.urlopen(self.trailer['url']).read(1024) except HTTPError, e: AlertBox("%s %s: %s" % (_("Could not retrieve URL"), self.trailer['url'], e)).show() return if trailerdata.find('<?quicktime type="application/x-quicktime-media-link"?>') > -1: self.set_url(trailerdata.split('src="')[1].split('"')[0]) elif trailerdata.lower().find('<asx') == 0: res = asx_re.search(trailerdata) if res: self.set_url(res.group(1)) elif trailerdata.lower().find('rtsp:') == 0: self.set_url(trailerdata) VideoItem.play(self, arg, menuw, alternateplayer)
class VPVideoItem(VideoItem): """ Video podcast video item """ def __init__(self, filename, parent, item_url, results): """ Initialise the VPVideoItem class """ logger.log( 9, 'VPVideoItem.__init__(filename=%r, parent=%r, item_url=%r, results=%r)', filename, parent, item_url, results) VideoItem.__init__(self, filename, parent) self.item_url = item_url self.results = results def play(self, arg=None, menuw=None): """ Play this Podcast """ download_failed = False self.download_url = self.item_url if not os.path.exists( self.filename) or os.path.getsize(self.filename) < 1024: try: background = BGDownload(self.download_url, self.filename, self.results) background.start() popup = PopupBox(text=_('Fetching "%s"...' % self.name)) popup.show() try: size = 0 for i in range(int(config.VPODCAST_BUFFERING_TIME)): if os.path.exists(self.filename): size = os.stat(self.filename)[stat.ST_SIZE] if size > config.VPODCAST_BUFFERING_SIZE: break time.sleep(1.0) else: if size < config.VPODCAST_BUFFERING_SIZE: download_failed = True finally: popup.destroy() if download_failed: AlertBox(text=_('Fetching "%s" failed\nNo data') % self.filename).show() return except youtube.DownloadError, why: AlertBox(text=_('Fetching "%(filename)s" failed:\n%(why)s') % ({ 'filename': self.filename, 'why': why })).show() return # call the play funuction of VideoItem VideoItem.play(self, menuw=menuw, arg=arg)
def __init__(self, video, id, parent): VideoItem.__init__(self, local_server.get_url('/youtube/%s' % id), parent) self.name = unicode(video.title.text) if video.content.type == "text" and video.content.text: self.description = unicode(video.content.text) elif video.content.type == "html": text = util.htmlenties2txt(unicode(video.content.text), 'unicode') match = re.search('<span>([^\<]*)<', text) if match: self.description = decodeAcute(match.group(1)) else: self.description = text match = re.search('src="([^\"]*)"', text) if match: self.image = match.group(1) else: self.description = "" self.description += '\n' + _('User') + ': ' + video.author[0].name.text date = video.published.text.split('T') self.description += '. ' + date[0] self.plot = self.description
def download_play(self, arg=None, menuw=None): pop = PopupBox("Descargando programa") pop.show() video = VideoItem(_fetch_image(arg['flv']), self) pop.destroy() video.image = _fetch_image(arg['image']) video.menuw = menuw video.play()
def __init__(self, trailer, parent): VideoItem.__init__(self, trailer.preview_url, parent) self.trailer = trailer self.name = trailer.title self.type = 'video' self.mplayer_options = '-user-agent QuickTime/7.5' self.mode = '' self.files = '' self.image = trailer.poster self.description = trailer.description self.description += _('\nGenres: ') + ','.join(trailer.genres) if trailer.release_date: self.description += _('\nDate: ') + trailer.release_date.strftime(config.APPLETRAILERS_DATE_FORMAT) else: self.description += _('\nDate: Unknown') if trailer.rating: self.description += ('\nRating: ') + trailer.rating if trailer.director: self.description += ('\nDirector: ') + trailer.director if trailer.runtime: self.description += ('\nRuntime: %d minutes') % trailer.runtime self.plot = self.description
def __init__(self, name, url, parent): VideoItem.__init__(self, url, parent) self.name = name self.type = 'trailers'
def __init__(self, trailer, parent): VideoItem.__init__(self, trailer['url'], parent) self.name = "%(type)s - %(speed)s" % trailer self.trailer = trailer self.type = 'video'
def __init__(self, name, url, parent): _debug_('YoutubeVideoItem.__init__(name=%r, url=%r, parent=%r)' % (name, url, parent), 2) VideoItem.__init__(self, url, parent) self.name = name self.type = 'youtube'
def cwd(self, arg=None, menuw=None): """ Download the url and create a menu with more links """ txdata = None txheaders = { 'User-Agent': 'freevo %s (%s)' % (config.VERSION, sys.platform), 'Accept-Language': 'en-us', } popup = PopupBox(text=_('Downloading link list...')) popup.show() try: req = urllib2.Request(self.url, txdata, txheaders) response = urllib2.urlopen(req) except: popup.destroy() box = AlertBox(text=_('Failed to download %s') % self.url) box.show() return # base for this url self.base = response.geturl()[:response.geturl().rfind('/') + 1] # normalize the text so that it can be searched all = '' for line in response.read().split('\n'): all += line + ' ' all = all.replace('\r', '').replace('\t', ' ') # find names for links (text between <a>) name_map = {} m = re.compile('href="([^"]*)">([^<]*)</a>', re.I).findall(all) if m: for url, title in m: while title.find(' ') > 0: title = title.replace(' ', ' ') title = util.htmlenties2txt(title.lstrip().rstrip()) name_map[url] = title # now search for links, normal links and movie links together all_urls = [] movie_regexp = re.compile('.*(mov|avi|mpg|asf)$', re.I) for m in (re.compile('href="(.*?)"', re.I).findall(all), re.compile('"(http.[^"]*.(mov|avi|mpg|asf))"', re.I).findall(all)): if m: for url in m: if isinstance(url, tuple): url = url[0] all_urls.append(url) # now split all_urls into link_urls (more links) and # movie_urls (video) link_urls = [] movie_urls = [] if all_urls: for url in all_urls: long_url = self.make_complete_url(response.geturl(), url) # bad url? if not long_url: continue # find a title title = url if name_map.has_key(url): title = name_map[url] else: title = title.replace('.html', '').replace('.php', '') # remove blacklisted urls for b in self.blacklist_regexp: if b(long_url): break else: # movie or link? if movie_regexp.match(long_url): movie_urls.append((long_url, url, title)) else: link_urls.append((long_url, url, title)) items = [] # add all link urls if link_urls: for long, short, title in link_urls: # should all links be displayed? if (not self.all_links) and long.find(self.base) != 0: continue # don't display self if long == self.url: continue # search for duplicate links for l in items: if l.url == long: # increase counter, this link seems to be # important l.counter += 1 break else: # add link as new new l = Link(title, long, self.blacklist_regexp, self.autoplay, self.all_links, self) l.url_name = short l.image = None items.append(l) # sort all items items.sort(lambda l, o: cmp(l.sort().upper(), o.sort().upper())) # add part of the url to the name in case a title is used for # more than one item for l in items: for o in items: if l.name == o.name and l.name.find('(') == -1 and not l == o: # duplicate found, get last part of the url url = l.url[l.url.rfind('/') + 1:] if not url: url = l.url[l.url[:-1].rfind('/') + 1:] if url: l.name = '%s (%s)' % (l.name, url) # same for the other url = o.url[o.url.rfind('/') + 1:] if not url: url = o.url[o.url[:-1].rfind('/') + 1:] if url: o.name = '%s (%s)' % (o.name, url) # now search for movies movies = [] if movie_urls: for long, short, title in movie_urls: # search for duplicate links for l in movies: if l.filename == long: break else: movies.append(VideoItem(long, self, parse=False)) if title.find('/') != -1: title = 'Video: ' + long[long.rfind('/') + 1:] movies[-1].name = title # all done popup.destroy() if len(movies) == 1 and arg == 'autoplay': movies[0].play(menuw=menuw) elif len(movies) == 1 and arg == 'autoplay_max': movies[0].play_max_cache(menuw=menuw) elif items or movies: menuw.pushmenu(menu.Menu(self.name, movies + items))
def __init__(self, name, url, parent): VideoItem.__init__(self, url, parent) self.name = name self.description = "URL: " + url
def __init__(self, name, url, parent): """ Initialise the VPVideoItem class """ self.vp_url = url url = name VideoItem.__init__(self, name, parent)