<commit_before># coding: utf-8
from __future__ import print_function, unicode_literals

import datetime
import os
from collections import OrderedDict

import tornado.escape

from bgmi.config import SAVE_PATH, DB_PATH
from bgmi.front.base import BaseHandler, WEEK
from bgmi.models import Bangumi, Followed, STATUS_NORMAL, STATUS_UPDATING, STATUS_END


def get_player(bangumi_name):
    episode_list = {}
    bangumi_path = os.path.join(SAVE_PATH, bangumi_name)
    for root, _, files in os.walk(bangumi_path):
        if not _ and files:
            _ = root.replace(bangumi_path, '').split(os.path.sep)
            base_path = root.replace(SAVE_PATH, '')
            if len(_) >= 2:
                episode_path = root.replace(os.path.join(SAVE_PATH, bangumi_name), '')
                if episode_path.split(os.path.sep)[1].isdigit():
                    episode = int(episode_path.split(os.path.sep)[1])
                else:
                    continue
            else:
                episode = -1

            for bangumi in files:
                if bangumi.lower().endswith('.mp4'):
                    mp4_path = os.path.join(base_path, bangumi).replace(os.path.sep, '/')
                    mp4_path = os.path.join(os.path.dirname(mp4_path),
                                            tornado.escape.url_escape(os.path.basename(mp4_path)))
                    episode_list[episode] = {'path': mp4_path.replace(os.path.sep, '/')}
                    break

    return episode_list


class MainHandler(BaseHandler):
    def get(self, type_=''):
        if os.environ.get('DEV', False):
            self._add_header()

        if not os.path.exists(DB_PATH):
            self.write('BGmi db file not found.')
            self.finish()
            return

        if type_ == 'calendar':
            calendar = Bangumi.get_all_bangumi()

            for i in self.patch_list:
                calendar[i['update_time'].lower()].append(i)

            def shift(seq, n):
                n %= len(seq)
                return seq[n:] + seq[:n]

            weekday_order = shift(WEEK, datetime.datetime.today().weekday())
            cal_ordered = OrderedDict()
<commit_msg>fix bug of url path<commit_after># coding: utf-8
from __future__ import print_function, unicode_literals

import datetime
import os
from collections import OrderedDict

import tornado.escape

from bgmi.config import SAVE_PATH, DB_PATH
from bgmi.front.base import BaseHandler, WEEK
from bgmi.models import Bangumi, Followed, STATUS_NORMAL, STATUS_UPDATING, STATUS_END


def get_player(bangumi_name):
    episode_list = {}
    bangumi_path = os.path.join(SAVE_PATH, bangumi_name)
    for root, _, files in os.walk(bangumi_path):
        if not _ and files:
            _ = root.replace(bangumi_path, '').split(os.path.sep)
            base_path = root.replace(SAVE_PATH, '')
            if len(_) >= 2:
                episode_path = root.replace(os.path.join(SAVE_PATH, bangumi_name), '')
                if episode_path.split(os.path.sep)[1].isdigit():
                    episode = int(episode_path.split(os.path.sep)[1])
                else:
                    continue
            else:
                episode = -1

            for bangumi in files:
                if bangumi.lower().endswith('.mp4'):
                    mp4_path = os.path.join(base_path, bangumi)
                    mp4_path = os.path.join(os.path.dirname(mp4_path), os.path.basename(mp4_path))
                    mp4_path = mp4_path.replace(os.path.sep, '/')
                    episode_list[episode] = {'path': mp4_path}
                    break

    return episode_list


class MainHandler(BaseHandler):
    def get(self, type_=''):
        if os.environ.get('DEV', False):
            self._add_header()

        if not os.path.exists(DB_PATH):
            self.write('BGmi db file not found.')
            self.finish()
            return

        if type_ == 'calendar':
            calendar = Bangumi.get_all_bangumi()

            for i in self.patch_list:
                calendar[i['update_time'].lower()].append(i)

            def shift(seq, n):
                n %= len(seq)
                return seq[n:] + seq[:n]

            weekday_order = shift(WEEK, datetime.datetime.today().weekday())
            cal_ordered = OrderedDict()

{'fraction_non_alphanumeric': 0.11155008133860098, 'fraction_numerical': 0.005577504066930049, 'mean_word_length': 1.945927446954141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1260801', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1288, 'n_words': 266}