Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info-web. 

5 

6otaku-info-web is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info-web is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info-web. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from typing import List 

21from flask import request 

22from flask.blueprints import Blueprint 

23from puffotter.flask.routes.decorators import api 

24from puffotter.flask.exceptions import ApiException 

25from otaku_info_web.Config import Config 

26from otaku_info_web.db.MediaId import MediaId 

27from otaku_info_web.db.MediaItem import MediaItem 

28from otaku_info_web.utils.enums import MediaType, ListService 

29 

30 

31def define_blueprint(blueprint_name: str) -> Blueprint: 

32 """ 

33 Defines the blueprint for this route 

34 :param blueprint_name: The name of the blueprint 

35 :return: The blueprint 

36 """ 

37 blueprint = Blueprint(blueprint_name, __name__) 

38 api_base_path = f"/api/v{Config.API_VERSION}" 

39 

40 @blueprint.route(f"{api_base_path}/media_ids", methods=["GET"]) 

41 @api 

42 def media_ids(): 

43 """ 

44 Retrieves all media IDs for a media ID 

45 :return: The response 

46 """ 

47 service = ListService(request.args["service"]) 

48 service_id = request.args["service_id"] 

49 media_type = MediaType(request.args["media_type"]) 

50 

51 matching_ids: List[MediaItem] = [ 

52 x for x in 

53 MediaId.query 

54 .filter_by(service_id=service_id, service=service).all() 

55 if x.media_item.media_type == media_type 

56 ] 

57 

58 if len(matching_ids) < 1: 

59 raise ApiException("ID does not exist", 404) 

60 

61 media_item = matching_ids[0].media_item 

62 

63 id_mappings = { 

64 x.service.value: x.service_id 

65 for x in MediaId.query.filter_by(media_item_id=media_item.id).all() 

66 } 

67 id_mappings["otaku_info"] = media_item.id 

68 

69 return id_mappings 

70 

71 return blueprint