def get_videos(self, video_id): data = self._get_video_info(video_id) try: items = [util.struct(self._get_video_info(video['id'])) for video in data['children']] except KeyError: items = [util.struct(data)] return items
def get_videos(self, video_id): data = self._get_video_info(video_id) if 'children' in data: items = [util.struct(self._get_video_info(video['id'])) for video in data.get('children')] return items else: return [util.struct(data)]
def get_gplay_episodes(channel, show, page): videos = [] properties = ('id', 'title', 'plot', 'duration', 'date', 'mpaa', 'thumb') prop_data = ('id_globo_videos', 'title', 'description', 'duration_in_milliseconds', 'exhibition_date', 'content_rating', 'thumb_image') (show_id, show_kind) = show.split('/') if show_kind != 'shows': properties += ('episode', 'season', 'tvshowtitle') prop_data += ('number', 'season', 'program') headers = {'Authorization': GLOBOSAT_API_AUTHORIZATION} apiurl = GLOBOSAT_API_SHOWS if show_kind == 'shows' else GLOBOSAT_API_EPISODES data = get_page(apiurl % (int(show_id), page), headers=headers) results = data['results'] if 'results' in data else [data] for item in results: video = util.struct( dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date[:10], '%Y-%m-%d') video.mpaa = util.getMPAAFromCI(video.mpaa) video.tvshowtitle = video.tvshowtitle[ 'title'] if video.tvshowtitle else None video.season = video.season['number'] if video.season else None video.duration = int(video.duration / 1000) videos.append(video) page = (page + 1 if 'next' in data else None) return videos, page
def get_globo_episodes(channel, show, page): videos = [] properties = ('id', 'title', 'plot', 'duration', 'date') prop_data = ('id', 'title', 'description', 'duration', 'exhibited') days = get_page(GLOBOPLAT_DAYS % int(show))['days'] video_page_size = 10 size_videos = 10 page_num = 1 while size_videos >= video_page_size: try: data = get_page(GLOBOPLAY_VIDEOS % (int(show), days[page - 1], page_num)) size_videos = len(data['videos']) for item in data['videos']: video = util.struct( dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date, '%Y-%m-%d') video.duration = sum( int(x) * 60**i for i, x in enumerate(reversed(video.duration.split(':')))) # video.duration = video.duration.split(':')[0] video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) page_num += 1 except: break page = (page + 1 if page < len(days) else None) return videos, page
def get_globo_episodes(channel, show, page): page_size = 1 videos = [] properties = ('id', 'title', 'plot', 'duration', 'date') prop_data = ('id', 'title', 'description', 'duration', 'exhibited') days = get_page(GLOBOPLAT_DAYS % int(show))['days'] for i in range((page-1)*page_size, page*page_size) : for page_num in range (1, 5) : try: data = get_page(GLOBOPLAY_VIDEOS % (int(show), days[i], page_num)) for item in data['videos']: video = util.struct(dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date, '%Y-%m-%d') video.duration = sum(int(x) * 60 ** i for i, x in enumerate(reversed(video.duration.split(':')))) # video.duration = video.duration.split(':')[0] video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) except: break page_num = page_num + 1 page = (page+1 if (page*page_size) < len(days) else None) return videos, page
def get_episodes(self, channel, show, page): # page_size = int(self.plugin.get_setting('page_size') or 10) self.plugin.log.debug('getting episodes for %s/%s, page %s' % (channel, show, page)) # define scraper method method_strs = { 'megapix': 'get_megapix_episodes', 'globo':'get_globo_episodes', } method = method_strs.get(channel) or 'get_gplay_episodes' episodes, next = getattr(scraper, method)(channel, show, page) return util.struct({'list': episodes, 'next': next})
def get_episodes(self, channel, show, page): # page_size = int(self.plugin.get_setting('page_size') or 10) self.plugin.log.debug('getting episodes for %s/%s, page %s' % (channel, show, page)) # define scraper method method_strs = { 'megapix': 'get_megapix_episodes', 'telecine': 'get_megapix_episodes', 'globo':'get_globo_episodes', } method = method_strs.get(channel) or 'get_gplay_episodes' episodes, next = getattr(scraper, method)(channel, show, page) return util.struct({'list': episodes, 'next': next})
def get_rail_videos(self, **kwargs): video_count = last_count = 0 videos = util.struct() videos.list = [] videos.next = 1 while video_count < int(self.plugin.get_setting('page_size') or 15): data = requests.get(RAIL_URL % kwargs).text # match video 'rail's # match: (title, video_id, date [DD/MM/AAAA], # thumb, duration [MM:SS], plot) regExp = ( r'<li.*data-video-title="(.+?)"[\s]+data-video-id="(.+?)"[\s]+' + r'data-video-data-exibicao="(.+?)">[\s\S]+?' + r'<img.+src="(.+?)"[\s\S]+?' + r'<span class="duracao.*?">(.+?)</span>[\s\S]+?' + r'div class="balao">[\s]+?<p>[\s]+?([\w].+?)[\s]+?</p>' ) matches = re.compile(regExp).findall(data) mcount = len(matches) properties = ('title', 'id', 'date', 'thumb', 'duration', 'plot') for item in matches: video = util.struct(dict(zip(properties, item))) # update attrs video.title = util.unescape(video.title) video.plot = util.unescape(video.plot) video.date = video.date.replace('/', '.') _split = video.duration.split(':') video.duration = sum(int(x) * 60 ** i for i, x in enumerate(reversed(_split))) self.cache.set('video|%s' % video.id, repr(video)) videos.list.append(video) if mcount == 0 or mcount < last_count: videos.next = None break video_count += mcount last_count = mcount kwargs['page'] += 1 if videos.next: videos.next = kwargs['page'] return videos
def get_rail_videos(self, **kwargs): video_count = last_count = 0 videos = util.struct() videos.list = [] videos.next = 1 while video_count < int(self.plugin.get_setting('page_size') or 15): data = requests.get(RAIL_URL % kwargs).text # match video 'rail's # match: (title, video_id, date [DD/MM/AAAA], # thumb, duration [MM:SS], plot) regExp = ( '<li.*data-video-title="(.+?)"[\s]+data-video-id="(.+?)"[\s]+' + 'data-video-data-exibicao="(.+?)">[\s\S]+?' + '<img.+src="(.+?)"[\s\S]+?' + '<span class="duracao.*?">(.+?)</span>[\s\S]+?' + 'div class="balao">[\s]+?<p>[\s]+?([\w].+?)[\s]+?</p>' ) matches = re.compile(regExp).findall(data) mcount = len(matches) properties = ('title', 'id', 'date', 'thumb', 'duration', 'plot') for item in matches: video = util.struct(dict(zip(properties, item))) # update attrs video.title = util.unescape(video.title) video.plot = util.unescape(video.plot) video.date = video.date.replace('/', '.') _split = video.duration.split(':') video.duration = sum(int(x) * 60 ** i for i, x in enumerate(reversed(_split))) self.cache.set('video|%s' % video.id, repr(video)) videos.list.append(video) if mcount == 0 or mcount < last_count: videos.next = None break video_count += mcount last_count = mcount kwargs['page'] += 1 if videos.next: videos.next = kwargs['page'] return videos
def get_gplay_episodes(channel, show, page): videos = [] properties = ('id', 'title', 'plot', 'duration', 'date', 'episode', 'season', 'mpaa', 'tvshowtitle', 'thumb') prop_data = ('id_globo_videos', 'title', 'description', 'duration_in_milliseconds', 'exhibition_date', 'number', 'season', 'content_rating', 'program', 'thumb_image') headers = {'Authorization': GLOBOSAT_API_AUTHORIZATION} data = get_page(GLOBOSAT_API_EPISODES % (int(show), page), headers=headers) for item in data['results']: video = util.struct(dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date[:10], '%Y-%m-%d') video.mpaa = util.getMPAAFromCI(video.mpaa) video.tvshowtitle = video.tvshowtitle['title'] video.season = video.season['number'] if video.season else None video.duration = int(video.duration/1000) videos.append(video) page = (page+1 if data['next'] else None) return videos, page
def get_gplay_episodes(channel, show, page): # page_size = 15 # import pydevd; pydevd.settrace() videos = [] properties = ('id', 'title', 'plot', 'duration', 'date') prop_data = ('id', 'titulo', 'descricao', 'duracao_original', 'data_exibicao') data = get_page(GLOBOSAT_EPS_JSON % ('%s/%s' % (channel, show), page)) for item in data['resultado']: video = util.struct(dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date[:10], '%Y-%m-%d') video.duration = int(video.duration/1000) video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) page = (page+1 if page < data['total_paginas'] else None) return videos, page
def get_megapix_episodes(channel, show, page): page_size = 20 MEGAPIX_EPS_JSON = 'http://globosatplay.globo.com/%s/generos/%s/videos/pagina/%s.json' videos = [] properties = ('id', 'title', 'icon', 'plot', 'duration', 'date') prop_data = ('id', 'titulo', 'poster') data = get_page(MEGAPIX_EPS_JSON % (channel, show, page)) for item in data: video = util.struct( dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = '2014-01-01' # video.duration = int(video.duration/1000) video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) page = (page + 1 if len(videos) == page_size else None) return videos, page
def get_megapix_episodes(channel, show, page): page_size = 20 MEGAPIX_EPS_JSON = 'http://globosatplay.globo.com/%s/generos/%s/videos/pagina/%s.json' videos = [] properties = ('id', 'title', 'icon', 'plot', 'duration', 'date') prop_data = ('id', 'titulo', 'poster') data = get_page( MEGAPIX_EPS_JSON % (channel, show, page) ) for item in data: video = util.struct(dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = '2014-01-01' # video.duration = int(video.duration/1000) video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) page = (page+1 if len(videos) == page_size else None) return videos, page
def get_gplay_episodes(channel, show, page): videos = [] properties = ('id', 'title', 'plot', 'duration', 'date', 'episode', 'season', 'mpaa', 'tvshowtitle') prop_data = ('id', 'titulo', 'descricao', 'duracao_original', 'data_exibicao', 'episodio', 'temporada', 'classificacao_indicativa', 'programa') data = get_page(GLOBOSAT_EPS_JSON % ('%s/%s' % (channel, show), page)) for item in data['resultado']: video = util.struct(dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date[:10], '%Y-%m-%d') video.mpaa = util.getMPAAFromCI(video.mpaa) video.tvshowtitle = video.tvshowtitle['titulo'] video.duration = int(video.duration/1000) video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) page = (page+1 if page < data['total_paginas'] else None) return videos, page
def get_gplay_episodes(channel, show, page): # page_size = 15 # import pydevd; pydevd.settrace() videos = [] properties = ('id', 'title', 'plot', 'duration', 'date') prop_data = ('id', 'titulo', 'descricao', 'duracao_original', 'data_exibicao') data = get_page(GLOBOSAT_EPS_JSON % ('%s/%s' % (channel, show), page)) for item in data['resultado']: video = util.struct( dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date[:10], '%Y-%m-%d') video.duration = int(video.duration / 1000) video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) page = (page + 1 if page < data['total_paginas'] else None) return videos, page
def get_globo_episodes(channel, show, page): # page_size = 10 videos = [] properties = ('id', 'title', 'plot', 'duration', 'date') prop_data = ('id', 'titulo', 'descricao', 'duracao', 'exibicao') data = get_page(GLOBOTV_EPS_JSON % (show, page)) for item in data: try: video = util.struct(dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date, '%d/%m/%Y') video.duration = sum(int(x) * 60 ** i for i, x in enumerate(reversed(video.duration.split(':')))) # video.duration = video.duration.split(':')[0] video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) except: break page = (page+1 if len(data) == 10 else None) return videos, page
def get_globo_episodes(channel, show, page): # page_size = 10 videos = [] properties = ('id', 'title', 'plot', 'duration', 'date') prop_data = ('id', 'titulo', 'descricao', 'duracao', 'exibicao') data = get_page(GLOBOTV_EPS_JSON % (show, page)) for item in data: try: video = util.struct( dict(zip(properties, [item.get(p) for p in prop_data]))) # update attrs video.date = util.time_format(video.date, '%d/%m/%Y') video.duration = sum( int(x) * 60**i for i, x in enumerate(reversed(video.duration.split(':')))) # video.duration = video.duration.split(':')[0] video.thumb = EPSTHUMB_URL % video.id # self.cache.set('video|%s' % video.id, repr(video)) videos.append(video) except: break page = (page + 1 if len(data) == 10 else None) return videos, page
def initActions(self): def menu(title, actions=None): menu = self.menuBar().addMenu(title) if actions: util.addActions(menu, actions) return menu action = partial(util.newAction, self) shortcuts = self.config["shortcut"] turn_prev = action( self.tr("&上一张"), partial(self.turnImg, -1), shortcuts["turn_prev"], "Prev", self.tr("翻到上一张图片"), ) turn_next = action( self.tr("&下一张"), partial(self.turnImg, 1), shortcuts["turn_next"], "Next", self.tr("翻到下一张图片"), ) open_image = action( self.tr("&打开图像"), self.openImage, shortcuts["open_image"], "OpenImage", self.tr("打开一张图像进行标注"), ) open_folder = action( self.tr("&打开文件夹"), self.openFolder, shortcuts["open_folder"], "OpenFolder", self.tr("打开一个文件夹下所有的图像进行标注"), ) change_output_dir = action( self.tr("&改变标签保存路径"), self.changeOutputDir, shortcuts["change_output_dir"], "ChangeLabelPath", self.tr("打开一个文件夹下所有的图像进行标注"), ) load_param = action( self.tr("&加载模型参数"), self.changeParam, shortcuts["load_param"], "Model", self.tr("加载一个模型参数"), ) finish_object = action( self.tr("&完成当前目标"), self.finishObject, shortcuts["finish_object"], "Ok", self.tr("完成当前目标的标注"), ) clear = action( self.tr("&清除所有标注"), self.undoAll, shortcuts["clear"], "Clear", self.tr("清除所有标注信息"), ) undo = action( self.tr("&撤销"), self.undoClick, shortcuts["undo"], "Undo", self.tr("撤销一次点击"), ) redo = action( self.tr("&重做"), self.redoClick, shortcuts["redo"], "Redo", self.tr("重做一次点击"), ) save = action( self.tr("&保存"), self.saveLabel, "", "Save", self.tr("保存图像标签"), ) save_as = action( self.tr("&另存为"), partial(self.saveLabel, True), "", "OtherSave", self.tr("指定标签保存路径"), ) auto_save = action( self.tr("&自动保存"), self.toggleAutoSave, "", "AutoSave", self.tr("翻页同时自动保存"), checkable=True, ) quit = action( self.tr("&退出"), self.close, "", "Close", self.tr("退出软件"), ) save_label = action( self.tr("&保存标签列表"), self.saveLabelList, "", "ExportLabel", self.tr("将标签保存成标签配置文件"), ) load_label = action( self.tr("&加载标签列表"), self.loadLabelList, "", "ImportLabel", self.tr("从标签配置文件中加载标签"), ) clear_label = action( self.tr("&清空标签列表"), self.clearLabelList, "", "ClearLabel", self.tr("清空所有的标签"), ) clear_recent = action( self.tr("&清除标注记录"), self.clearRecentFile, "", "ClearRecent", self.tr("清除近期标注记录"), ) recent_files = QtWidgets.QMenu(self.tr("近期文件")) recent_files.aboutToShow.connect(self.updateRecentFile) recent_params = QtWidgets.QMenu(self.tr("近期模型及参数")) recent_params.aboutToShow.connect(self.updateModelsMenu) self.actions = util.struct( auto_save=auto_save, recent_files=recent_files, recent_params=recent_params, fileMenu=( open_image, open_folder, change_output_dir, load_param, clear_recent, recent_files, recent_params, None, save, save_as, auto_save, None, turn_next, turn_prev, None, quit, ), labelMenu=( save_label, load_label, clear_label, ), toolBar=( finish_object, clear, undo, redo, turn_prev, turn_next, ), ) menu("文件", self.actions.fileMenu) menu("标注", self.actions.labelMenu) util.addActions(self.toolBar, self.actions.toolBar)