Announcement

Collapse
No announcement yet.

Brain Surgery and Other Glorious Adventures in Hacking The Episode Analyser

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Prime Video Brain Surgery and Other Glorious Adventures in Hacking The Episode Analyser

    Before some rapture their aneurysms, let's get some terminology right, a hack is




    So if you won't perform a craniotomy on yourself (read: not crazy and not desperate enough), quit reading this post and go back; for the adventurous kind, continues. All of the below assumes you have the "single season" mod, otherwise things get messy very fast and nor worth dealing with.



    I had a particular problem where the pilot episode of a series was SD while the remainder of the series was perfectly good HD, and 'Fab was stuck analysing the pilot, even with the single season mod. It's pretty easy to infer, that whatever list of episodes is given to 'Fab's engine, the engine will take the first entry in the list and analyse that. Knowing that, we can perform some brain surgery on 'Fab to re-wire its brain. We will be operating on

    Code:
    amazon_get_seasons_info.py
    file, so back it up (don't you wish you could do that with a real patient?) before you start hacking at it! Having done that, here are some hacks in increasing difficulty levels.The function in the above-mentioned file that is responsible for returning the list of episodes is called "get_episodes_info," and we don't need to change anything major in it, just change what it signals to the cerebrum of 'Fab.



    Lobotomy Level (easy, anyone can do it)

    The simplest way to get 'Fab to analyse something other than the first episode in a season, is to reverse the list of episodes and get 'Fab to analyse the last episode of the season (obviously this breaks if Amazon insert junk like specials etc in the main listing of the episodes instead of the specials, but that's why this is a hack (see terminology) and not a fix). You will observe that the aforementioned function returns a list of episodes on line 174 as

    Code:
    return episodes_array
    ​
    so to reverse that array, we don't need to do anything major, just literally reverse that array in place, and luckily, there's a python way of doing it:

    Code:
    return episodes_array[::-1]
    ​
    That is all: you literally have to add six characters and you get a list in reverse order.


    Of course the additional benefit of this hack is that if you're only downloading the latest episode of a series and are careless like me, not only the correct episode should be selected and analysed, but also you won't have to remember to unclick the first episode of the season and accidentally blow a download credit.



    Before:
    Click image for larger version

Name:	image.png
Views:	385
Size:	165.6 KB
ID:	452855

    After:
    Click image for larger version

Name:	image.png
Views:	552
Size:	155.3 KB
ID:	452854


    Brain Aneurysm Clipping Level (medium, skill and intricate work required)


    Now that we can arbitrarily manipulate what 'Fab's cerebrum sees as episodes, why don't we go one further? Let's say we want to analyse and download a specific episode of a season? We can get a list of episodes that 'Fab sees, and get that episode's position in the list of episodes (again, a hack, not a fix, so you have to count manually (intricate work!) what that episode is, and not rely on episode numbering when Amazon listing doesn't match 1:1). Let's say we want to analyse episode 3 of season 3, and luckily, in this case that episode's position is actually 3. However, recall that python's arrays start at zero, not at one, so you have to subtract one from the position. So in the python-land, the index would be 2. Conveniently, we already have an array of the episodes constructed for us in the aforementioned function​, so all we need to do is pluck out that specific episode from that array and return an array containing just that one episode. Simple to do in python, again working with line 174 only:

    old like
    Code:
    return episodes_array
    ​
    now looks like
    Code:
    return [episodes_array[2]]
    The advantage of this method over the "movie mode" is that this preserves all episode data, so you can queue up all episodes you like and then download them and all of them will be treated as series episodes by 'Fab.


    Before:
    Click image for larger version

Name:	image.png
Views:	385
Size:	165.6 KB
ID:	452856
    After:
    Click image for larger version

Name:	image.png
Views:	384
Size:	183.4 KB
ID:	452858

    Haemorrhagic Stroke Repair Level (hard, you'd better get it right!)

    Having read the previous hack, you might be tempted to say "you want me to sit there and count episodes to analyse a single episode, that's just daft?!" and you'll be partially right... We can do better, we can use the name of the episode! If you study the aforementioned function, there is a loop that iterated over the episodes data and constructs the episodes array, while the title of the episode under consideration in that loop is stored in a variable called "title". So what we can do is interfere with that loop so that only the episode with the requisite title gets added to the episodes array. You will notice that the actual adding of the episode to the final array is done on line 172, and that's where we want to clip. Again, as our luck has it, python provides a way to do a partial string match, and we can make our life even easier by doing a lower case match so we don't have to get the CaMeL casing of the title correctly. The way we clip the required episode is by saying only add episodes with lower case titles that match the string we give you. So, let's say we want the episode called "Glorious Five Year Plan" to be analysed, you would modify from

    Code:
    episodes_array.append(e_obj)
    ​

    to
    Code:
    if "five year plan" in title.lower(): episodes_array.append(e_obj)
    ​

    obviously the string you give in the if condition has to be sufficiently unique to single out the episode you're after, otherwise you're not going to get the correct result! And I've not tested this with anything other than latinised titles, so it might not work for other languages, which is why it's still a hack, and not a fix

    Before:
    Click image for larger version

Name:	image.png
Views:	385
Size:	165.6 KB
ID:	452857
    After:
    Click image for larger version

Name:	image.png
Views:	388
Size:	190.3 KB
ID:	452859

    Naturally, you wouldn't want to be forced to remember and retype all those hacks as the case arises, so we can just keep that "collection" in the script, but commented out (by prepending a hash (#) in front of the code), and enable/disable things as the need arises, so my tail-end of that function changed from the original that looks like:

    Code:
                count += 1
                episodes_array.append(e_obj)
    
        return episodes_array

    to a slightly messy one that looks like:
    Code:
                # +HACK+ pluck out by title
                #pluckout_title="five year plan"
                #if pluckout_title in title.lower(): episodes_array.append(e_obj)
    
                # +HACK+ default episode-set comprehension behaviour
                episodes_array.append(e_obj)
    
        # +HACK+ pluck out by index
        #pluckout_index=2
        #return [episodes_array[pluckout_index]]
        
        # +HACK+ reverse order episodes
        return episodes_array[::-1]
    
        # +HACK+ default behaviour
        #return episodes_array
    and as you can see, what I have enabled in my script at the moment is only reversing of the order of the episodes.


    With all that, if your patient survives the brain surgery, well done, if you have the adverse outcome, well, you were warned!​

    #2
    One question related to this and how the program operates. If one were to modify the script with the single episode method, does one have to close the entire program or the Amazon module and reopen it each time, or does it load the script every single time you want to analyze something, therefore no additional action needed? Except of course opening your text editor with admin access so you can actually SAVE the file in the program files folder. By default you get a permissions denied error.

    Comment


      #3
      Nope, there's no caching, so the script is run every time you hit the analyse button, you will need to reload the season page as the results of the analysis are cached, however. So, yup, you can edit the script file with SF running.

      Comment


        #4
        Originally posted by 0xFeedBeef View Post
        Code:
        # +HACK+ pluck out by title
        #pluckout_title="five year plan"
        #if pluckout_title in title.lower(): episodes_array.append(e_obj)
        
        # +HACK+ default episode-set comprehension behaviour
        episodes_array.append(e_obj)
        
        # +HACK+ pluck out by index
        #pluckout_index=2
        #return [episodes_array[pluckout_index]]
        
        # +HACK+ reverse order episodes
        return episodes_array[::-1]
        
        # +HACK+ default behaviour
        #return episodes_array
        and as you can see, what I have enabled in my script at the moment is only reversing of the order of the episodes.


        With all that, if your patient survives the brain surgery, well done, if you have the adverse outcome, well, you were warned!​
        Great job but instead of using the title variable, wouldn't it be better to have it use the class for the play button? You start the episode you want to analyze, stop the episode, now the play button is set to that episode and you analyze it.

        The script can find the play button class, get the href, and then you filter the array to the play_url instead of the title. Very busy onboarding a couple of new hires today but i may try my hand at it sometime this week.

        Click image for larger version

Name:	image.png
Views:	302
Size:	305.2 KB
ID:	452898

        Comment


          #5
          Originally posted by jpp72 View Post

          Great job but instead of using the title variable, wouldn't it be better to have it use the class for the play button? You start the episode you want to analyze, stop the episode, now the play button is set to that episode and you analyze it.
          Potentially yes, but I'm working with a list of episodes that the function has already parsed from the episode list, and selecting the episode based on the "Continue watching" button could lose episode information and can be quite messy... You could just pluck out the name of the episode from the button and match the name in the list, I suppose, but that's getting messy as well. In any event, I suspect episodes_data (the sole argument to the function) has a way smaller scope than the entire page, so you'd have to hack some upstream function, if not several... extra mess... And just plucking out the episode from a list based on its name doesn't actually require you playing the episode.

          Comment


            #6
            Originally posted by 0xFeedBeef View Post

            And just plucking out the episode from a list based on its name doesn't actually require you playing the episode.
            True but you have to do multiple edits of the python script. I'd rather just apply the mod once.

            Again, good job nonetheless

            Comment


              #7
              Could the script be edited so that each episode is automatically analyzed individually, like Streamfab used to do?

              Comment


                #8
                Won't the scripts in the script directory be overwritten on every update? Mine were on the .3 update and I had to redo the single-season mod.

                Comment


                  #9
                  Originally posted by Sebastian001 View Post
                  Could the script be edited so that each episode is automatically analyzed individually, like Streamfab used to do?
                  StreamFab has never done that

                  Comment


                    #10
                    Originally posted by Sebastian001 View Post
                    Could the script be edited so that each episode is automatically analyzed individually, like Streamfab used to do?

                    I think you mean OnceHasBeenStream, and it never did that either, it just presented an interface to allow the user to manually click on the episode to analyse it and add it to the queue.

                    Speaking from the practicalities, you only would ever need to analyse a single episode in rare edge cases, most of the time it's a colossal waste of time, and analysing a first or a last episode is more than sufficient to get the gist of the series' parameters...



                    Originally posted by MidnightInAurora View Post
                    Won't the scripts in the script directory be overwritten on every update? Mine were on the .3 update and I had to redo the single-season mod.
                    ​​​​​​​Yup, that's why it's a hack and not a fix

                    Comment


                      #11
                      Originally posted by jpp72 View Post

                      StreamFab has never done that
                      Are you saying Streamfab never did it on Amazon, or never on any of the modules?

                      I'm asking because I haven't been using Amazon as long as the German RTL+ module. On RTL+, up to version 6116, it was possible to load season 9 in 1080p, even if season 1 was only analyzed at 540p. If you had put a soap with 1000 episodes in the queue back then, you would see in the window, Analyzing episode 1, 2, 3.... of 1000. From version 6117 onwards, everything was downloaded in the resolution of season 1? The window only said analyzing season 1 of season 5.

                      I hope you understand what I mean and that the translation doesn't come across wrong :-)

                      See also here​

                      Hello, some RTL+ videos are not loading in 1080p. The problem has existed since version 6.6.1.7. As can be seen in the photo, everything was fine with 6.6.1.6. Log.zip (https://forum.dvdfab.cn/core/filedata/fetch?id=427505&d=1688566382)

                      Comment


                        #12
                        Originally posted by 0xFeedBeef View Post


                        I think you mean OnceHasBeenStream, and it never did that either, it just presented an interface to allow the user to manually click on the episode to analyse it and add it to the queue.

                        Speaking from the practicalities, you only would ever need to analyse a single episode in rare edge cases, most of the time it's a colossal waste of time, and analysing a first or a last episode is more than sufficient to get the gist of the series' parameters...





                        ​​​​​​​Yup, that's why it's a hack and not a fix
                        Basically, this problem with the bitrates B1 B2 B3 bothers me as jpp72 has nicely described it...

                        For two days now, it has no longer been possible to analyze individual episodes. However, manual selection and download works and movies are not affected: If I use a url for a season or single episode nothing is marked in selection. So it's not more possible to analyze single episodes or detect differences in seasons. All SF

                        Comment


                          #13
                          Originally posted by Sebastian001 View Post

                          Basically, this problem with the bitrates B1 B2 B3 bothers me as jpp72 has nicely described it...

                          You can pluck out the episode by title or index as described in the hacks above and you won't even have to play the episode in the browser (which is what you used to have to do) to have it analysed. That's what the situation is now...

                          In any event, the single season mod takes care of most problems.

                          Comment


                            #14
                            Originally posted by 0xFeedBeef View Post


                            You can pluck out the episode by title or index as described in the hacks above and you won't even have to play the episode in the browser (which is what you used to have to do) to have it analysed. That's what the situation is now...

                            In any event, the single season mod takes care of most problems.
                            Yes, I'm already using your change to analyze each season individually... It's great...

                            It's not meant to be a criticism​

                            Comment


                              #15
                              Originally posted by Sebastian001 View Post

                              Are you saying Streamfab never did it on Amazon, or never on any of the modules?

                              I'm asking because I haven't been using Amazon as long as the German RTL+ module. On RTL+, up to version 6116, it was possible to load season 9 in 1080p, even if season 1 was only analyzed at 540p. If you had put a soap with 1000 episodes in the queue back then, you would see in the window, Analyzing episode 1, 2, 3.... of 1000. From version 6117 onwards, everything was downloaded in the resolution of season 1? The window only said analyzing season 1 of season 5.

                              I hope you understand what I mean and that the translation doesn't come across wrong :-)

                              See also here​
                              I do understand what you mean. I had no idea RTL+ was doing it that way.

                              I am saying for Amazon, Netflix, Hulu and Max, StreamFab always analyzed a single episode. Probably the same for most other modules.

                              All the issues we are having with the logic of the bitrate selection could be avoided if they had a section where you could define your must haves or minimums. For example, i could tell them that on Amazon, i want:
                              • H265 Video
                              • Lowest video bitrate for 1080p that is > 2500kbps
                              • English, French and Romanian subtitles
                              • 5.1 Audio for Movies and 2.0 audio for TV Shows
                              These are defaults but i could always say actually for this TV Show, 5.1 audio since it's not a Comedy or Reality show but a show like Jack Ryan, LOTR or Reacher.

                              Obviously, the solution to us getting the exact specs we want for a specific episode is to add an Analyze button next to each individual episode like i have suggested many times in the past 2 years

                              Comment

                              Working...
                              X