Example #1
0
def add(manager, options):
    series_name = options.series_name
    entity_ids = options.entity_id
    quality = options.quality or os.environ.get(ENV_ADD_QUALITY, None)
    series_name = series_name.replace(r'\!', '!')
    normalized_name = plugin_series.normalize_series_name(series_name)
    with Session() as session:
        series = plugin_series.shows_by_exact_name(normalized_name, session)
        if not series:
            console('Series not yet in database, adding `%s`' % series_name)
            series = plugin_series.Series()
            series.name = series_name
            session.add(series)
        else:
            series = series[0]
        for ent_id in entity_ids:
            try:
                plugin_series.add_series_entity(session,
                                                series,
                                                ent_id,
                                                quality=quality)
            except ValueError as e:
                console(e.args[0])
            else:
                console('Added entity `%s` to series `%s`.' %
                        (ent_id, series.name.title()))
        session.commit()
    manager.config_changed()
Example #2
0
    def post(self, session):
        """ Create a new show and set its first accepted episode and/or alternate names """
        data = request.json
        series_name = data.get('series_name')

        normalized_name = series.normalize_series_name(series_name)
        matches = series.shows_by_exact_name(normalized_name, session=session)
        if matches:
            return {'status': 'error',
                    'message': 'Show `%s` already exist in DB' % series_name
                    }, 500
        show = series.Series()
        show.name = series_name
        session.add(show)

        ep_id = data.get('episode_identifier')
        alt_names = data.get('alternate_names')
        if ep_id:
            try:
                series.set_series_begin(show, ep_id)
            except ValueError as e:
                return {'status': 'error',
                        'message': e.args[0]
                        }, 501
        if alt_names:
            try:
                series.set_alt_names(alt_names, show, session)
            except PluginError as e:
                return {'status': 'error',
                        'message': e.value
                        }, 502

        return jsonify(get_series_details(show))
Example #3
0
    def post(self, session):
        """ Create a new show and set its first accepted episode and/or alternate names """
        data = request.json
        series_name = data.get('name')

        normalized_name = series.normalize_series_name(series_name)
        matches = series.shows_by_exact_name(normalized_name, session=session)
        if matches:
            raise Conflict('Show `%s` already exist in DB' % series_name)
        show = series.Series()
        show.name = series_name
        session.add(show)

        ep_id = data.get('begin_episode')
        alt_names = data.get('alternate_names')
        if ep_id:
            series.set_series_begin(show, ep_id)
        if alt_names:
            try:
                series.set_alt_names(alt_names, show, session)
            except PluginError as e:
                # Alternate name already exist for a different show
                raise Conflict(e.value)
        session.commit()
        rsp = jsonify(series_details(show, begin=ep_id is not None))
        rsp.status_code = 201
        return rsp
Example #4
0
    def test_series_delete(self, mock_show_by_id, mock_forget_series, api_client):
        show = series.Series()
        show.name = 'Some name'

        mock_show_by_id.return_value = show

        rsp = api_client.delete('/series/1')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_show_by_id.called
        assert mock_forget_series.called
Example #5
0
    def test_series_get_episode(self, mock_show_by_id, mock_episode_by_id, mock_episode_in_show, api_client):
        show = series.Series()
        episode = series.Episode()

        mock_show_by_id.return_value = show
        mock_episode_by_id.return_value = episode

        rsp = api_client.get('/series/1/episodes/1')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_show_by_id.called
        assert mock_episode_by_id.called
        assert mock_episode_in_show.called
Example #6
0
    def test_series_get_episodes(self, mock_show_by_id, api_client):
        show = series.Series()
        episode = series.Episode()
        release = series.Release()
        release.downloaded = True
        episode.releases.append(release)
        show.episodes.append(episode)

        mock_show_by_id.return_value = show

        rsp = api_client.get('/series/1/episodes')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_show_by_id.called
Example #7
0
    def test_series_begin(self, mock_show_by_id, mock_series_begin,
                          mock_latest_release, mock_new_eps_after, api_client):
        show = series.Series()
        episode = series.Episode()
        release = series.Release()
        release.downloaded = True
        episode.releases.append(release)
        ep_id = {"episode_identifier": "s01e01"}

        mock_show_by_id.return_value = show
        mock_latest_release.return_value = episode
        mock_new_eps_after.return_value = 0

        rsp = api_client.json_put('/series/1', data=json.dumps(ep_id))
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_show_by_id.called
Example #8
0
    def test_series_search(self, mocked_series_search, mock_latest_release, mock_new_eps_after, api_client):
        show = series.Series()
        episode = series.Episode()
        release = series.Release()
        release.downloaded = True
        episode.releases.append(release)

        mock_latest_release.return_value = episode
        mock_new_eps_after.return_value = 0
        mocked_series_search.return_value = [show]

        rsp = api_client.get('/series/search/the%20big%20bang%20theory')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_latest_release.called
        assert mock_new_eps_after.called
        assert mocked_series_search.called
Example #9
0
    def test_series_get(self, mock_show_by_id, mock_latest_release, mock_new_eps_after, api_client):
        show = series.Series()
        episode = series.Episode()
        release = series.Release()
        release.downloaded = True
        episode.releases.append(release)

        mock_show_by_id.return_value = show
        mock_latest_release.return_value = episode
        mock_new_eps_after.return_value = 0

        rsp = api_client.get('/series/1')

        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_latest_release.called
        assert mock_new_eps_after.called
        assert mock_show_by_id.called
Example #10
0
    def test_series_get_release(self, mock_show_by_id, mock_episode_by_id, mock_episode_in_show, mock_release_by_id,
                                mock_release_in_episode, api_client):
        show = series.Series()
        episode = series.Episode()
        release = series.Release()

        mock_show_by_id.return_value = show
        mock_episode_by_id.return_value = episode
        mock_release_by_id.return_value = release

        rsp = api_client.get('/series/2/episodes/653/releases/1551/')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        assert mock_show_by_id.called
        assert mock_episode_by_id.called
        assert mock_episode_in_show.called
        assert mock_release_by_id.called
        assert mock_release_in_episode.called
Example #11
0
 def post(self, name, session):
     """ Create a new show and set its first accepted episode """
     normalized_name = series.normalize_series_name(name)
     matches = series.shows_by_exact_name(normalized_name, session=session)
     if matches:
         return {
             'status': 'error',
             'message': 'Show `%s` already exist in DB' % name
         }, 500
     show = series.Series()
     show.name = name
     session.add(show)
     data = request.json
     ep_id = data.get('episode_identifier')
     try:
         series.set_series_begin(show, ep_id)
     except ValueError as e:
         return {'status': 'error', 'message': e.args[0]}, 400
     return jsonify(get_series_details(show))
Example #12
0
 def on_task_output(self, task, config):
     if not (config and task.accepted):
         return
     for entry in task.accepted:
         if entry.get('series_name') and entry.get('series_id'):
             fshow = task.session.query(plugin_series.Series).filter(
                 plugin_series.Series.name == entry['series_name']).first()
             if not fshow:
                 fshow = plugin_series.Series()
                 fshow.name = entry['series_name']
                 task.session.add(fshow)
             try:
                 plugin_series.set_series_begin(fshow, entry['series_id'])
             except ValueError as e:
                 log.error(
                     'An error occurred trying to set begin for %s: %s',
                     entry['series_name'], e)
             log.info('First episode for "%s" set to %s',
                      entry['series_name'], entry['series_id'])
Example #13
0
    def test_series_get_episode_releases(self, mock_show_by_id, mock_episode_by_id, mock_episode_in_show, api_client):
        show = series.Series()
        episode = series.Episode()

        mock_show_by_id.return_value = show
        mock_episode_by_id.return_value = episode

        rsp = api_client.get('/series/1/episodes/1/releases')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code

        rsp = api_client.get('/series/1/episodes/1/releases?downloaded=true')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code

        rsp = api_client.get('/series/1/episodes/1/releases?downloaded=false')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code

        assert mock_show_by_id.call_count == 3
        assert mock_episode_by_id.call_count == 3
        assert mock_episode_in_show.call_count == 3
Example #14
0
def begin(manager, options):
    series_name = options.series_name
    series_name = series_name.replace(r'\!', '!')
    normalized_name = plugin_series.normalize_series_name(series_name)
    with Session() as session:
        series = plugin_series.shows_by_exact_name(normalized_name, session)
        if options.forget:
            if not series:
                console('Series `%s` was not found in the database.' %
                        series_name)
            else:
                series = series[0]
                series.begin = None
                console('The begin episode for `%s` has been forgotten.' %
                        series.name)
                session.commit()
                manager.config_changed()
        elif options.episode_id:
            ep_id = options.episode_id
            if not series:
                console('Series not yet in database. Adding `%s`.' %
                        series_name)
                series = plugin_series.Series()
                series.name = series_name
                session.add(series)
            else:
                series = series[0]
            try:
                _, entity_type = plugin_series.set_series_begin(series, ep_id)
            except ValueError as e:
                console(e)
            else:
                if entity_type == 'season':
                    console('`%s` was identified as a season.' % ep_id)
                    ep_id += 'E01'
                console(
                    'Releases for `%s` will be accepted starting with `%s`.' %
                    (series.name, ep_id))
                session.commit()
            manager.config_changed()