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

does --write-comments need to be set for comments to be available in getComments()? #224

Open
9x3l6 opened this issue Dec 25, 2023 · 4 comments

Comments

@9x3l6
Copy link
Contributor

9x3l6 commented Dec 25, 2023

Not sure where else the code needs to be updated in order to make it so when calling getComments() it actually returns the comments instead of an empty array.

// ...
private bool $writeComments = false;
// ...
/**
 * Write video comments inside .info.json file.
 */
public function writeComments(bool $writeComments): self
{
    $new = clone $this;
    $new->writeComments = $writeComments;

    return $new;
}
// ...
'write-comments' => $this->writeComments,
@9x3l6
Copy link
Contributor Author

9x3l6 commented Dec 26, 2023

With the current way it is the comments are showing up as empty objects in the database during my tests. comment_count returns 6 and comments shows like below... Note this is from a youtube video, I have yet to check other platforms, and will update this when I can.

[{},{},{},{},{},{}]

To get around this issue with the empty objects, I am trying this for the moment. How sure how it effects performance though, time will tell. Also on a side note I noticed that the .info.json file is missing from the downloadPath but that's alright, since I can $video->toJson(), so long as the video and thumbnail are in the downloadPath I'm happy. In the future I'll check to make sure any subtitle files are also there, that'll have to wait.

try {
    $json = $video->toJson();
    $json = json_decode($json);
    $comments = $json->comments;
} catch (\Exception $e) {
    $comments = [];
}

I'm seeing these fields in the info.json file with I use the --write-comments argument with yt-dlp. Sometimes there is a like_count present and sometimes there isn't. I hope this helps. I could use all of those values. Thank you for working on this.

{
    "id": "string",
    "text": "string",
    "like_count": 2,
    "author_id": "string",
    "author": "string",   
    "author_thumbnail": "string",
    "parent": "string",                                  
    "_time_text": "string",
    "timestamp": 1672012800,
    "author_url": "string",
    "author_is_uploader": false,
    "is_favorited": false
}

Here is the code below to add the fields that aren't already in the code.

src/Entity/Comment.php

    public function getAuthorUrl(): ?string {
        return $this->get('author_url');
    }

    public function getAuthorIsUploader(): ?bool {
        return $this->get('author_is_uploader');
    }

    public function getAuthorThumbnail(): ?string {
        return $this->get('author_thumbnail');
    }

    public function getLikeCount(): ?int {
        return $this->get('like_count');
    }

    public function getIsFavorited(): ?bool {
        return $this->get('is_favorited');
    }

    public function getTimeText(): ?string {
        return $this->get('_time_text');
    }

@9x3l6 9x3l6 changed the title --write-comments needs to be set for comments to be available in getComments() does --write-comments need to be set for comments to be available in getComments()? Dec 26, 2023
@norkunas
Copy link
Owner

Like the Video entity, Comment also has direct access to any undefined properties through ->get('key') method. IIRC I've added only subset of getters that are most common in all providers, but if you want to contribute this also, I'm ok with it

@norkunas
Copy link
Owner

With the current way it is the comments are showing up as empty objects in the database during my tests.

That's expected if you use json_encode on objects when they don't implement JsonSerializable interface.
If you really need this, contribution welcome :)

@norkunas
Copy link
Owner

But you could also just use ->toArray() and all Comment data will be exposed to encode for database

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

No branches or pull requests

2 participants