Skip to content

Commit

Permalink
Merge pull request #24 from SheepYY039/777tv
Browse files Browse the repository at this point in the history
777tv
  • Loading branch information
jyyyeung authored Jul 12, 2023
2 parents f5ef85f + 3688a50 commit abe7fe4
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 7 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## v1.0.1 (2023-07-12)

### Refactor

- added all sources import in __init__.py and generalized ssstv urls into source_url and relative path

## v1.0.0 (2023-07-11)

### Feat

- **source**: Added new media source 777tv

### Fix

- websockets auto patch failed due to pyppeteer==1.0.2 dependencies

## v1.0.0a0 (2023-07-11)

### Fix
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespaces = false # to disable scanning PEP 420 namespaces (true by default)
[tool.commitizen]
name = "cz_conventional_commits"
version_scheme = "pep440"
version = "1.0.0a0"
version = "1.0.1"
tag_format = "v$version"
version_files = [
"VERSION",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typer==0.9.0
typing_extensions==4.7.1
urllib3==1.26.16
w3lib==2.1.1
websockets==11.0.3
websockets~=10.0
zipp==3.16.0

mkdocstrings==0.22.0
Expand Down
1 change: 1 addition & 0 deletions tvsd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional

import typer
from rich import print

from tvsd import __app_name__, __version__
from tvsd.actions import search_media_and_download
Expand Down
16 changes: 13 additions & 3 deletions tvsd/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
import sys
from typing import TYPE_CHECKING, Any, Literal, Union, List
from bs4 import PageElement
from tvsd.sources import *
from rich.table import Table
from rich.console import Console


import typer


from tvsd import sources
from tvsd.source import Source
from tvsd.sources.xiao_bao import XiaoBao
from tvsd.sources.olevod import OLEVOD

from tvsd.utils import LOGGER

if TYPE_CHECKING:
from tvsd.season import Season
from tvsd.show import Show

console = Console()


class SearchQuery:
"""Searches for a show based on query"""
Expand Down Expand Up @@ -86,6 +90,7 @@ def find_shows_online(self):
LOGGER.debug("Searching for %s", self._query)

for file in dir(sources):
LOGGER.debug(f"Found {file}...")
if not file.startswith("__"):
for cls_name, cls_obj in inspect.getmembers(
sys.modules[f"tvsd.sources.{file}"]
Expand All @@ -100,9 +105,14 @@ def find_shows_online(self):
LOGGER.info(f"Searching {cls_name}...")
query_results += cls_obj().query_from_source(self._query)

table = Table("index", "Title", "Source", "Note")

for result_index, result in enumerate(query_results):
print(result_index, result.title, result.source.source_name, result.note)
table.add_row(
str(result_index), result.title, result.source.source_name, result.note
)

console.print(table)
self._chosen_show = query_results[typer.prompt(text="请选择你下载的节目", type=int)]

@property
Expand Down
2 changes: 1 addition & 1 deletion tvsd/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _get_result_note(self, query_result: BeautifulSoup) -> str:
"""
return ""

@abstractmethod
# @abstractmethod
def _get_result_source_id(self, query_result: BeautifulSoup) -> str:
"""Gets the result source id
Expand Down
2 changes: 1 addition & 1 deletion tvsd/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print()
__all__ = ["xiao_bao", "olevod", "ssstv"]
93 changes: 93 additions & 0 deletions tvsd/sources/ssstv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import re
from typing import Any

from bs4 import BeautifulSoup, ResultSet, Tag

from tvsd.source import Source


class SSSTV(Source):
"""777tv class"""

source_url = "https://777tv.tw"

def __init__(self):
super().__init__()
self.__status__ = "active"

### SEARCHING FOR A SHOW ###

def _search_url(self, search_query: str) -> str:
return f"{self.source_url}/vodsearch/-------------.html?wd={search_query}"

def _get_query_results(self, query_result_soup: BeautifulSoup) -> ResultSet[Any]:
return query_result_soup.find_all("div", attrs={"class": "module-search-item"})

##### PARSE EPISODE DETAILS FROM URL #####

def _set_relative_episode_url(self, soup: Tag) -> str:
return soup["href"]

def _set_episode_title(self, soup: Tag) -> str:
return soup.find("span").get_text()

##### PARSE SEASON FROM QUERY RESULT #####

def _get_result_note(self, query_result: BeautifulSoup) -> str:
note = query_result.find("a", attrs={"class": "video-serial"}).get_text()
return note

def _get_result_details_url(self, query_result: BeautifulSoup) -> str:
relative_url = query_result.find("a", attrs={"class": "video-serial"})["href"]

return f"{self.source_url}{relative_url}"

#### PARSE SEASON DETAILS FROM DETAILS URL ####

def _set_season_title(self, soup: BeautifulSoup):
return soup.find("h1", attrs={"class": "page-title"}).get_text()

def _set_season_description(self, soup: BeautifulSoup):
return (
soup.find("div", attrs={"class": "video-info-content"})
.find("span")
.get_text()
)

def _set_season_episodes(self, soup: BeautifulSoup):
return (
soup.find("div", attrs={"class": "module-player-list"})
.find("div", attrs={"class": "scroll-content"})
.find_all("a")
)

def _set_season_year(self, soup: BeautifulSoup):
return soup.find(
"a",
{
"class": "tag-link",
"href": re.compile(r"/vodshow/\d{2}-+\d{4}.html"),
},
).get_text()

######## FETCH EPISODE M3U8 ########

def _episode_url(self, relative_episode_url: str) -> str:
return self.source_url + relative_episode_url

def _set_episode_script(self, episode_soup: BeautifulSoup) -> str:
return str(
episode_soup.find("div", attrs={"class": "player-wrapper"}).find("script")
)

def _set_episode_m3u8(self, episode_script: str) -> str:
print(episode_script)
return (
re.findall(
r"\"url\":\"https:[\w\d\-\_\\\/\.]*\.m3u8\"",
episode_script,
)[0]
.replace("\\", "")
.replace('"url":', "")
.replace('"', "")
)

0 comments on commit abe7fe4

Please sign in to comment.