Automatically Program is geting rerun just by changing website for 5 sec

How to keep the Website static for 5 Min
For Eg - I am downloading a Playlist of 10 videos of youtube
I Started downloading and and giving the user option to save video
Once they click on save video , Program started running again
I need sol - How to Stop program from rerun and exceute from where it left
repo - GitHub - dudegladiator/YoutubeDownloader

Hi @Harsh_Gupta1,

I tried out the app with a playlist, and I see the issue that you’re having.

Here is one approach that should help:

  1. Use st.experimental_memo (soon to be renamed st.cache_data) rather than st.cache. Also, when you use it around a function, you have to do @st.experimental_memo (notice the @ symbol). Otherwise it won’t do anything to your function.
  2. Use return values rather than global variables (e.g. make download return the path of the downloaded file, rather than simply changing a global variable).
  3. Break some more of the slow parts of the app into functions, and cache the data-only ones. For example:
@st.experimental_memo
def get_audio_files(urls):
    files = []
    for url in urls:
        q = download(url, "720p", option=2)
        files.append((q, title))
    return files

def get_audio_buttons(urls):
    files = get_audio_files(urls)
    for q, title in files:
        st.write(title)
        with open(q, "rb") as f:
            st.download_button("Save Audio", f, file_name=f"{title}.mp3")

Which you can call this way:

get_audio_buttons(list(ytplay.video_urls))

Note that this doesn’t stop the app from rerunning when you download a file, but it makes the rerunning very fast in my testing, so it shouldn’t cause your users any issues.

Hopefully those are some helpful tips that will resolve most of this issue. Nice app, by the way!

Thank you for the solution
I have one feedback about adding a function ;-
When someone click on any widget - there should be option whether the code run from start or from some line

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.