Exemplo n.º 1
0
    def showSubtitleMissed(indexer_id, whichSubs):
        main_db_con = db.DBConnection()
        cur_show_results = main_db_con.select(
            "SELECT season, episode, name, subtitles FROM tv_episodes WHERE showid = ? {0} AND (status LIKE '%4' OR status LIKE '%6') and "
            "location != ''".format(
                ("AND season != 0 ",
                 "")[sickbeard.SUBTITLES_INCLUDE_SPECIALS]), [int(indexer_id)])
        result = {}
        for cur_result in cur_show_results:
            if whichSubs == 'all':
                if not frozenset(
                        subtitle_module.wanted_languages()).difference(
                            cur_result[b"subtitles"].split(',')):
                    continue
            elif whichSubs in cur_result[b"subtitles"]:
                continue

            cur_season = int(cur_result[b"season"])
            cur_episode = int(cur_result[b"episode"])

            if cur_season not in result:
                result[cur_season] = {}

            if cur_episode not in result[cur_season]:
                result[cur_season][cur_episode] = {}

            result[cur_season][cur_episode]["name"] = cur_result[b"name"]

            result[cur_season][cur_episode]["subtitles"] = cur_result[
                b"subtitles"]

        return json.dumps(result)
Exemplo n.º 2
0
    def showSubtitleMissed(indexer_id, whichSubs):
        main_db_con = db.DBConnection()
        cur_show_results = main_db_con.select(
            b'SELECT season, episode, name, subtitles '
            b'FROM tv_episodes '
            b'WHERE showid = ? '
            b'AND season != 0 '
            b'AND (status LIKE \'%4\' OR status LIKE \'%6\') '
            b'AND location != \'\'',
            [int(indexer_id)]
        )

        result = {}
        for cur_result in cur_show_results:
            if whichSubs == 'all':
                if not frozenset(subtitles.wanted_languages()).difference(cur_result[b'subtitles'].split(',')):
                    continue
            elif whichSubs in cur_result[b'subtitles']:
                continue

            cur_season = int(cur_result[b'season'])
            cur_episode = int(cur_result[b'episode'])

            if cur_season not in result:
                result[cur_season] = {}

            if cur_episode not in result[cur_season]:
                result[cur_season][cur_episode] = {}

            result[cur_season][cur_episode]['name'] = cur_result[b'name']
            result[cur_season][cur_episode]['subtitles'] = cur_result[b'subtitles']

        return json.dumps(result)
Exemplo n.º 3
0
def test_wanted_languages__only_valid_3letter_codes(monkeypatch):
    # Given
    monkeypatch.setattr('sickbeard.SUBTITLES_LANGUAGES', ['pob', 'trash', 'eng', 'fre', 'abc', 'pt-BR'])

    # When
    actual = sut.wanted_languages()

    # Then
    assert {'pob', 'eng', 'fre'} == actual
Exemplo n.º 4
0
    def subtitleMissed(self, whichSubs=None):
        t = PageTemplate(rh=self, filename="manage_subtitleMissed.mako")

        if not whichSubs:
            return t.render(whichSubs=whichSubs,
                            title=_('Episode Overview'),
                            header=_('Episode Overview'),
                            topmenu='manage',
                            show_names=None,
                            ep_counts=None,
                            sorted_show_ids=None,
                            controller="manage",
                            action="subtitleMissed")

        main_db_con = db.DBConnection()
        status_results = main_db_con.select(
            "SELECT show_name, tv_shows.indexer_id as indexer_id, tv_episodes.subtitles subtitles "
            + "FROM tv_episodes, tv_shows " +
            "WHERE tv_shows.subtitles = 1 AND (tv_episodes.status LIKE '%4' OR tv_episodes.status LIKE '%6') AND tv_episodes.season != 0 "
            +
            "AND tv_episodes.location != '' AND tv_episodes.showid = tv_shows.indexer_id ORDER BY show_name"
        )

        ep_counts = {}
        show_names = {}
        sorted_show_ids = []
        for cur_status_result in status_results:
            if whichSubs == 'all':
                if not frozenset(
                        subtitle_module.wanted_languages()).difference(
                            cur_status_result[b"subtitles"].split(',')):
                    continue
            elif whichSubs in cur_status_result[b"subtitles"]:
                continue

            cur_indexer_id = int(cur_status_result[b"indexer_id"])
            if cur_indexer_id not in ep_counts:
                ep_counts[cur_indexer_id] = 1
            else:
                ep_counts[cur_indexer_id] += 1

            show_names[cur_indexer_id] = cur_status_result[b"show_name"]
            if cur_indexer_id not in sorted_show_ids:
                sorted_show_ids.append(cur_indexer_id)

        return t.render(whichSubs=whichSubs,
                        show_names=show_names,
                        ep_counts=ep_counts,
                        sorted_show_ids=sorted_show_ids,
                        title=_('Missing Subtitles'),
                        header=_('Missing Subtitles'),
                        topmenu='manage',
                        controller="manage",
                        action="subtitleMissed")
Exemplo n.º 5
0
def render_scripts(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        srRoot = context.get('srRoot', UNDEFINED)
        static_url = context.get('static_url', UNDEFINED)

        def scripts():
            return render_scripts(context)

        __M_writer = context.writer()
        __M_writer(
            u'\n    <script>\n        $(document).ready(function() {\n            $("#subtitles_languages").tokenInput(['
        )
        __M_writer(
            unicode(','.join("{\"id\": \"" + code + "\", name: \"" +
                             subtitles.name_from_code(code) + "\"}"
                             for code in subtitles.subtitle_code_filter())))
        __M_writer(
            u'], {\n                method: "POST",\n                hintText: _(\'Write to search a language and select it\'),\n                preventDuplicates: true,\n                prePopulate: ['
        )
        __M_writer(
            unicode(','.join("{\"id\": \"" + code + "\", name: \"" +
                             subtitles.name_from_code(code) + "\"}"
                             for code in subtitles.wanted_languages())))
        __M_writer(
            u'],\n                resultsFormatter: function(item) {\n                    return "<li><img src=\''
        )
        __M_writer(unicode(srRoot))
        __M_writer(
            u'/images/subtitles/flags/" + item.id + ".png\' onError=\'this.onerror=null;this.src=\\"'
        )
        __M_writer(unicode(static_url('images/flags/unknown.png')))
        __M_writer(
            u'\\";\' style=\'vertical-align: middle !important;\' /> " + item.name + "</li>"\n                },\n                tokenFormatter: function(item) {\n                    return "<li><img src=\''
        )
        __M_writer(unicode(srRoot))
        __M_writer(
            u'/images/subtitles/flags/" + item.id + ".png\' onError=\'this.onerror=null;this.src=\\"'
        )
        __M_writer(unicode(static_url('images/flags/unknown.png')))
        __M_writer(
            u'\\";\' style=\'vertical-align: middle !important;\' /> " + item.name + "</li>"\n                }\n            });\n        });\n        $(\'#config-components\').tabs();\n        $(\'#subtitles_dir\').fileBrowser({ title: _(\'Select Subtitles Download Directory\') });\n    </script>\n'
        )
        return ''
    finally:
        context.caller_stack._pop_frame()
Exemplo n.º 6
0
    def subtitleMissed(self, whichSubs=None):
        t = PageTemplate(rh=self, filename='manage_subtitleMissed.mako')

        if not whichSubs:
            return t.render(whichSubs=whichSubs, title='Missing Subtitles',
                            header='Missing Subtitles', topmenu='manage',
                            show_names=None, ep_counts=None, sorted_show_ids=None,
                            controller='manage', action='subtitleMissed')

        main_db_con = db.DBConnection()
        status_results = main_db_con.select(
            b'SELECT show_name, tv_shows.indexer_id as indexer_id, tv_episodes.subtitles subtitles '
            b'FROM tv_episodes, tv_shows '
            b'WHERE tv_shows.subtitles = 1 '
            b'AND (tv_episodes.status LIKE \'%4\' OR tv_episodes.status LIKE \'%6\') '
            b'AND tv_episodes.season != 0 '
            b'AND tv_episodes.location != \'\' '
            b'AND tv_episodes.showid = tv_shows.indexer_id '
            b'ORDER BY show_name'
        )

        ep_counts = {}
        show_names = {}
        sorted_show_ids = []
        for cur_status_result in status_results:
            if whichSubs == 'all':
                if not frozenset(subtitles.wanted_languages()).difference(cur_status_result[b'subtitles'].split(',')):
                    continue
            elif whichSubs in cur_status_result[b'subtitles']:
                continue

            cur_indexer_id = int(cur_status_result[b'indexer_id'])
            if cur_indexer_id not in ep_counts:
                ep_counts[cur_indexer_id] = 1
            else:
                ep_counts[cur_indexer_id] += 1

            show_names[cur_indexer_id] = cur_status_result[b'show_name']
            if cur_indexer_id not in sorted_show_ids:
                sorted_show_ids.append(cur_indexer_id)

        return t.render(whichSubs=whichSubs, show_names=show_names, ep_counts=ep_counts, sorted_show_ids=sorted_show_ids,
                        title='Missing Subtitles', header='Missing Subtitles', topmenu='manage',
                        controller='manage', action='subtitleMissed')