Skip to content

Commit

Permalink
local
Browse files Browse the repository at this point in the history
local
  • Loading branch information
wingeva1986 committed Oct 4, 2023
1 parent 6666ec4 commit f95a056
Show file tree
Hide file tree
Showing 12 changed files with 3,081 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Jvav/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__pycache__
.vscode
.DS_Store
.idea

# for jvav pkg
/dist
jvav.egg-info

# for jvav.exe
*.spec
/jvav/dist
/jvav/build
674 changes: 674 additions & 0 deletions Jvav/LICENSE

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Jvav/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Include
include README.md
include LICENSE
include requirements.txt

## Exclude
recursive-exclude tests *
68 changes: 68 additions & 0 deletions Jvav/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Jvav

Useful tools for Jav.

## INSTALL

```
# python >= 3.7.9
pip install jvav -U
```

## LIB

- DmmUtil
- JavDbUtil
- JavLibUtil
- JavBusUtil
- AvgleUtil
- MagnetUtil
- SukebeiUtil
- WikiUtil
- TransUtil
- SgpUtil

```py
# A sample for DmmUtil
import jvav

util = jvav.DmmUtil(proxy_addr='http://127.0.0.1:7890')
util.get_nice_avs_by_star_name('小倉由菜')
util.get_score_by_id('cawd-441')
util.get_all_top_stars()
```

## CMD

```
$ jvav -h
usage: cmd.py [-h] [-v] [-av1 AV1] [-av2 AV2] [-nc] [-uc] [-sr SR] [-srn SRN]
[-tg TG] [-pv1 PV1] [-pv2 PV2] [-tp] [-p PROXY]
optional arguments:
-h, --help show this help message and exit
-v, --version View the version number
-av1 AV1 Followed by a code, search for the code on JavBus
-av2 AV2 Followed by a code, search for the code on Sukebei
-nc Filter out high-definition torrents with subtitles
-uc Filter out uncensored torrents
-sr SR Followed by an actress name, get a list of high-rated codes based on the actress name
-srn SRN Followed by an actress name, get a list of the latest codes based on the actress name
-tg TG Followed by a keyword, search for codes based on the keyword
-pv1 PV1 Followed by a code, get the preview video corresponding to the code from DMM
-pv2 PV2 Followed by a code, get the preview video corresponding to the code from Avgle
-tp Get the top 25 ranking of DMM actresses
-p PROXY, --proxy PROXY
Followed by the proxy server address, by default reads the value of the http_proxy environment variable.
```

## TODO

The following are some functions to be implemented, and I look forward to your contribution~

- [ ] cache the successful query results locally
- [x] support javdb.com (Thanks: [@Steven-Fake](https://github.com/Steven-Fake))
- [ ] support db.msin.jp
- [ ] support JavDbUtil in cmd
- [ ] support SgpUtil in cmd
- [ ] support JavDbUtil in cmd
35 changes: 35 additions & 0 deletions Jvav/jvav/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: UTF-8 -*-
from jvav.utils import (
BaseUtil,
JavLibUtil,
DmmUtil,
JavBusUtil,
AvgleUtil,
MagnetUtil,
SukebeiUtil,
WikiUtil,
TransUtil,
JavDbUtil,
SjsUtil,
SgpUtil,
)

__version__ = "1.4.1"

VERSION = __version__

__all__ = [
VERSION,
BaseUtil,
JavLibUtil,
DmmUtil,
JavBusUtil,
AvgleUtil,
MagnetUtil,
SukebeiUtil,
WikiUtil,
TransUtil,
JavDbUtil,
SjsUtil,
SgpUtil
]
202 changes: 202 additions & 0 deletions Jvav/jvav/cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# -*- coding: UTF-8 -*-
import os
import sys
import json
import logging
import argparse
import langdetect
import jvav

PATH_ROOT = os.path.expanduser("~") + "/.jvav"
if not os.path.exists(PATH_ROOT):
os.makedirs(PATH_ROOT)


class Logger:
def __init__(self, log_level: int, path_log_file: str):
"""初始化日志记录器
:param int log_level: 记录级别
:param str path_log_file: 日志文件位置
"""
self.logger = logging.getLogger()
self.logger.addHandler(self.get_file_handler(path_log_file))
self.logger.addHandler(logging.StreamHandler(sys.stdout))
self.logger.setLevel(log_level)

def get_file_handler(self, file):
file_handler = logging.FileHandler(file)
file_handler.setFormatter(
logging.Formatter("[%(asctime)s] %(levelname)s: %(message)s")
)
return file_handler


LOG = Logger(logging.INFO, f"{PATH_ROOT}/log.txt").logger


class JvavArgsParser:
def __init__(self):
parser = argparse.ArgumentParser()
# Check version
parser.add_argument(
"-v", "--version", action="store_true", help="Check version"
)
# Search number
parser.add_argument(
"-av1",
type=str,
default="",
help="Followed by a code, search this code on JavBus",
)
parser.add_argument(
"-av2",
type=str,
default="",
help="Followed by a code, search this code on Sukebei",
)
parser.add_argument(
"-nc",
action="store_true",
help="Filter out high-definition subtitles magnet links",
)
parser.add_argument(
"-uc", action="store_true", help="Filter out uncoded magnet links"
)
# Search actor
parser.add_argument(
"-sr",
type=str,
default="",
help="Followed by an actress name, get a list of high-rated codes based on the actress name",
)
parser.add_argument(
"-srn",
type=str,
default="",
help="Followed by an actress name, get a list of the most recent codes based on the actress name",
)
# Search number by keyword
parser.add_argument(
"-tg",
type=str,
default="",
help="Followed by a keyword, search for codes based on the keyword",
)
# Get preview video
parser.add_argument(
"-pv1",
type=str,
default="",
help="Followed by a code, get the corresponding preview video of the code on DMM",
)
parser.add_argument(
"-pv2",
type=str,
default="",
help="Follow a code, get the corresponding preview video of the code on Avgle",
)
# Get leaderboard
parser.add_argument(
"-tp", action="store_true", help="Get the top 25 ranking of DMM actresses"
)
# Configure proxy
parser.add_argument(
"-p",
"--proxy",
type=str,
default="",
help="Followed by a proxy server address (by default reads the value of the environment variable http_proxy)",
)
self.parser = parser
self.args = None

def handle_code(self, code: int, res):
"""处理结果
:param int code: 状态码
:param any res: 结果
"""
if code != 200:
LOG.error(code)
return
LOG.info(json.dumps(res, indent=4, ensure_ascii=False))

def parse(self):
"""解析命令行参数"""
parser = self.parser
self.args = parser.parse_args()

def exec(self):
"""根据参数表自行相应操作"""
if not self.args:
self.parser.print_help()
return
args = self.args
env_proxy = os.getenv("http_proxy")
if args.version:
print(f"jvav-{jvav.VERSION}")
return
if args.proxy == "" and env_proxy:
args.proxy = env_proxy
if args.av1 != "":
self.handle_code(
*jvav.JavBusUtil(proxy_addr=args.proxy).get_av_by_id(
id=args.av1, is_nice=args.nc, is_uncensored=args.uc
)
)
elif args.av2 != "":
self.handle_code(
*jvav.SukebeiUtil(proxy_addr=args.proxy).get_av_by_id(
id=args.av2, is_nice=args.nc, is_uncensored=args.uc
)
)
elif args.tp:
self.handle_code(*jvav.DmmUtil(proxy_addr=args.proxy).get_top_stars(1))
elif args.sr != "" or args.srn != "":
star_name = args.sr if args.sr != "" else args.srn
flag_srn = True if args.srn != "" else False
if langdetect.detect(star_name) != "ja": # zh
wiki_json = jvav.WikiUtil(proxy_addr=args.proxy).get_wiki_page_by_lang(
topic=star_name, from_lang="zh", to_lang="ja"
)
if wiki_json and wiki_json["lang"] == "ja":
star_name = wiki_json["title"]
if not flag_srn:
self.handle_code(
*jvav.DmmUtil(proxy_addr=args.proxy).get_nice_avs_by_star_name(
args.sr
)
)
else:
self.handle_code(
*jvav.JavBusUtil(proxy_addr=args.proxy).get_new_ids_by_star_name(
args.srn
)
)
elif args.pv1 != "":
self.handle_code(
*jvav.DmmUtil(proxy_addr=args.proxy).get_pv_by_id(args.pv1)
)
elif args.pv2 != "":
self.handle_code(
*jvav.AvgleUtil(proxy_addr=args.proxy).get_pv_by_id(args.pv2)
)
elif args.tg != "":
self.handle_code(
*jvav.JavDbUtil(proxy_addr=args.proxy).get_ids_by_tag(args.tg)
)
else:
self.parser.print_help()


def main():
parser = JvavArgsParser()
parser.parse()
parser.exec()


# pyinstaller --onefile cmd.py --name jvav # to build an exe named jvav.exe
# python -m jvav.cmd
if __name__ == "__main__":
main()
Loading

0 comments on commit f95a056

Please sign in to comment.