Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/chingari.py (Python)

Code before:
import itertools
import json

from .common import InfoExtractor
from ..compat import compat_urllib_parse_unquote_plus
from ..utils import (
    clean_html,
    ExtractorError,
    str_to_int,
)


class ChingariBaseIE(InfoExtractor):
    def _get_post(self, id, post_data):
        media_data = post_data['mediaLocation']
        base_url = media_data['base']
        author_data = post_data.get('authorData', {})
        song_data = post_data.get('song', {})  # revist this in future for differentiating b/w 'art' and 'author'

        formats = []
        for frmt, frmt_path in media_data.get('transcoded', {}).items():
            formats.append({
                'format_id': frmt,
                'width': str_to_int(frmt[1:]),
                'url': base_url + frmt_path,
            })
        if media_data.get('path'):
            formats.append({
                'format_id': 'original',
                'format_note': 'Direct video.',
                'url': base_url + '/apipublic' + media_data['path'],
                'quality': 10,
            })
        self._sort_formats(formats)

        return {
            'id': id,
            'title': compat_urllib_parse_unquote_plus(clean_html(post_data.get('caption'))),
            'description': compat_urllib_parse_unquote_plus(clean_html(post_data.get('caption'))),
            'duration': media_data.get('duration'),
            'thumbnail': base_url + media_data.get('thumbnail', ''),
            'like_count': post_data.get('likeCount'),
            'view_count': post_data.get('viewsCount'),
            'comment_count': post_data.get('commentCount'),
            'repost_count': post_data.get('shareCount'),
            'timestamp': str_to_int(post_data.get('created_at')) // 1000,
            'uploader_id': post_data.get('userId') or author_data.get('_id'),
            'uploader': author_data.get('name'),
            'uploader_url': 'https://chingari.io/' + author_data.get('username', ''),
            'track': song_data.get('title'),
            'artist': song_data.get('author'),

Review comment (suggestion):
```suggestion
        formats = [{
            'format_id': frmt,
            'width': str_to_int(frmt[1:]),
            'url': base_url + frmt_path,
        } for frmt, frmt_path in media_data.get('transcoded', {}).items())
```

Code after:
import itertools
import json

from .common import InfoExtractor
from ..compat import compat_urllib_parse_unquote_plus
from ..utils import (
    clean_html,
    ExtractorError,
    int_or_none,
    str_to_int,
    url_or_none,
)


class ChingariBaseIE(InfoExtractor):
    def _get_post(self, id, post_data):
        media_data = post_data['mediaLocation']
        base_url = media_data['base']
        author_data = post_data.get('authorData', {})
        song_data = post_data.get('song', {})  # revist this in future for differentiating b/w 'art' and 'author'

        formats = [{
            'format_id': frmt,
            'width': str_to_int(frmt[1:]),
            'url': base_url + frmt_path,
        } for frmt, frmt_path in media_data.get('transcoded', {}).items()]

        if media_data.get('path'):
            formats.append({
                'format_id': 'original',
                'format_note': 'Direct video.',
                'url': base_url + '/apipublic' + media_data['path'],
                'quality': 10,
            })
        self._sort_formats(formats)
        timestamp = str_to_int(post_data.get('created_at'))
        if timestamp:
            timestamp = int_or_none(timestamp, 1000)

        thumbnail, uploader_url = None, None
        if media_data.get('thumbnail'):
            thumbnail = base_url + media_data.get('thumbnail')
        if author_data.get('username'):
            uploader_url = 'https://chingari.io/' + author_data.get('username')

        return {
            'id': id,
            'title': compat_urllib_parse_unquote_plus(clean_html(post_data.get('caption'))),
            'description': compat_urllib_parse_unquote_plus(clean_html(post_data.get('caption'))),
            'duration': media_data.get('duration'),
            'thumbnail': url_or_none(thumbnail),