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

Extend custom_tags_parser functionality #247

Merged
merged 5 commits into from
Jan 13, 2022

Conversation

SerhiyRomanov
Copy link
Contributor

@SerhiyRomanov SerhiyRomanov commented Apr 5, 2021

What have been already implementing:

  • Changed the priority of calling the custom_tags_parser
  • Added the ability to control whether should 'main' parser go to the next line or not after custom_tags_parser has finished
  • The Segment class has been extended for storing custom values
#EXTM3U
#EXTINF: -1 timeshift="0" catchup-days="1" catchup-type="flussonic-ts" tvg-id="ethno-channel"  group-title="Ukraine" tvg-logo="http://iptv.domain/icon/7331.png",Етно HD
#EXTVLCOPT:video-filter=invert:croppadd{croptop=50,cropbottom=50}
#EXTGRP:MaybeUkraine
#EXTVLCOPT:param2=value2
http://str00.iptv.domain/7331/mpegts?token=longtokenhere

Example of new custom_tags_parser function, which allow parsing the playlist above

def parse_iptv_attributes(line, lineno, data, state):
    # Customize parsing #EXTINF
    if line.startswith(protocol.extinf):
        chunks = line.replace(protocol.extinf + ':', '').split(',', 1)
        if len(chunks) == 2:
            duration_and_props, title = chunks
        elif len(chunks) == 1:
            duration_and_props = chunks[0]
            title = ''

        additional_props = OrderedDict()
        chunks = duration_and_props.strip().split(' ', 1)
        if len(chunks) == 2:
            duration, raw_props = chunks
            matched_props = re.finditer(r'([\w\-]+)="([^"]*)"', raw_props)
            for match in matched_props:
                additional_props[match.group(1)] = match.group(2)
        else:
            duration = duration_and_props

        if 'segment' not in state:
            state['segment'] = {}
        state['segment']['duration'] = float(duration)
        state['segment']['title'] = title

        save_segment_custom_value(state, 'extinf_props', additional_props)

        state['expect_segment'] = True
        return True

    # Parse #EXTGRP
    if line.startswith('#EXTGRP'):
        _, value = _parse_simple_parameter_raw_value(line, str)
        save_segment_custom_value(state, 'extgrp', value)
        state['expect_segment'] = True
        return True

    # Parse #EXTVLCOPT
    if line.startswith('#EXTVLCOPT'):
        _, value = _parse_simple_parameter_raw_value(line, str)

        existing_opts = get_segment_custom_value(state, 'vlcopt', [])
        existing_opts.append(value)
        save_segment_custom_value(state, 'vlcopt', existing_opts)

        state['expect_segment'] = True
        return True

@SerhiyRomanov
Copy link
Contributor Author

This PR is ready for review and merging.

Please, highlight in release notes, that there is a breaking change:
custom_tags_parser function now receives 4 arguments

def custom_tags_parser_function(line, lineno, data, state):

@SerhiyRomanov SerhiyRomanov changed the title WIP: Extend custom_tags_parser functionality Extend custom_tags_parser functionality Apr 6, 2021
@SerhiyRomanov
Copy link
Contributor Author

@leandromoreira @mauricioabreu
Any chance to get this merged?

@leandromoreira
Copy link
Contributor

@SerhiyRomanov sorry for delay I'll try to read all the PR :) thanks again, you're always helping a lot.

@leandromoreira
Copy link
Contributor

that's wonderful @SerhiyRomanov I'll try to reach @mauricioabreu so we can seep up your work to be released as soon as possible.

@leandromoreira
Copy link
Contributor

This PR is ready for review and merging.

Please, highlight in release notes, that there is a breaking change: custom_tags_parser function now receives 4 arguments def custom_tags_parser_function(line, lineno, data, state):

I think, next relase we may need to bump up major version @mauricioabreu , @SerhiyRomanov do you agree?

@leandromoreira
Copy link
Contributor

@SerhiyRomanov there's still conflicts can you resolve them?

@SerhiyRomanov
Copy link
Contributor Author

@leandromoreira I've resolved conflicts, so it can be merged. Let me know if I can help more with that library.

@leandromoreira
Copy link
Contributor

@leandromoreira I've resolved conflicts, so it can be merged. Let me know if I can help more with that library.

thanks a lot, @mauricioabreu and I are planning to release a new version before your changes and a new major after merging your work.

@mauricioabreu
Copy link
Member

@SerhiyRomanov good job! I want to merge this but there are some tests failing. Can you check it? Are those tests failing for you too?

SerhiyRomanov and others added 4 commits January 13, 2022 13:45
Added the ability to control whether should 'main' go to next line or not after custom_tags_parser has finished
The Segment class has been extended for storing custom values
@SerhiyRomanov
Copy link
Contributor Author

@mauricioabreu I fixed the tests, could you run the test suite one more time?

@mauricioabreu mauricioabreu merged commit 4abc009 into globocom:master Jan 13, 2022
@mauricioabreu
Copy link
Member

Thank you @SerhiyRomanov

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.

None yet

3 participants