catalog: bangumi (wip)

This commit is contained in:
Your Name 2022-12-09 03:09:06 +00:00
parent bfd68e6a3f
commit 01e8b89af4
4 changed files with 44 additions and 0 deletions

View file

@ -47,6 +47,7 @@ class IdType(models.TextChoices):
TMDB_Person = 'tmdb_person', _('TMDB影人')
IGDB = 'igdb', _('IGDB游戏')
Steam = 'steam', _('Steam游戏')
Bangumi = 'bangumi', _('Bangumi')
ApplePodcast = 'apple_podcast', _('苹果播客')

View file

@ -89,6 +89,24 @@ class DoubanGameTestCase(TestCase):
self.assertEqual(site.resource.item.douban_game, '10734307')
class BangumiGameTestCase(TestCase):
def test_parse(self):
t_id_type = IdType.Bangumi
t_id_value = '15912'
t_url = 'https://bgm.tv/subject/15912'
site = SiteList.get_site_by_id_type(t_id_type)
self.assertIsNotNone(site)
self.assertEqual(site.validate_url(t_url), True)
site = SiteList.get_site_by_url(t_url)
self.assertEqual(site.url, t_url)
self.assertEqual(site.id_value, t_id_value)
@use_local_response
def test_scrape(self):
# TODO
pass
class MultiGameSitesTestCase(TestCase):
@use_local_response
def test_games(self):

View file

@ -12,3 +12,4 @@ from .imdb import IMDB
from .spotify import Spotify
from .igdb import IGDB
from .steam import Steam
from .bangumi import Bangumi

24
catalog/sites/bangumi.py Normal file
View file

@ -0,0 +1,24 @@
from catalog.common import *
from catalog.models import *
import logging
_logger = logging.getLogger(__name__)
@SiteList.register
class Bangumi(AbstractSite):
ID_TYPE = IdType.Bangumi
URL_PATTERNS = [
r"https://bgm\.tv/subject/(\d+)",
]
WIKI_PROPERTY_ID = ''
DEFAULT_MODEL = None
@classmethod
def id_to_url(self, id_value):
return f"https://bgm.tv/subject/{id_value}"
def scrape(self):
# TODO rewrite with bangumi api https://bangumi.github.io/api/
pass