| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2025 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for https://fikfap.com/""" |
| 10 |
|
| 11 |
from .common import Extractor, Message |
| 12 |
from .. import text |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?fikfap\.com" |
| 15 |
|
| 16 |
|
| 17 |
class FikfapExtractor(Extractor): |
| 18 |
"""Base class for fikfap extractors""" |
| 19 |
category = "fikfap" |
| 20 |
root = "https://fikfap.com" |
| 21 |
root_api = "https://api.fikfap.com" |
| 22 |
directory_fmt = ("{category}", "{author[username]}") |
| 23 |
filename_fmt = "{postId} {label[:240]}.{extension}" |
| 24 |
archive_fmt = "{postId}" |
| 25 |
|
| 26 |
def items(self): |
| 27 |
headers = { |
| 28 |
"Referer" : self.root + "/", |
| 29 |
"Origin" : self.root, |
| 30 |
"Sec-Fetch-Dest": "empty", |
| 31 |
"Sec-Fetch-Mode": "cors", |
| 32 |
"Sec-Fetch-Site": "cross-site", |
| 33 |
} |
| 34 |
|
| 35 |
for post in self.posts(): |
| 36 |
if url := post.get("videoFileOriginalUrl"): |
| 37 |
post["extension"] = text.ext_from_url(url) |
| 38 |
elif url := post.get("videoStreamUrl"): |
| 39 |
url = "ytdl:" + url |
| 40 |
post["extension"] = "mp4" |
| 41 |
post["_ytdl_manifest"] = "hls" |
| 42 |
post["_ytdl_manifest_headers"] = headers |
| 43 |
else: |
| 44 |
self.log.warning("%s: No video available", post["postId"]) |
| 45 |
continue |
| 46 |
|
| 47 |
post["date"] = self.parse_datetime_iso(post["createdAt"]) |
| 48 |
post["date_updated"] = self.parse_datetime_iso(post["updatedAt"]) |
| 49 |
post["tags"] = [t["label"] for t in post["hashtags"]] |
| 50 |
post["filename"] = post["label"] |
| 51 |
|
| 52 |
yield Message.Directory, "", post |
| 53 |
yield Message.Url, url, post |
| 54 |
|
| 55 |
def request_api(self, url, params): |
| 56 |
return self.request_json(url, params=params, headers={ |
| 57 |
"Authorization-Anonymous": "2527cc30-c3c5-41be-b8bb-104b6ea7a206", |
| 58 |
"IsLoggedIn" : "false", |
| 59 |
"IsPWA" : "false", |
| 60 |
}) |
| 61 |
|
| 62 |
|
| 63 |
class FikfapPostExtractor(FikfapExtractor): |
| 64 |
subcategory = "post" |
| 65 |
pattern = BASE_PATTERN + r"/(?:user/[^/?#]+/)?post/(\d+)" |
| 66 |
example = "https://fikfap.com/user/USER/post/12345" |
| 67 |
|
| 68 |
def posts(self): |
| 69 |
pid = self.groups[0] |
| 70 |
|
| 71 |
url = f"{self.root_api}/posts/{pid}" |
| 72 |
post = self.request_api(url, None) |
| 73 |
|
| 74 |
if post["postId"] == int(pid): |
| 75 |
return (post,) |
| 76 |
raise self.exc.NotFoundError("post") |
| 77 |
|
| 78 |
|
| 79 |
class FikfapUserExtractor(FikfapExtractor): |
| 80 |
subcategory = "user" |
| 81 |
pattern = BASE_PATTERN + r"/user/([^/?#]+)" |
| 82 |
example = "https://fikfap.com/user/USER" |
| 83 |
|
| 84 |
def posts(self): |
| 85 |
user = self.groups[0] |
| 86 |
|
| 87 |
url = f"{self.root_api}/profile/username/{user}/posts" |
| 88 |
params = {"amount": "21"} |
| 89 |
|
| 90 |
while True: |
| 91 |
data = self.request_api(url, params) |
| 92 |
|
| 93 |
yield from data |
| 94 |
|
| 95 |
if len(data) < 21: |
| 96 |
return |
| 97 |
params["afterId"] = data[-1]["postId"] |
| 98 |
|
| 99 |
|
| 100 |
class FikfapHashtagExtractor(FikfapExtractor): |
| 101 |
subcategory = "hashtag" |
| 102 |
directory_fmt = ("{category}", "{hashtag}") |
| 103 |
pattern = BASE_PATTERN + r"/hash/([^/?#]+)" |
| 104 |
example = "https://fikfap.com/hash/HASH" |
| 105 |
|
| 106 |
def posts(self): |
| 107 |
self.kwdict["hashtag"] = hashtag = self.groups[0] |
| 108 |
|
| 109 |
url = f"{self.root_api}/hashtags/label/{hashtag}/posts" |
| 110 |
params = {"amount": "21"} |
| 111 |
|
| 112 |
while True: |
| 113 |
data = self.request_api(url, params) |
| 114 |
|
| 115 |
yield from data |
| 116 |
|
| 117 |
if len(data) < 21: |
| 118 |
return |
| 119 |
params["afterId"] = data[-1]["postId"] |