Skip to content

Commit

Permalink
Update version to 0.2.2-a in pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
m-krastev committed Sep 24, 2024
1 parent d8f3641 commit e827f3e
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 95 deletions.
96 changes: 77 additions & 19 deletions mtl_agent/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

ROOT = Path.home() / ".config" / "mtl_agent"


def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -91,7 +92,8 @@ def get_parser():
)
encode_parser.add_argument(
"--kwargs",
help="Additional arguments to pass to the ffmpeg command (e.g. --kwargs '-preset=veryfast -crf=23')",
help="Additional arguments to pass to the ffmpeg command (e.g. --kwargs 'vf;format=yuv240p' 'crf;23' 'map')",
nargs="*",
)
encode_parser.set_defaults(func=encode)
####################### ENCODE PARSER #######################
Expand Down Expand Up @@ -119,13 +121,15 @@ def get_parser():
)
upload_parser.set_defaults(func=upload)
####################### UPLOAD PARSER #######################

####################### PIPELINE PARSER #######################

pipeline_parser = subparsers.add_parser("pipeline")
pipeline_parser.add_argument("file", help="File to process", type=str)
pipeline_parser.add_argument(
"--subtitle", "-s", help="Ready-made subtitle file to use",
"--subtitle",
"-s",
help="Ready-made subtitle file to use",
)
pipeline_parser.add_argument(
"--audio_track",
Expand All @@ -134,29 +138,76 @@ def get_parser():
default=None,
help="Audio track to use. If not specified, will output all available audio tracks. Otherwise, must use the language code (e.g. jpn)",
)
pipeline_parser.add_argument("--profile_path", "-pp", default=None, help="Path to profile to use for uploading")
pipeline_parser.add_argument("--secrets", default=None, help="Path to secrets.json file for translation API")
pipeline_parser.add_argument("--backup_path", default=None, help="Path to backup translated file")
pipeline_parser.add_argument("--translation_provider", "-sp", default="deepl", choices=["deepl", "google"], help="Translation API provider to use")
pipeline_parser.add_argument("--subtitle_track", "-st", default=0, help="Subtitle track (English) to use for translation. Default is 0")
pipeline_parser.add_argument("--codec", "-c", type=str, default="x264", choices=["hevc", "x264"], help="Codec to use for encoding")
pipeline_parser.add_argument("--force", "-f", action="store_true", help="Whether to force the encoding process even if the file already exists")

pipeline_parser.add_argument("--video_url", "-v", help="If present, skips the vbox upload and uses the specified URL instead")
pipeline_parser.add_argument("--upload", "-u", action="store_true", help="Whether to upload to Vbox7, Animes-Portal etc.")
pipeline_parser.add_argument("--thumb", "-t", action="store_true", help="If present, changes the thumbnail of the video during the upload.")
pipeline_parser.add_argument(
"--profile_path",
"-pp",
default=None,
help="Path to profile to use for uploading",
)
pipeline_parser.add_argument(
"--secrets", default=None, help="Path to secrets.json file for translation API"
)
pipeline_parser.add_argument(
"--backup_path", default=None, help="Path to backup translated file"
)
pipeline_parser.add_argument(
"--translation_provider",
"-sp",
default="deepl",
choices=["deepl", "google"],
help="Translation API provider to use",
)
pipeline_parser.add_argument(
"--subtitle_track",
"-st",
default=0,
help="Subtitle track (English) to use for translation. Default is 0",
)
pipeline_parser.add_argument(
"--codec",
"-c",
type=str,
default="x264",
choices=["hevc", "x264"],
help="Codec to use for encoding",
)
pipeline_parser.add_argument(
"--force",
"-f",
action="store_true",
help="Whether to force the encoding process even if the file already exists",
)

pipeline_parser.add_argument(
"--video_url",
"-v",
help="If present, skips the vbox upload and uses the specified URL instead",
)
pipeline_parser.add_argument(
"--upload",
"-u",
action="store_true",
help="Whether to upload to Vbox7, Animes-Portal etc.",
)
pipeline_parser.add_argument(
"--thumb",
"-t",
action="store_true",
help="If present, changes the thumbnail of the video during the upload.",
)
pipeline_parser.set_defaults(func=pipeline)
####################### PIPELINE PARSER #######################

return parser


async def pipeline(INPUT_FILE, args):
sub = translate(args)
out = await encode(INPUT_FILE, sub, args)
if args.upload:
out = await upload(out, args)
return out


def main():
parser = get_parser()
Expand All @@ -167,7 +218,10 @@ def main():
args.root.mkdir(parents=True)

logging.basicConfig(
handlers=[logging.FileHandler(args.root / "debug.log"), logging.StreamHandler()],
handlers=[
logging.FileHandler(args.root / "debug.log"),
logging.StreamHandler(),
],
level=logging.INFO,
format="[%(asctime)s][%(levelname)-8s] %(name)s - %(message)s",
)
Expand All @@ -179,7 +233,9 @@ def main():
exit(1)

if args.headless and args.headless not in INPUT_FILE.parts:
logging.error("Headless mode invoked in non-automatically managed folder. Exiting...")
logging.error(
"Headless mode invoked in non-automatically managed folder. Exiting..."
)
exit(1)

match args.func.__name__:
Expand Down Expand Up @@ -208,5 +264,7 @@ def main():
out = asyncio.run(pipeline(INPUT_FILE, args))

print(out)


if __name__ == "__main__":
main()
18 changes: 10 additions & 8 deletions mtl_agent/providers/animes_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from .base import BaseProvider
from playwright.async_api import BrowserContext


class AnimesPortal(BaseProvider):
def __init__(self, browser: BrowserContext, config):
self.browser = browser
self.config = config
self.video_link = None

def get_cookies(self):
return [
{
Expand All @@ -17,10 +18,11 @@ def get_cookies(self):
"domain": "animes-portal.info",
},
]

async def upload(self, final_url: str, episode_num: int, animes_portal_url: str):

final_url = f'<iframe src="{final_url}" frameborder="0" allowfullscreen></iframe>'
async def upload(self, final_url: str, episode_num: int, animes_portal_url: str):
final_url = (
f'<iframe src="{final_url}" frameborder="0" allowfullscreen></iframe>'
)
page = await self.browser.new_page()
await page.goto(animes_portal_url)

Expand All @@ -44,8 +46,6 @@ async def upload(self, final_url: str, episode_num: int, animes_portal_url: str)
submit.click()
logging.info("AP: Video Uploaded")



async def upload_to_wall(
self,
final_url: str,
Expand All @@ -59,7 +59,9 @@ async def upload_to_wall(
return

page = await self.browser.new_page()
await page.goto(animes_portal_wall_url, timeout=0, wait_until="domcontentloaded")
await page.goto(
animes_portal_wall_url, timeout=0, wait_until="domcontentloaded"
)

await page.wait_for_selector("#comments > form > span > textarea")
await page.eval_on_selector(
Expand All @@ -69,4 +71,4 @@ async def upload_to_wall(
textarea = await page.query_selector("#comments > form > span > textarea")
await textarea.press("Enter", delay=1)

logging.info(f"AP: {final_url} uploaded to AP wall")
logging.info(f"AP: {final_url} uploaded to AP wall")
9 changes: 5 additions & 4 deletions mtl_agent/providers/base.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from abc import ABC, abstractmethod


class BaseProvider(ABC):
def __init__(self, config):
self.config = config

# @abstractmethod
async def upload(self):
"""Uploads a video to the provider"""
pass

# @abstractmethod
def get_cookies(self) -> list[dict]:
"""Provides the cookies for the provider"""
pass

# @abstractmethod
async def get_video_url(self) -> str:
"""Returns the video url"""
pass
pass
43 changes: 25 additions & 18 deletions mtl_agent/providers/tubebg.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,62 @@
from playwright.async_api import BrowserContext
from .base import BaseProvider


class TubeBG(BaseProvider):
upload_url = "https://www.tubebg.com/upload"

def __init__(self, browser: BrowserContext, session_id: str, user: str):
self.browser = browser
self.session_id = session_id
self.user = user

def get_cookies(self):
return [{
return [
{
"name": "PHPSESSID",
"value": self.session_id,
"path": "/",
"domain": "www.tubebg.com"
}]

async def upload(self, file_path, title, description = "", tags = "", categories= []):
"""Uploads a video to TubeBG. """
"domain": "www.tubebg.com",
}
]

async def upload(self, file_path, title, description="", tags="", categories=[]):
"""Uploads a video to TubeBG."""
page = await self.browser.new_page()
await page.goto(self.upload_url)

uploader = await page.wait_for_selector("#file")
await uploader.set_input_files(file_path)




_title = await page.wait_for_selector("#title")
await _title.fill(title)

_description = await page.wait_for_selector("#description")
await _description.fill(description)

_tags = await page.wait_for_selector("#tags")
await _tags.fill(tags)

if categories:
_categories = await page.wait_for_selector("select")
await _categories.select_option(categories)

_submit_button = await page.wait_for_selector("input[name=upload-video]")
# Ignore any obstructions to the click
await _submit_button.dispatch_event("click")

async def get_secret_link(self):
page = await self.browser.new_page()
await page.goto(f"https://www.tubebg.com/users/{self.user}")

video_url = await page.query_selector("div.music_video:nth-child(1) > div:nth-child(1) > a:nth-child(1)")

video_url = await page.query_selector(
"div.music_video:nth-child(1) > div:nth-child(1) > a:nth-child(1)"
)
video_url = await video_url.get_attribute("href")

identifier = video_url.split("/")[-2]

return "https://www.tubebg.com" + video_url, f'https://www.tubebg.com/embed/{identifier}'
return (
"https://www.tubebg.com" + video_url,
f"https://www.tubebg.com/embed/{identifier}",
)
26 changes: 15 additions & 11 deletions mtl_agent/providers/vbox7.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def __init__(self, browser: BrowserContext, **config):
self.browser = browser
self.video_link = None

async def upload(self,filepath: str,
title: str = "",
description: str = "",
tags: str = "",
private=False,
async def upload(
self,
filepath: str,
title: str = "",
description: str = "",
tags: str = "",
private=False,
):
# navigate
page = await self.browser.new_page()
Expand Down Expand Up @@ -50,7 +52,7 @@ async def upload(self,filepath: str,
except:
# video got uploaded immediately
final_url = page.url

self.video_link = final_url
return final_url

Expand All @@ -73,23 +75,23 @@ def get_cookies(self, config: dict) -> list[dict]:
"value": config["larabox_session"],
"path": "/",
"domain": ".vbox7.com",
}
]
},
]

async def get_video_url(self) -> str:
page = await self.browser.new_page()
await page.goto(self.video_link)

await page.wait_for_selector("#html5player[data-src]")
url = await page.get_attribute("#html5player", "data-src")
url = url.replace(".mpd", "_1080.mp4")

# if requests.get(url).status_code == 404:
# raise Exception("VBOX7: Secret link not found")

return url

async def change_thumbnail(self, path_to_img: str):

page = await self.browser.new_page()
await page.goto(self.video_link)

Expand All @@ -98,7 +100,9 @@ async def change_thumbnail(self, path_to_img: str):
# if await page.title() != props["title"].format(episode_num):
await page.wait_for_selector("#html5player[data-src]")

await page.goto(f"https://www.vbox7.com/video/{self.video_link.rpartition(':')[-1]}/edit")
await page.goto(
f"https://www.vbox7.com/video/{self.video_link.rpartition(':')[-1]}/edit"
)

input_field = await page.query_selector("#file_change_thumb")

Expand Down
Loading

0 comments on commit e827f3e

Please sign in to comment.