Ejemplo n.º 1
0
def create_or_get_chapter(url):
    """
    Fetch info and create Chapter record if not already created.
    Returns Chapter object.
    """

    # Check if this url is supported
    site = sites.get_site(url)
    if site is None:
        raise PyError({'msg': 'unsupported_url'})

    chapter = Chapter.get_by_url(url)
    if chapter is None:
        page_html = site.fetch_chapter_seed_page(url)
        info = site.chapter_info(page_html, url=url)
        series = create_or_get_series(info['series_url'])

        chapter = Chapter.create(url,
                                 info['name'],
                                 info['pages'],
                                 info['series_url'],
                                 series.name,
                                 info['prev_chapter_url'],
                                 info['next_chapter_url'])
        chapter.put()

    return chapter
Ejemplo n.º 2
0
def create_or_get_chapter(url):
    """
    Fetch info and create Chapter record if not already created.
    Returns Chapter object.
    """

    # Check if this url is supported
    site = sites.get_site(url)
    if site is None:
        raise PyError({'msg': 'unsupported_url'})

    chapter = Chapter.get_by_url(url)
    if chapter is None:
        page_html = site.fetch_chapter_seed_page(url)
        info = site.chapter_info(page_html)

        if info['series_url']:
            series = create_or_get_series(info['series_url'])
        else:
            series = type('', (object, ), {'name': 'Unknown'})

        chapter = Chapter.create(url,
                                 info['name'],
                                 info['pages'],
                                 info['series_url'],
                                 series.name,
                                 info['prev_chapter_url'],
                                 info['next_chapter_url'])
        chapter.put()

    return chapter
Ejemplo n.º 3
0
def create_or_get_series(url, no_update=False):
    """
    Fetch info and create Series record if not already created.
    Returns Series object.
    """

    # Check if this url is supported
    site = sites.get_site(url)
    if site is None:
        raise PyError({'msg': 'unsupported_url'})

    # Check if series is already in db
    series_record = Series.get_by_url(url)

    # Skip reloading series info if updated recently
    if series_record and (no_update or series_record.is_fresh()):
        return series_record

    # Fetch series info (name, thumburl, chapter list, etc.)
    series_page = site.fetch_manga_seed_page(url)
    series = site.series_info(series_page)

    # Create new series if not in db yet
    if series_record is None:
        series_record = Series.create(url,
                                      site.netlocs[0],
                                      series['name'],
                                      series['thumb_url'],
                                      series['chapters'],
                                      series['status'],
                                      series['tags'],
                                      series['description'],
                                      series['authors'])
    else:
        # Update existing Series db record
        fields = ('site', 'name', 'thumb_url', 'chapters', 'status', 'tags',
                  'description', 'authors')
        params = {field: series[field] for field in fields}
        update_series(series_record, **params)

    return series_record
Ejemplo n.º 4
0
def create_or_get_series(url, no_update=False):
    """
    Fetch info and create Series record if not already created.
    Returns Series object.
    """

    # Check if this url is supported
    site = sites.get_site(url)
    if site is None:
        raise PyError({'msg': 'unsupported_url'})

    # Check if series is already in db
    series_record = Series.get_by_url(url)

    # Skip reloading series info if updated recently
    if series_record and (no_update or series_record.is_fresh()):
        return series_record

    # Fetch series info (name, thumburl, chapter list, etc.)
    series_page = site.fetch_manga_seed_page(url)
    series = site.series_info(series_page)

    # Create new series if not in db yet
    if series_record is None:
        series_record = Series.create(url,
                                      site.netlocs[0],
                                      series['name'],
                                      series['thumb_url'],
                                      series['chapters'],
                                      series['status'],
                                      series['tags'],
                                      series['description'],
                                      series['authors'])
    else:
        # Update existing Series db record
        fields = ('site', 'name', 'thumb_url', 'chapters', 'status', 'tags',
                  'description', 'authors')
        params = {field: series[field] for field in fields}
        update_series(series_record, **params)

    return series_record
Ejemplo n.º 5
0
 def _test_instance(self, urls, cls):
     for url in urls:
         self.assertIsInstance(get_site(url), cls)
Ejemplo n.º 6
0
 def _test_none(self, *args):
     for url in args:
         self.assertIsNone(get_site(url))
Ejemplo n.º 7
0
 def _test_instance(self, urls, cls):
     for url in urls:
         self.assertIsInstance(get_site(url), cls)
Ejemplo n.º 8
0
 def _test_none(self, *args):
     for url in args:
         self.assertIsNone(get_site(url))