def get(self, type_=''): if not os.path.exists(DB_PATH): self.write('BGmi db file not found.') self.finish() return data = Followed.get_all_followed(STATUS_NORMAL, STATUS_UPDATING, order='followed.updated_time', desc=True) followed = list(map(lambda b: b['bangumi_name'], data)) followed.extend(list(map(lambda b: b['bangumi_name'], self.patch_list))) data = Followed.get_all_followed(STATUS_NORMAL, STATUS_UPDATING if not type_ == 'old' else STATUS_END, order='followed.updated_time', desc=True) if type_ == 'index': data.extend(self.patch_list) data.sort(key=lambda _: _['updated_time'] if _['updated_time'] else 1) data.reverse() for item in data: item['player'] = get_player(item['bangumi_name']) self.write(self.jsonify(data)) self.finish()
def get(self): is_json = self.get_argument('json', False) is_old = self.get_argument('old', False) if not os.path.exists(DB_PATH): self.write('BGmi db file not found.') self.finish() return data = Followed.get_all_followed(STATUS_NORMAL, STATUS_UPDATING, order='followed.updated_time', desc=True) followed = map(lambda b: b['bangumi_name'], data) data = Followed.get_all_followed(STATUS_NORMAL, STATUS_UPDATING if not is_old else STATUS_END, order='followed.updated_time', desc=True) calendar = Bangumi.get_all_bangumi() def shift(seq, n): n %= len(seq) return seq[n:] + seq[:n] weekday_order = shift(WEEK, datetime.datetime.today().weekday()) cal_ordered = OrderedDict() for week in weekday_order: cal_ordered[week] = calendar[week.lower()] if is_json: self.write(json.dumps(cal_ordered)) self.finish() else: self.render('templates/bangumi.html', data=data, cal=cal_ordered, followed=list(followed), version=__version__)
def update(ret): print_info('marking bangumi status ...') now = int(time.time()) for i in Followed.get_all_followed(): if i['updated_time'] and int(i['updated_time'] + 86400) < now: followed_obj = Followed(bangumi_name=i['bangumi_name']) followed_obj.status = STATUS_FOLLOWED followed_obj.save() print_info('updating bangumi data ...') fetch(save=True, group_by_weekday=False) print_info('updating subscriptions ...') download_queue = [] if ret.action.update.name is None: updated_bangumi_obj = Followed.get_all_followed() else: updated_bangumi_obj = [] for i in ret.action.update.name: f = Followed(bangumi_name=i) f.select_obj() updated_bangumi_obj.append(f) for subscribe in updated_bangumi_obj: print_info('fetching %s ...' % subscribe['bangumi_name']) bangumi_obj = Bangumi(name=subscribe['bangumi_name']) bangumi_obj.select_obj() # filter by subtitle group if not bangumi_obj: print_error( 'The bangumi {0} you subscribed does not exists ..'.format( subscribe['bangumi_name']), exit_=False) continue episode, all_episode_data = get_maximum_episode(bangumi=bangumi_obj) if episode.get('episode') > subscribe['episode']: episode_range = range(subscribe['episode'] + 1, episode.get('episode')) print_success('%s updated, episode: %d' % (subscribe['bangumi_name'], episode['episode'])) _ = Followed(bangumi_name=subscribe['bangumi_name']) _.episode = episode['episode'] _.status = STATUS_UPDATED _.updated_time = int(time.time()) _.save() download_queue.append(episode) for i in episode_range: for epi in all_episode_data: if epi['episode'] == i: download_queue.append(epi) break if ret.action.update and ret.action.update.download: download_prepare(download_queue) print_info('Re-downloading ...') download_prepare( Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD))
def get(self): type_ = self.get_argument('type', 0) cal = Calendar() cal.add('prodid', '-//BGmi Followed Bangumi Calendar//bangumi.ricterz.me//') cal.add('version', '2.0') data = Followed.get_all_followed() data.extend(self.patch_list) if type_ == 0: bangumi = defaultdict(list) [ bangumi[Bangumi.week.index(i['update_time']) + 1].append( i['bangumi_name']) for i in data ] weekday = datetime.datetime.now().weekday() for i, k in enumerate(range(weekday, weekday + 7)): if k % 7 in bangumi: for v in bangumi[k % 7]: event = Event() event.add('summary', v) event.add( 'dtstart', datetime.datetime.now().date() + datetime.timedelta(i - 1)) event.add( 'dtend', datetime.datetime.now().date() + datetime.timedelta(i - 1)) cal.add_component(event) else: data = [bangumi for bangumi in data if bangumi['status'] == 2] for bangumi in data: event = Event() event.add('summary', 'Updated: {}'.format(bangumi['bangumi_name'])) event.add('dtstart', datetime.datetime.now().date()) event.add('dtend', datetime.datetime.now().date()) cal.add_component(event) cal.add('name', 'Bangumi Calendar') cal.add('X-WR-CALNAM', 'Bangumi Calendar') cal.add('description', 'Followed Bangumi Calendar') cal.add('X-WR-CALDESC', 'Followed Bangumi Calendar') self.write(cal.to_ical()) self.finish()
def get(self, type_=''): data = Followed.get_all_followed( STATUS_NORMAL, STATUS_UPDATING if not type_ == 'old' else STATUS_END) if type_ == 'index': data.extend(self.patch_list) data.sort( key=lambda _: _['updated_time'] if _['updated_time'] else 1) for bangumi in data: bangumi['cover'] = '{}/{}'.format(COVER_URL, normalize_path(bangumi['cover'])) data.reverse() for item in data: item['player'] = get_player(item['bangumi_name']) self.write(self.jsonify(data)) self.finish()
def get(self): data = Followed.get_all_followed(STATUS_NORMAL, STATUS_UPDATING, order='followed.updated_time', desc=True) bangumi = defaultdict(list) [ bangumi[Bangumi.week.index(i['update_time']) + 1].append( i['bangumi_name']) for i in data ] cal = Calendar() cal.add('prodid', '-//BGmi Followed Bangumi Calendar//bangumi.ricterz.me//') cal.add('version', '2.0') weekday = datetime.datetime.now().weekday() for i, k in enumerate(range(weekday, weekday + 7)): if k % 7 in bangumi: event = Event() v = bangumi[k % 7] event.add('summary', ', '.join(v)) event.add( 'dtstart', datetime.datetime.now().date() + datetime.timedelta(i)) event.add( 'dtend', datetime.datetime.now().date() + datetime.timedelta(i)) cal.add_component(event) cal.add('name', 'Bangumi Calendar') cal.add('X-WR-CALNAM', 'Bangumi Calendar') cal.add('description', 'Followed Bangumi Calendar') cal.add('X-WR-CALDESC', 'Followed Bangumi Calendar') self.write(cal.to_ical()) self.finish()
def update(ret): ignore = False if ret.not_ignore else True print_info('marking bangumi status ...') now = int(time.time()) for i in Followed.get_all_followed(): if i['updated_time'] and int(i['updated_time'] + 86400) < now: followed_obj = Followed(bangumi_name=i['bangumi_name']) followed_obj.status = STATUS_FOLLOWED followed_obj.save() print_info('updating bangumi data ...') fetch(save=True, group_by_weekday=False) print_info('updating subscriptions ...') download_queue = [] if ret.download: if not ret.name: print_warning('No specified bangumi, ignore `--download` option') if len(ret.name) > 1: print_warning( 'Multiple specified bangumi, ignore `--download` option') if not ret.name: updated_bangumi_obj = Followed.get_all_followed() else: updated_bangumi_obj = [] for i in ret.name: f = Followed(bangumi_name=i) f.select_obj() updated_bangumi_obj.append(f) for subscribe in updated_bangumi_obj: print_info('fetching %s ...' % subscribe['bangumi_name']) bangumi_obj = Bangumi(name=subscribe['bangumi_name']) bangumi_obj.select_obj() followed_obj = Followed(bangumi_name=subscribe['bangumi_name']) followed_obj.select_obj() # filter by subtitle group if not bangumi_obj or not followed_obj: print_error( 'Bangumi<{0}> does not exist or not been followed.'.format( subscribe['bangumi_name']), exit_=False) continue episode, all_episode_data = get_maximum_episode(bangumi=bangumi_obj, ignore_old_row=ignore, max_page=1) if (episode.get('episode') > subscribe['episode']) or (len( ret.name) == 1 and ret.download): if len(ret.name) == 1 and ret.download: episode_range = ret.download else: episode_range = range(subscribe['episode'] + 1, episode.get('episode', 0) + 1) print_success('%s updated, episode: %d' % (subscribe['bangumi_name'], episode['episode'])) followed_obj.episode = episode['episode'] followed_obj.status = STATUS_UPDATED followed_obj.updated_time = int(time.time()) followed_obj.save() for i in episode_range: for epi in all_episode_data: if epi['episode'] == i: download_queue.append(epi) break if ret.download is not None: download_prepare(download_queue) print_info('Re-downloading ...') download_prepare( Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD))
def update(name, download=None, not_ignore=False): result = { 'status': 'info', 'message': '', 'data': { 'updated': [], 'downloaded': [] } } ignore = not bool(not_ignore) print_info('marking bangumi status ...') now = int(time.time()) for i in Followed.get_all_followed(): if i['updated_time'] and int(i['updated_time'] + 86400) < now: followed_obj = Followed.get(bangumi_name=i['bangumi_name']) followed_obj.status = STATUS_FOLLOWED followed_obj.save() for script in ScriptRunner().scripts: obj = script.Model().obj if obj.updated_time and int(obj.updated_time + 86400) < now: obj.status = STATUS_FOLLOWED obj.save() print_info('updating bangumi data ...') website.fetch(save=True, group_by_weekday=False) print_info('updating subscriptions ...') download_queue = [] if download: if not name: print_warning('No specified bangumi, ignore `--download` option') if len(name) > 1: print_warning( 'Multiple specified bangumi, ignore `--download` option') if not name: updated_bangumi_obj = Followed.get_all_followed() else: updated_bangumi_obj = [] for i in name: try: f = Followed.get(bangumi_name=i).__dict__['_data'] updated_bangumi_obj.append(f) except DoesNotExist: pass runner = ScriptRunner() script_download_queue = runner.run() for subscribe in updated_bangumi_obj: print_info('fetching %s ...' % subscribe['bangumi_name']) try: bangumi_obj = Bangumi.get(name=subscribe['bangumi_name']) except Bangumi.DoesNotExist: print_error('Bangumi<{0}> does not exists.'.format( subscribe['bangumi_name']), exit_=False) continue try: followed_obj = Followed.get(bangumi_name=subscribe['bangumi_name']) except Followed.DoesNotExist: print_error('Bangumi<{0}> is not followed.'.format( subscribe['bangumi_name']), exit_=False) continue episode, all_episode_data = website.get_maximum_episode( bangumi=bangumi_obj, ignore_old_row=ignore, max_page=1) if (episode.get('episode') > subscribe['episode']) or (len(name) == 1 and download): if len(name) == 1 and download: episode_range = download else: episode_range = range(subscribe['episode'] + 1, episode.get('episode', 0) + 1) print_success('%s updated, episode: %d' % (subscribe['bangumi_name'], episode['episode'])) followed_obj.episode = episode['episode'] followed_obj.status = STATUS_UPDATED followed_obj.updated_time = int(time.time()) followed_obj.save() result['data']['updated'].append({ 'bangumi': subscribe['bangumi_name'], 'episode': episode['episode'] }) for i in episode_range: for epi in all_episode_data: if epi['episode'] == i: download_queue.append(epi) break if download is not None: result['data']['downloaded'] = download_queue download_prepare(download_queue) download_prepare(script_download_queue) print_info('Re-downloading ...') download_prepare( Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD)) return result
def get(self): data = Followed.get_all_followed(status=None, bangumi_status=None) self.set_header('Content-Type', 'text/css; charset=utf-8') self.render('templates/image.css', data=data, image_url=COVER_URL)
def get(self): data = Followed.get_all_followed() self.set_header('Content-Type', 'text/css') self.render('templates/image.css', data=data, image_url=IMAGE_URL)