Ejemplo n.º 1
0
def series_data(series_slug):
    series = Series.objects.get(slug=series_slug)
    chapters = Chapter.objects.filter(series=series).select_related('group')
    chapters_dict = {}
    groups_dict = {}
    for chapter in chapters:
        chapter_media_path = os.path.join(settings.MEDIA_ROOT, "manga", series_slug, "chapters", chapter.folder)
        ch_clean = Chapter.clean_chapter_number(chapter)
        groups_dict[str(chapter.group.id)] = chapter.group.name
        query_string = "" if not chapter.version else f"?v{chapter.version}"
        if ch_clean in chapters_dict:
            chapters_dict[ch_clean]["groups"][str(chapter.group.id)] = sorted([u + query_string for u in os.listdir(os.path.join(chapter_media_path, str(chapter.group.id)))])
        else:
            chapters_dict[ch_clean] = {
                "volume": str(chapter.volume),
                "title": chapter.title,
                "folder": chapter.folder,
                "groups": {
                    str(chapter.group.id): sorted([u + query_string for u in os.listdir(os.path.join(chapter_media_path, str(chapter.group.id)))])
                }
            }
            if chapter.preferred_sort:
                try:
                    chapters_dict[ch_clean]["preferred_sort"] = json.loads(chapter.preferred_sort)
                except:
                    pass
    vols = Volume.objects.filter(series=series).order_by('-volume_number')
    cover_vol_url = ""
    for vol in vols:
        if vol.volume_cover:
            cover_vol_url = f"/media/{vol.volume_cover}"
            break
    return {"slug": series_slug, "title": series.name, "description": series.synopsis, "author": series.author.name, "artist": series.artist.name, "groups": groups_dict, "cover": cover_vol_url, "preferred_sort": settings.PREFERRED_SORT, "chapters": chapters_dict}
Ejemplo n.º 2
0
def series_data(request, series_slug):
    series = Series.objects.get(slug=series_slug)
    chapters = Chapter.objects.filter(series=series)
    chapters_dict = {}
    for chapter in chapters:
        chapter_media_path = os.path.join(settings.MEDIA_ROOT, "manga",
                                          series_slug, "chapters",
                                          chapter.folder)
        ch_clean = Chapter.clean_chapter_number(chapter)
        if ch_clean in chapters_dict:
            chapters_dict[ch_clean]["groups"][str(chapter.group.id)] = sorted(
                os.listdir(chapter_media_path))
        else:
            chapters_dict[ch_clean] = {
                "volume": str(chapter.volume),
                "title": chapter.title,
                "folder": chapter.folder,
                "groups": {
                    str(chapter.group.id):
                    sorted(os.listdir(chapter_media_path))
                }
            }
    data = {
        "slug": series_slug,
        "title": series.name,
        "chapters": chapters_dict
    }
    return HttpResponse(JsonResponse(data))
Ejemplo n.º 3
0
def series_data(series_slug):
    series = Series.objects.get(slug=series_slug)
    chapters = Chapter.objects.filter(series=series).select_related('group')
    chapters_dict = {}
    groups_dict = {}
    for chapter in chapters:
        chapter_media_path = os.path.join(settings.MEDIA_ROOT, "manga",
                                          series_slug, "chapters",
                                          chapter.folder)
        ch_clean = Chapter.clean_chapter_number(chapter)
        groups_dict[str(chapter.group.id)] = chapter.group.name
        if ch_clean in chapters_dict:
            chapters_dict[ch_clean]["groups"][str(chapter.group.id)] = sorted(
                os.listdir(
                    os.path.join(chapter_media_path, str(chapter.group.id))))
        else:
            chapters_dict[ch_clean] = {
                "volume": str(chapter.volume),
                "title": chapter.title,
                "folder": chapter.folder,
                "groups": {
                    str(chapter.group.id):
                    sorted(
                        os.listdir(
                            os.path.join(chapter_media_path,
                                         str(chapter.group.id))))
                }
            }
    vols = Volume.objects.filter(series=series).order_by('-volume_number')
    cover_vol_url = ""
    for vol in vols:
        if vol.volume_cover:
            cover_vol_url = f"/media/{vol.volume_cover}"
            break
    return {
        "slug": series_slug,
        "title": series.name,
        "description": series.synopsis,
        "author": series.author.name,
        "artist": series.artist.name,
        "groups": groups_dict,
        "cover": cover_vol_url,
        "chapters": chapters_dict
    }
Ejemplo n.º 4
0
def series_data(series_slug):
    series = Series.objects.filter(slug=series_slug).first()
    if not series:
        raise Http404("Page not found.")
    chapters = Chapter.objects.filter(series=series).select_related("group")
    chapters_dict = {}
    groups_dict = {}
    for chapter in chapters:
        chapter_media_path = os.path.join(settings.MEDIA_ROOT, "manga",
                                          series_slug, "chapters",
                                          chapter.folder)
        ch_clean = Chapter.clean_chapter_number(chapter)
        groups_dict[str(chapter.group.id)] = chapter.group.name
        query_string = "" if not chapter.version else f"?v{chapter.version}"
        if ch_clean in chapters_dict:
            chapters_dict[ch_clean]["groups"][str(chapter.group.id)] = sorted([
                u + query_string for u in os.listdir(
                    os.path.join(chapter_media_path, str(chapter.group.id)))
            ])
            chapters_dict[ch_clean]["release_date"][str(
                chapter.group.id)] = int(chapter.uploaded_on.timestamp())
        else:
            chapters_dict[ch_clean] = {
                "volume": str(chapter.volume),
                "title": chapter.title,
                "folder": chapter.folder,
                "groups": {
                    str(chapter.group.id):
                    sorted([
                        u + query_string for u in os.listdir(
                            os.path.join(chapter_media_path,
                                         str(chapter.group.id)))
                    ])
                },
                "release_date": {
                    str(chapter.group.id): int(chapter.uploaded_on.timestamp())
                },
            }
            if chapter.wo and chapter.wo != 0:
                chapters_dict[ch_clean]["wo"] = chapter.wo
        if chapter.preferred_sort:
            try:
                chapters_dict[ch_clean]["preferred_sort"] = literal_eval(
                    chapter.preferred_sort)
            except:
                pass
    vols = Volume.objects.filter(series=series).order_by("-volume_number")
    cover_vol_url = ""
    for vol in vols:
        if vol.volume_cover:
            cover_vol_url = f"/media/{vol.volume_cover}"
            break
    return {
        "slug":
        series_slug,
        "title":
        series.name,
        "description":
        series.synopsis,
        "author":
        series.author.name,
        "artist":
        series.artist.name,
        "groups":
        groups_dict,
        "cover":
        cover_vol_url,
        "preferred_sort":
        settings.PREFERRED_SORT,
        "chapters":
        chapters_dict,
        "next_release_page":
        series.next_release_page,
        "next_release_time":
        series.next_release_time.timestamp()
        if series.next_release_time else None,
        "next_release_html":
        series.next_release_html,
    }