Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delete tg post video & update FinalRip & store relative path #10

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

Tohrusky
Copy link
Member

@Tohrusky Tohrusky commented Dec 19, 2024

#7
#8
#9

Summary by Sourcery

Refactor the pipeline to replace video uploads with text posts to Telegram channels, and update the task execution to support video slicing and timeout parameters. Simplify deployment by removing the Telegram bot API service from Docker Compose. Enhance the task building process to include server configuration and use relative paths for file operations. Update tests to align with these changes.

New Features:

  • Introduce support for specifying video slicing and timeout parameters in the encoding process.

Enhancements:

  • Refactor the task building process to include server configuration details.
  • Update the pipeline to use relative paths for file operations, improving flexibility and portability.

Deployment:

  • Remove the Telegram bot API service from the Docker Compose configuration, simplifying the deployment setup.

Tests:

  • Update tests to reflect changes in the Telegram posting functionality and task execution.

Copy link

sourcery-ai bot commented Dec 19, 2024

Reviewer's Guide by Sourcery

This PR implements several significant changes to improve the pipeline's functionality and reliability. The main changes include updating the TaskInfo model with new fields, modifying the FinalRip encoding process to support video slicing options, replacing video uploads with text-only posts in Telegram, and removing the local Telegram bot API server dependency.

Sequence diagram for the updated pipeline process

sequenceDiagram
    participant User
    participant Pipeline
    participant TaskExecutor
    participant FinalRipClient
    participant TGChannelSender
    User->>Pipeline: Start pipeline
    Pipeline->>TaskExecutor: Submit task
    TaskExecutor->>FinalRipClient: Start FinalRip task
    FinalRipClient-->>TaskExecutor: Task completed
    TaskExecutor->>TGChannelSender: Send text post
    TGChannelSender-->>TaskExecutor: Post successful
Loading

Updated class diagram for TaskInfo

classDiagram
    class TaskInfo {
        +DirectoryPath download_path
        +str uploader
        +str script_content
        +str param_content
        +Optional~bool~ slice
        +Optional~int~ timeout
    }
Loading

File-Level Changes

Change Details Files
Enhanced TaskInfo model and configuration handling
  • Added download_path, slice, and timeout fields to TaskInfo model
  • Renamed script/param fields to script_content/param_content for clarity
  • Updated build_task_info to include server configuration
  • Added slice and timeout options to RSS configuration
animepipeline/loop.py
animepipeline/config/rss.py
conf/rss.yml
Improved FinalRip encoding process
  • Added support for configurable video slicing
  • Implemented timeout settings for encoding tasks
  • Updated path handling to use relative paths
  • Increased sleep intervals between progress checks
  • Removed automatic merge retry logic
animepipeline/loop.py
animepipeline/encode/finalrip.py
animepipeline/encode/type.py
Simplified Telegram posting functionality
  • Replaced video uploads with text-only posts
  • Removed local Telegram bot API server dependency
  • Simplified TGChannelSender configuration
  • Renamed pipeline_tg to pipeline_post for clarity
animepipeline/post/tg.py
animepipeline/config/server.py
deploy/docker-compose.yml
deploy/docker-compose-dev.yml

Possibly linked issues

  • Initial commit #1: PR deletes Telegram video posting, aligning with issue's focus on removing video upload method.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Tohrusky - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The removal of retry logic for failed merges in pipeline_finalrip() could reduce reliability. Consider keeping the retry mechanism or document why it's no longer needed.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 4 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -38,7 +37,7 @@ async def test_start_task(self) -> None:
s = v
print(repr(s))
try:
await self.finalrip.start_task(encode_param=p, script=s, video_key=video_key)
await self.finalrip.start_task(encode_param=p, script=s, video_key=video_key, slice=True, timeout=10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test should verify the new slice and timeout parameters

The test should include cases for different combinations of slice and timeout values to ensure they're properly handled. Also, consider testing the default values.

Suggested implementation:

@pytest.mark.skipif(os.environ.get("GITHUB_ACTIONS") == "true", reason="Only test locally")
class Test_FinalRip:
    @pytest.fixture
    def mock_video_key(self):
        return "test_video_key"

    @pytest.fixture
    def mock_encode_param(self):
        return {"param": "test"}

    @pytest.fixture
    def mock_script(self):
        return "test_script"

    def setup_method(self) -> None:
            s = v
        print(repr(s))
        try:
            await self.finalrip.start_task(encode_param=p, script=s, video_key=video_key, slice=True, timeout=10)
        except Exception as e:
            print(e)

    @pytest.mark.asyncio
    async def test_start_task_default_values(self, mock_video_key, mock_encode_param, mock_script):
        # Test with default values (assuming slice=False and no timeout by default)
        await self.finalrip.start_task(
            encode_param=mock_encode_param,
            script=mock_script,
            video_key=mock_video_key
        )
        # Add assertions based on expected behavior with default values

    @pytest.mark.asyncio
    async def test_start_task_with_slice(self, mock_video_key, mock_encode_param, mock_script):
        # Test with slice=True
        await self.finalrip.start_task(
            encode_param=mock_encode_param,
            script=mock_script,
            video_key=mock_video_key,
            slice=True
        )
        # Add assertions for slice=True behavior

    @pytest.mark.asyncio
    async def test_start_task_with_timeout(self, mock_video_key, mock_encode_param, mock_script):
        # Test with specific timeout value
        await self.finalrip.start_task(
            encode_param=mock_encode_param,
            script=mock_script,
            video_key=mock_video_key,
            timeout=15
        )
        # Add assertions for timeout behavior

    @pytest.mark.asyncio
    async def test_start_task_with_slice_and_timeout(self, mock_video_key, mock_encode_param, mock_script):
        # Test with both slice and timeout
        await self.finalrip.start_task(
            encode_param=mock_encode_param,
            script=mock_script,
            video_key=mock_video_key,
            slice=True,
            timeout=10
        )
        # Add assertions for combined slice and timeout behavior

    @pytest.mark.asyncio
    async def test_start_task_invalid_timeout(self, mock_video_key, mock_encode_param, mock_script):
        # Test with invalid timeout value
        with pytest.raises(ValueError):
            await self.finalrip.start_task(
                encode_param=mock_encode_param,
                script=mock_script,
                video_key=mock_video_key,
                timeout=-1
            )

To complete these tests, you'll need to:

  1. Add appropriate assertions in each test case based on the expected behavior of your FinalRip class
  2. Possibly mock any external dependencies or services that FinalRip.start_task might use
  3. Add any necessary setup in the setup_method if required by your implementation
  4. Adjust the mock fixtures based on your actual parameter requirements

Comment on lines +15 to 17
task_info = build_task_info(torrent_info, cfg, rss_config, server_config)
assert isinstance(task_info, TaskInfo)
print(task_info)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test should verify the new TaskInfo fields

Add specific assertions to verify that download_path, slice, and timeout are correctly set in the TaskInfo object. Also, test error cases when server_config is invalid or missing.

Suggested implementation:

def test_build_task_info() -> None:
    rss_config: RSSConfig = RSSConfig.from_yaml(CONFIG_PATH / "rss.yml")
    server_config: ServerConfig = ServerConfig.from_yaml(CONFIG_PATH / "server.yml")
    for cfg in rss_config.nyaa:
        torrent_info_list = parse_nyaa(cfg)

        for torrent_info in torrent_info_list:
            task_info = build_task_info(torrent_info, cfg, rss_config, server_config)
            assert isinstance(task_info, TaskInfo)

            # Verify TaskInfo fields are set correctly
            assert task_info.download_path == server_config.download_path
            assert task_info.slice == server_config.slice
            assert task_info.timeout == server_config.timeout

def test_build_task_info_invalid_server_config() -> None:
    rss_config: RSSConfig = RSSConfig.from_yaml(CONFIG_PATH / "rss.yml")
    cfg = next(iter(rss_config.nyaa))  # Get first config for testing
    torrent_info = next(iter(parse_nyaa(cfg)))  # Get first torrent info

    # Test with missing server_config
    with pytest.raises(TypeError):
        build_task_info(torrent_info, cfg, rss_config, None)

    # Test with invalid server_config values
    invalid_server_config = ServerConfig.from_yaml(CONFIG_PATH / "server.yml")
    invalid_server_config.download_path = None
    with pytest.raises(ValueError):
        build_task_info(torrent_info, cfg, rss_config, invalid_server_config)

You'll need to:

  1. Import pytest if not already imported at the top of the file
  2. Ensure ServerConfig class has proper validation for its fields
  3. Update the test configuration files (rss.yml and server.yml) to have valid test data

Comment on lines +17 to +18
torrent_hash = "5484cff30b108ca1d1987fb6ea4eebed356b9ddd"
torrent_url = "https://nyaa.si/download/1878677.torrent"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Test relies on external torrent that might become unavailable

Consider creating a small test torrent file and including it in the test assets to avoid dependency on external resources that might become unavailable.

Comment on lines 4 to 5
async def test_task_store() -> None:
store = AsyncJsonStore()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test should verify the renamed tg_posted field

Add test cases to verify that the TaskStatus.tg_posted field (renamed from tg_uploaded) works correctly and maintains backward compatibility if needed.

Suggested implementation:

@pytest.mark.asyncio
async def test_task_store() -> None:
    store = AsyncJsonStore()

    # Test setting and getting tg_posted field
    task = TaskStatus(task_id="test1")
    assert not task.tg_posted  # Should default to False

    task.tg_posted = True
    await store.save_task(task)

    loaded_task = await store.get_task("test1")
    assert loaded_task.tg_posted is True

    # Test backward compatibility with tg_uploaded field
    old_format_task = {
        "task_id": "test2",
        "tg_uploaded": True
        # Add other required fields here
    }
    await store.save_task(TaskStatus.from_dict(old_format_task))

    loaded_old_task = await store.get_task("test2")
    assert loaded_old_task.tg_posted is True  # Should read old field correctly

Note: The exact implementation details might need to be adjusted based on:

  1. The actual fields available in TaskStatus
  2. The specific backward compatibility mechanism used in TaskStatus
  3. The actual method signatures for save_task and get_task in AsyncJsonStore

@Tohrusky Tohrusky merged commit dfb76d1 into TensoRaws:main Dec 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant