Skip to content

Commit 755724b

Browse files
authored
Merge pull request #6 from Dibakarroy1997/enable-ci-ww31.7
Enable CI
2 parents 79a6040 + 45ce56f commit 755724b

File tree

9 files changed

+160
-72
lines changed

9 files changed

+160
-72
lines changed

.github/workflows/pull-request.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
on: pull_request
3+
4+
jobs:
5+
ci:
6+
strategy:
7+
fail-fast: true
8+
matrix:
9+
python-version: ["3.8", "3.9", "3.10"]
10+
poetry-version: ["1.1.14"]
11+
os: [ubuntu-latest, macos-latest, windows-latest]
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Run image
19+
uses: abatilo/[email protected]
20+
with:
21+
poetry-version: ${{ matrix.poetry-version }}
22+
- name: Install dependencies
23+
run: poetry install
24+
- name: Virtual environment info
25+
run: poetry env info
26+
- name: Run flake8 (along with black, isort and bandit wrapper)
27+
run: poetry run flake8 src tests
28+
- name: Run mypy
29+
run: poetry run mypy --install-types --non-interactive --ignore-missing-imports src
30+
- name: Run pytest
31+
run: poetry run pytest

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Python package
1+
name: CD
22
on:
33
push:
44
tags:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ cython_debug/
160160
#.idea/
161161

162162
# VS Code
163-
.vscode/
163+
.vscode/

poetry.lock

Lines changed: 94 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ readme = "README.md"
66
authors = ["Debakar Roy <[email protected]>"]
77

88
[tool.poetry.dependencies]
9-
python = "^3.10"
10-
requests = "^2.28.1"
9+
python = "^3.8"
1110
click = "^8.1.3"
12-
validators = "^0.20.0"
11+
requests = "^2.28.1"
1312
pydantic = "^1.9.1"
13+
validators = "^0.20.0"
1414
yt-dlp = "^2022.7.18"
1515

1616
[tool.poetry.dev-dependencies]
17-
pytest-cov = "^3.0.0"
17+
datamodel-code-generator = { extras = ["http"], version = "^0.13.0" }
1818
flake8 = "^4.0.1"
19-
black = "^22.6.0"
2019
flake8-bugbear = "^22.7.1"
20+
flake8-black = "^0.3.3"
21+
flake8-bandit = "^3.0.0"
2122
flake8-comprehensions = "^3.10.0"
22-
pep8-naming = "^0.13.0"
2323
flake8-isort = "^4.1.1"
24-
flake8-bandit = "^3.0.0"
25-
datamodel-code-generator = {extras = ["http"], version = "^0.13.0"}
24+
pep8-naming = "^0.13.0"
25+
pytest-cov = "^3.0.0"
26+
mypy = "^0.971"
2627

2728
[tool.black]
2829
line-length = 120

src/kisskh_downloader/cli.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from pathlib import Path
3+
from typing import List, Union
34
from urllib.parse import parse_qs, urlparse
45

56
import click
@@ -44,18 +45,22 @@ def dl(
4445
first: int,
4546
last: int,
4647
quality: str,
47-
sub_langs: list[str],
48-
output_dir: Path | str,
48+
sub_langs: List[str],
49+
output_dir: Union[Path, str],
4950
) -> None:
5051
kisskh_api = KissKHApi()
5152
downloader = Downloader()
5253
if validators.url(drama_url_or_name):
5354
parsed_url = urlparse(drama_url_or_name)
54-
drama_id = parse_qs(parsed_url.query)["id"][0]
55+
drama_id = int(parse_qs(parsed_url.query)["id"][0])
5556
drama_name = parsed_url.path.split("/")[-1].replace("-", "_")
5657
else:
5758
drama = kisskh_api.get_drama_by_query(drama_url_or_name)
58-
drama_id, drama_name = drama.id, drama.title
59+
if drama is None:
60+
print("No drama found with the query provided...")
61+
return None
62+
drama_id = drama.id
63+
drama_name = drama.title
5964

6065
episode_ids = kisskh_api.get_episode_ids(drama_id=drama_id, start=first, stop=last)
6166

src/kisskh_downloader/downloader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from pathlib import Path
3+
from typing import List
34
from urllib.parse import urlparse
45

56
import requests
@@ -25,7 +26,7 @@ def download_video_from_stream_url(self, video_stream_url: str, filepath: str, q
2526
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
2627
ydl.download(video_stream_url)
2728

28-
def download_subtitles(self, subtitles: list[SubItem], filepath: str) -> None:
29+
def download_subtitles(self, subtitles: List[SubItem], filepath: str) -> None:
2930
"""Download subtitles
3031
3132
:param subtitles: list of all subtitles

src/kisskh_downloader/kisskh_api.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import sys
2+
from typing import Dict, List, Optional
23
from urllib.parse import urljoin
34

45
import requests
56

67
from kisskh_downloader.models.drama import Drama
78
from kisskh_downloader.models.search import DramaInfo, Search
8-
from kisskh_downloader.models.sub import Sub
9+
from kisskh_downloader.models.sub import Sub, SubItem
910

1011

1112
class KissKHApi:
@@ -61,7 +62,7 @@ def _request(self, url: str) -> requests.models.Response:
6162
response.raise_for_status()
6263
return response
6364

64-
def get_episode_ids(self, drama_id: int, start: int = 1, stop: int = sys.maxsize) -> dict[int, tuple[str, str]]:
65+
def get_episode_ids(self, drama_id: int, start: int = 1, stop: int = sys.maxsize) -> Dict[int, int]:
6566
"""Get episode ids for a specific drama
6667
6768
:param drama_id: drama id
@@ -74,7 +75,7 @@ def get_episode_ids(self, drama_id: int, start: int = 1, stop: int = sys.maxsize
7475
drama = Drama.parse_obj(response.json())
7576
return drama.get_episodes_ids(start=start, stop=stop)
7677

77-
def get_subtitles(self, episode_id: int, *language_filter: str) -> list[str]:
78+
def get_subtitles(self, episode_id: int, *language_filter: str) -> List[SubItem]:
7879
"""Get subtitle details for a specific episode
7980
8081
:param episode_id: episode id
@@ -84,13 +85,13 @@ def get_subtitles(self, episode_id: int, *language_filter: str) -> list[str]:
8485
"""
8586
subtitle_api_url = self._subtitle_api_url(episode_id=episode_id)
8687
response = self._request(subtitle_api_url)
87-
subtitles = Sub.parse_obj(response.json())
88-
subtitle_urls = []
88+
subtitles: Sub = Sub.parse_obj(response.json())
89+
filtered_subtitles: List[SubItem] = []
8990
if "all" in language_filter:
90-
subtitle_urls.extend(subtitle for subtitle in subtitles)
91+
filtered_subtitles.extend(subtitle for subtitle in subtitles)
9192
elif language_filter:
92-
subtitle_urls.extend(subtitle for subtitle in subtitles if subtitle.land in language_filter)
93-
return subtitle_urls
93+
filtered_subtitles.extend(subtitle for subtitle in subtitles if subtitle.land in language_filter)
94+
return filtered_subtitles
9495

9596
def search_dramas_by_query(self, query: str) -> Search:
9697
"""Get all drama for a specific search query
@@ -112,7 +113,7 @@ def get_stream_url(self, episode_id: int) -> str:
112113
response = self._request(stream_api_url)
113114
return response.json().get("Video")
114115

115-
def get_drama_by_query(self, query: str) -> DramaInfo:
116+
def get_drama_by_query(self, query: str) -> Optional[DramaInfo]:
116117
"""Select specific drama from a search query
117118
118119
:param query: search string
@@ -121,7 +122,7 @@ def get_drama_by_query(self, query: str) -> DramaInfo:
121122
dramas = self.search_dramas_by_query(query=query)
122123
if len(dramas) == 0:
123124
print(f"No drama with query {query} found! " "Make sure you spelled everything correct.")
124-
return
125+
return None
125126

126127
user_selection = 0
127128
while user_selection < 1 or user_selection > len(dramas) + 1:

src/kisskh_downloader/models/drama.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any, Dict, List
44

55
from pydantic import BaseModel, Field
66

@@ -31,7 +31,7 @@ def __init__(self, **data: Any) -> None:
3131
data["episodes"] = sorted(data["episodes"], key=lambda episode: episode["number"])
3232
super().__init__(**data)
3333

34-
def get_episodes_ids(self, start: int, stop: int) -> dict[int, tuple[str, str]]:
34+
def get_episodes_ids(self, start: int, stop: int) -> Dict[int, int]:
3535
episode_ids = {}
3636
if start < self.episodes[0].number or start > self.episodes[-1].number:
3737
start = self.episodes[0].number

0 commit comments

Comments
 (0)