Пример #1
0
    def get(self):
        history = request.args.get('history')
        if history and history not in False_Keys:
            providers = list(
                TableHistory.select(TableHistory.provider).where(
                    TableHistory.provider != None
                    and TableHistory.provider != "manual").dicts())
            providers += list(
                TableHistoryMovie.select(TableHistoryMovie.provider).where(
                    TableHistoryMovie.provider != None
                    and TableHistoryMovie.provider != "manual").dicts())
            providers_list = list(set([x['provider'] for x in providers]))
            providers_dicts = []
            for provider in providers_list:
                providers_dicts.append({
                    'name': provider,
                    'status': 'History',
                    'retry': '-'
                })
            return jsonify(
                data=sorted(providers_dicts, key=itemgetter('name')))

        throttled_providers = list_throttled_providers()

        providers = list()
        for provider in throttled_providers:
            providers.append({
                "name":
                provider[0],
                "status":
                provider[1] if provider[1] is not None else "Good",
                "retry":
                provider[2] if provider[2] != "now" else "-"
            })
        return jsonify(data=providers)
Пример #2
0
def history_log(action,
                sonarrSeriesId,
                sonarrEpisodeId,
                description,
                video_path=None,
                language=None,
                provider=None,
                score=None,
                forced=False):
    TableHistory.insert({
        TableHistory.action: action,
        TableHistory.sonarr_series_id: sonarrSeriesId,
        TableHistory.sonarr_episode_id: sonarrEpisodeId,
        TableHistory.timestamp: time.time(),
        TableHistory.description: description,
        TableHistory.video_path: video_path,
        TableHistory.language: language,
        TableHistory.provider: provider,
        TableHistory.score: score
    }).execute()
Пример #3
0
def history_log(action,
                sonarr_series_id,
                sonarr_episode_id,
                description,
                video_path=None,
                language=None,
                provider=None,
                score=None,
                subs_id=None,
                subtitles_path=None):
    TableHistory.insert({
        TableHistory.action: action,
        TableHistory.sonarrSeriesId: sonarr_series_id,
        TableHistory.sonarrEpisodeId: sonarr_episode_id,
        TableHistory.timestamp: time.time(),
        TableHistory.description: description,
        TableHistory.video_path: video_path,
        TableHistory.language: language,
        TableHistory.provider: provider,
        TableHistory.score: score,
        TableHistory.subs_id: subs_id,
        TableHistory.subtitles_path: subtitles_path
    }).execute()
    event_stream(type='episode-history')
Пример #4
0
    def get(self):
        history = request.args.get('history')
        if history and history not in False_Keys:
            languages = list(
                TableHistory.select(TableHistory.language).where(
                    TableHistory.language != None).dicts())
            languages += list(
                TableHistoryMovie.select(TableHistoryMovie.language).where(
                    TableHistoryMovie.language != None).dicts())
            languages_list = list(
                set([l['language'].split(':')[0] for l in languages]))
            languages_dicts = []
            for language in languages_list:
                code2 = None
                if len(language) == 2:
                    code2 = language
                elif len(language) == 3:
                    code2 = alpha2_from_alpha3(language)
                else:
                    continue

                if not any(x['code2'] == code2 for x in languages_dicts):
                    try:
                        languages_dicts.append({
                            'code2':
                            code2,
                            'name':
                            language_from_alpha2(code2),
                            # Compatibility: Use false temporarily
                            'enabled':
                            False
                        })
                    except:
                        continue
            return jsonify(sorted(languages_dicts, key=itemgetter('name')))

        result = TableSettingsLanguages.select(TableSettingsLanguages.name,
                                               TableSettingsLanguages.code2,
                                               TableSettingsLanguages.enabled)\
            .order_by(TableSettingsLanguages.name).dicts()
        result = list(result)
        for item in result:
            item['enabled'] = item['enabled'] == 1
        return jsonify(result)
Пример #5
0
    def get(self):
        start = request.args.get('start') or 0
        length = request.args.get('length') or -1
        episodeid = request.args.get('episodeid')

        upgradable_episodes_not_perfect = []
        if settings.general.getboolean('upgrade_subs'):
            days_to_upgrade_subs = settings.general.days_to_upgrade_subs
            minimum_timestamp = (
                (datetime.datetime.now() -
                 timedelta(days=int(days_to_upgrade_subs))) -
                datetime.datetime(1970, 1, 1)).total_seconds()

            if settings.general.getboolean('upgrade_manual'):
                query_actions = [1, 2, 3, 6]
            else:
                query_actions = [1, 3]

            upgradable_episodes_conditions = [
                (TableHistory.action.in_(query_actions)),
                (TableHistory.timestamp > minimum_timestamp),
                (TableHistory.score is not None)
            ]
            upgradable_episodes_conditions += get_exclusion_clause('series')
            upgradable_episodes = TableHistory.select(TableHistory.video_path,
                                                      fn.MAX(TableHistory.timestamp).alias('timestamp'),
                                                      TableHistory.score,
                                                      TableShows.tags,
                                                      TableEpisodes.monitored,
                                                      TableShows.seriesType)\
                .join(TableEpisodes, on=(TableHistory.sonarrEpisodeId == TableEpisodes.sonarrEpisodeId))\
                .join(TableShows, on=(TableHistory.sonarrSeriesId == TableShows.sonarrSeriesId))\
                .where(reduce(operator.and_, upgradable_episodes_conditions))\
                .group_by(TableHistory.video_path)\
                .dicts()
            upgradable_episodes = list(upgradable_episodes)
            for upgradable_episode in upgradable_episodes:
                if upgradable_episode['timestamp'] > minimum_timestamp:
                    try:
                        int(upgradable_episode['score'])
                    except ValueError:
                        pass
                    else:
                        if int(upgradable_episode['score']) < 360:
                            upgradable_episodes_not_perfect.append(
                                upgradable_episode)

        query_conditions = [(TableEpisodes.title is not None)]
        if episodeid:
            query_conditions.append(
                (TableEpisodes.sonarrEpisodeId == episodeid))
        query_condition = reduce(operator.and_, query_conditions)
        episode_history = TableHistory.select(TableHistory.id,
                                              TableShows.title.alias('seriesTitle'),
                                              TableEpisodes.monitored,
                                              TableEpisodes.season.concat('x').concat(TableEpisodes.episode).alias('episode_number'),
                                              TableEpisodes.title.alias('episodeTitle'),
                                              TableHistory.timestamp,
                                              TableHistory.subs_id,
                                              TableHistory.description,
                                              TableHistory.sonarrSeriesId,
                                              TableEpisodes.path,
                                              TableHistory.language,
                                              TableHistory.score,
                                              TableShows.tags,
                                              TableHistory.action,
                                              TableHistory.subtitles_path,
                                              TableHistory.sonarrEpisodeId,
                                              TableHistory.provider,
                                              TableShows.seriesType)\
            .join(TableShows, on=(TableHistory.sonarrSeriesId == TableShows.sonarrSeriesId))\
            .join(TableEpisodes, on=(TableHistory.sonarrEpisodeId == TableEpisodes.sonarrEpisodeId))\
            .where(query_condition)\
            .order_by(TableHistory.timestamp.desc())\
            .limit(length)\
            .offset(start)\
            .dicts()
        episode_history = list(episode_history)

        blacklist_db = TableBlacklist.select(TableBlacklist.provider,
                                             TableBlacklist.subs_id).dicts()
        blacklist_db = list(blacklist_db)

        for item in episode_history:
            # Mark episode as upgradable or not
            item.update({"upgradable": False})
            if {
                    "video_path": str(item['path']),
                    "timestamp": float(item['timestamp']),
                    "score": str(item['score']),
                    "tags": str(item['tags']),
                    "monitored": str(item['monitored']),
                    "seriesType": str(item['seriesType'])
            } in upgradable_episodes_not_perfect:
                if os.path.isfile(
                        path_mappings.path_replace(item['subtitles_path'])):
                    item.update({"upgradable": True})

            del item['path']

            postprocessEpisode(item)

            if item['score']:
                item['score'] = str(round(
                    (int(item['score']) * 100 / 360), 2)) + "%"

            # Make timestamp pretty
            if item['timestamp']:
                item["raw_timestamp"] = int(item['timestamp'])
                item["parsed_timestamp"] = datetime.datetime.fromtimestamp(
                    int(item['timestamp'])).strftime('%x %X')
                item['timestamp'] = pretty.date(item["raw_timestamp"])

            # Check if subtitles is blacklisted
            item.update({"blacklisted": False})
            if item['action'] not in [0, 4, 5]:
                for blacklisted_item in blacklist_db:
                    if blacklisted_item['provider'] == item['provider'] and \
                            blacklisted_item['subs_id'] == item['subs_id']:
                        item.update({"blacklisted": True})
                        break

        count = TableHistory.select()\
            .join(TableEpisodes, on=(TableHistory.sonarrEpisodeId == TableEpisodes.sonarrEpisodeId))\
            .where(TableEpisodes.title is not None).count()

        return jsonify(data=episode_history, total=count)
Пример #6
0
    def get(self):
        timeframe = request.args.get('timeframe') or 'month'
        action = request.args.get('action') or 'All'
        provider = request.args.get('provider') or 'All'
        language = request.args.get('language') or 'All'

        # timeframe must be in ['week', 'month', 'trimester', 'year']
        if timeframe == 'year':
            delay = 364 * 24 * 60 * 60
        elif timeframe == 'trimester':
            delay = 90 * 24 * 60 * 60
        elif timeframe == 'month':
            delay = 30 * 24 * 60 * 60
        elif timeframe == 'week':
            delay = 6 * 24 * 60 * 60

        now = time.time()
        past = now - delay

        history_where_clauses = [(TableHistory.timestamp.between(past, now))]
        history_where_clauses_movie = [
            (TableHistoryMovie.timestamp.between(past, now))
        ]

        if action != 'All':
            history_where_clauses.append((TableHistory.action == action))
            history_where_clauses_movie.append(
                (TableHistoryMovie.action == action))
        else:
            history_where_clauses.append((TableHistory.action.in_([1, 2, 3])))
            history_where_clauses_movie.append(
                (TableHistoryMovie.action.in_([1, 2, 3])))

        if provider != 'All':
            history_where_clauses.append((TableHistory.provider == provider))
            history_where_clauses_movie.append(
                (TableHistoryMovie.provider == provider))

        if language != 'All':
            history_where_clauses.append((TableHistory.language == language))
            history_where_clauses_movie.append(
                (TableHistoryMovie.language == language))

        history_where_clause = reduce(operator.and_, history_where_clauses)
        history_where_clause_movie = reduce(operator.and_,
                                            history_where_clauses_movie)

        data_series = TableHistory.select(fn.strftime('%Y-%m-%d', TableHistory.timestamp, 'unixepoch').alias('date'),
                                          fn.COUNT(TableHistory.id).alias('count'))\
            .where(history_where_clause) \
            .group_by(fn.strftime('%Y-%m-%d', TableHistory.timestamp, 'unixepoch'))\
            .dicts()
        data_series = list(data_series)

        data_movies = TableHistoryMovie.select(fn.strftime('%Y-%m-%d', TableHistoryMovie.timestamp, 'unixepoch').alias('date'),
                                               fn.COUNT(TableHistoryMovie.id).alias('count')) \
            .where(history_where_clause_movie) \
            .group_by(fn.strftime('%Y-%m-%d', TableHistoryMovie.timestamp, 'unixepoch')) \
            .dicts()
        data_movies = list(data_movies)

        for dt in rrule.rrule(rrule.DAILY,
                              dtstart=datetime.datetime.now() -
                              datetime.timedelta(seconds=delay),
                              until=datetime.datetime.now()):
            if not any(d['date'] == dt.strftime('%Y-%m-%d')
                       for d in data_series):
                data_series.append({
                    'date': dt.strftime('%Y-%m-%d'),
                    'count': 0
                })
            if not any(d['date'] == dt.strftime('%Y-%m-%d')
                       for d in data_movies):
                data_movies.append({
                    'date': dt.strftime('%Y-%m-%d'),
                    'count': 0
                })

        sorted_data_series = sorted(data_series, key=lambda i: i['date'])
        sorted_data_movies = sorted(data_movies, key=lambda i: i['date'])

        return jsonify(series=sorted_data_series, movies=sorted_data_movies)