VideoHelp Forum




+ Reply to Thread
Page 2 of 2
FirstFirst 1 2
Results 31 to 34 of 34
  1. Remove ads segments from Goplay SSAI mpd


    Create mpd no ads template code using awk, sed and grep for Windows OS


    cat ads.mpd | sed "/Period.*-ad-/,/\/Period/d" | sed "/Representation.*height..[457]/,/\/Representation/d" | sed -z "s#\/Period.*\n.*MPD#/Period>\n</MPD#" | sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}" | awk "/\074S d/ && ++count==1{sub(/\074S d.*$/,\"\074qqqqq_video\076\")} 1" | awk "/\074S d/ && ++count==1{sub(/\074S d.*$/,\"\074qqqqq_audio\076\")} 1"




    code explanation


    cat ads.mpd


    This lists the contents of the file ads.mpd. This list is then piped into the stream editor sed


    sed "/Period.*-ad-/,/\/Period/d"
    This code deletes all lines between and including any period that has -ads-


    sed "/Representation.*height..[457]/,/\/Representation/d"
    This code deletes all lines between and including any period that has Representation with height starting with 4,5 or 7.
    With this line of code we have scraped the best resolution with height 1080




    sed -z "s#\/Period.*\n.*MPD#/Period>\n</MPD#"
    This code deletes all the Period data except the first. The 1080 Period is the first




    sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}"
    This code concatenates all the SegmentTimeline lines


    There are two sets of SegmentTimeline data ... video listed first and audio listed second


    Next task is to reidentify this data so that we can later do a find/replace when injecting the complete SegmentTimeline data




    awk "/\074S d/ && ++count==1{sub(/\074S d.*$/,\"\074qqqqq_video\076\")} 1"
    This code replaces the first found SegmentTimeline data (video) with <qqqqq_video>
    We have also replace the hook data <S d for this SegmentTimeline data


    We repeat the code.
    awk "/\074S d/ && ++count==1{sub(/\074S d.*$/,\"\074qqqqq_audio\076\")} 1"
    This code replaces the first found SegmentTimeline data. This is now the audio data. We replace it with <qqqqq_audio>




    We now have the complete remade mpd.
    All that is required is to add the video and audio SegmentTimeline data via another sed replacement.


    End of Part One


    ================================================


    Part Two ... Capturing the video and audio SegmentTimeline data


    cat ads.mpd | sed "/Period.*-ad-/,/\/Period/d" | sed "/Representation.*height..[457]/,/\/Representation/d" | sed -n "/SegmentTimeline/,/\/SegmentTimeline/p" | sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}" | grep -v "SegmentTimeline" | awk -v row=2 "BEGIN {}{A[(NR-1)%row]=A[(NR-1)%row]$0\"\";} END { print A[0]; }" | sed -e "s#/>#/>crlf#g" | gclip


    sed -n "/SegmentTimeline/,/\/SegmentTimeline/p"
    This code captures all the SegmentTimeline data .... at this point this is all 1080 data




    sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}"
    This code concatenates all the SegmentTimeline data


    grep -v "SegmentTimeline"
    this code removes all lines with the string SegmentTimeline


    At this point we have video and audio data in alternate lines. We need to filter them out
    awk -v row=2 "BEGIN {}{A[(NR-1)%row]=A[(NR-1)%row]$0\"\";} END { print A[0]; }"


    This code will collate alternate lines 1 3 5 7 etc and 2 8 6 8 etc
    video (odd) lines ... stored in A[0]
    audio (even) lines ... stored in A[1]


    Each array is printed out and stored in the clipboard


    for /f "tokens=*" %e in (' pclip ') do set v_data=%e
    This line of code stores the clipboard into a variable


    Two variables are created v_data and a_data


    This data is then injected into the template (created in part one)
    sed -e "s#<qqqqq_video>#%v_data%#" and
    sed -e "s#<qqqqq_audio>#%a_data%#"


    Here is the complete code


    Code:
    cat ads.mpd | sed "/Period.*-ad-/,/\/Period/d" | sed "/Representation.*height..[457]/,/\/Representation/d" | sed -n "/SegmentTimeline/,/\/SegmentTimeline/p" | sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}" | grep -v "SegmentTimeline" | awk -v row=2  "BEGIN {}{A[(NR-1)%row]=A[(NR-1)%row]$0\"\";} END { print A[0]; }" | sed -e "s#/>#/>crlf#g" | gclip 
    for /f "tokens=*" %e in (' pclip  ') do set v_data=%e
    
    
    cat ads.mpd | sed "/Period.*-ad-/,/\/Period/d" | sed "/Representation.*height..[457]/,/\/Representation/d" | sed -n "/SegmentTimeline/,/\/SegmentTimeline/p" | sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}" | grep -v "SegmentTimeline" | awk -v row=2  "BEGIN {}{A[(NR-1)%row]=A[(NR-1)%row]$0\"\";} END { print A[1]; }" | sed -e "s#/>#/>crlf#g" | gclip
    for /f "tokens=*" %f in (' pclip  ') do set a_data=%f
    
    
    cat ads.mpd | sed "/Period.*-ad-/,/\/Period/d" | sed "/Representation.*height..[457]/,/\/Representation/d" | sed -z "s#\/Period.*\n.*MPD#/Period>\n</MPD#" | sed "/SegmentTimeline/{n;:l N;/\/SegmentTimeline/b; s/\n//; bl}" | awk "/\074S d/ && ++count==1{sub(/\074S d.*$/,\"\074qqqqq_video\076\")} 1" | awk "/\074S d/ && ++count==1{sub(/\074S d.*$/,\"\074qqqqq_audio\076\")} 1" | sed -e "s#<qqqqq_video>#%v_data%#" | sed -e "s#<qqqqq_audio>#%a_data%#" | sed -e "s#crlf#\n#g" | sed -e  "/^$/d"
    Last edited by jack_666; 31st Aug 2024 at 12:20.
    Quote Quote  
  2. Search, Learn, Download! Karoolus's Avatar
    Join Date
    Oct 2022
    Location
    Belgium
    Search Comp PM
    Been using this for over a year now:

    VB.NET:
    Code:
    Private Function FixGoPlayMPD(MPDUrl As String)
        Dim MPD As XDocument = XDocument.Load(MPDUrl)
        Dim ns As XNamespace = MPD.Root.GetDefaultNamespace
        'This removes the ads
        MPD.Descendants(ns + "Period").Where(Function(n) n.Attribute("id").Value.ToString.Contains("-ad-")).Remove
        'Get This highest bitrate
        Dim HighestBandwidth As Integer = 0
        Dim Bandwidths = MPD.Descendants(ns + "Representation").Where(Function(n) n.Parent.Attribute("mimeType").Value.ToString.Contains("video"))
        For Each x In Bandwidths
            If CInt(x.Attribute("bandwidth").Value) > HighestBandwidth Then
                HighestBandwidth = CInt(x.Attribute("bandwidth").Value)
            End If
        Next
        'Remove all VIDEO Periods that are not the highest bitrate
        MPD.Descendants(ns + "Representation").Where(Function(n) n.Attribute("bandwidth").Value.ToString <> HighestBandwidth.ToString And n.Parent.Attribute("mimeType").Value.ToString.Contains("video")).Remove
        'Now we are going to concatenate the different periods into one
        Dim newvideoperiod = MPD.Descendants(ns + "SegmentTimeline").Where(Function(n) n.Parent.Parent.Parent.Attribute("mimeType").Value.Contains("video")).First
        Dim newaudioperiod = MPD.Descendants(ns + "SegmentTimeline").Where(Function(n) n.Parent.Parent.Parent.Attribute("mimeType").Value.Contains("audio")).First
        For Each period In MPD.Descendants(ns + "Period").Where(Function(n) n.Attribute("id").Value <> MPD.Descendants(ns + "Period").First.Attribute("id").Value)
            'This will copy other video periods to the first period
            For Each adaptationset In period.Descendants(ns + "AdaptationSet").Where(Function(n) n.Attribute("mimeType").Value.ToString.Contains("video"))
                For Each s In adaptationset.Descendants(ns + "S")
                    newvideoperiod.Add(New XElement(s))
                Next
            Next
            'Do the same for other audio periods
            For Each adaptationset In period.Descendants(ns + "AdaptationSet").Where(Function(n) n.Attribute("mimeType").Value.ToString.Contains("audio"))
                For Each s In adaptationset.Descendants(ns + "S")
                    newaudioperiod.Add(New XElement(s))
                Next
            Next
        Next
        'Remove the other periods so we only keep one stream
        MPD.Descendants(ns + "Period").Where(Function(n) n.Attribute("id").Value <> MPD.Descendants(ns + "Period").First.Attribute("id").Value).Remove
        'Save the modified MPD
        MPD.Save("cleaned.mpd")
        Return True
    End Function
    Works every time
    This removes all but the highest resolution though, as I don't need anything lower than highest resolution in the MPD.
    Quote Quote  
  3. Feels Good Man 2nHxWW6GkN1l916N3ayz8HQoi's Avatar
    Join Date
    Jan 2024
    Location
    Pepe Island
    Search Comp PM
    Originally Posted by Karoolus View Post
    GoPlay needs some extra stuff because of the periods in the MPD
    Out of curiosity, do you need to apply this "fix" even for livestreams? I can't seem to find any broken ones. And livestreams can be found in both m3u8/mpd
    --[----->+<]>.++++++++++++.---.--------.
    [*drm mass downloader: widefrog*]~~~~~~~~~~~[*how to make your own mass downloader: guide*]
    Quote Quote  
  4. Search, Learn, Download! Karoolus's Avatar
    Join Date
    Oct 2022
    Location
    Belgium
    Search Comp PM
    Originally Posted by 2nHxWW6GkN1l916N3ayz8HQoi View Post
    Originally Posted by Karoolus View Post
    GoPlay needs some extra stuff because of the periods in the MPD
    Out of curiosity, do you need to apply this "fix" even for livestreams? I can't seem to find any broken ones. And livestreams can be found in both m3u8/mpd
    I'm honestly not sure, I have not messed with livestreams and periods
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!