3

I am currently working on a project to download .mp4 files from links from a text document, and it works with this code

import urllib.request
import random
import threading

def request(line):
    urllib.request.urlretrieve(line, 'D:\\example_directory\\' +
                               str(random.randint(1000000, 9999999)) + "-69" +
                               str(random.randint(100, 999)) + "-" +
                               str(random.randint(1000000, 9999999)) + ".mp4")

with open('D:\\example_directory\\links.txt') as f:
    for line in f:
        print(line)
        threading.Thread(target=request, args=(line,)).start()

I want to use this code to download videos from a website which is built for streaming, and therefore caps the download speed after around 5 seconds to 120kb/s. I found a bypass for this limitation: resetting your connection. Resetting your connection can be manually achieved by plugging the ethernetcable in and out or turning WiFi on and off again.

I want to know if there is any way to reset the connection, without having to plugin and out the cable / turn on and off the WiFi. Like a package or function that can be imported, but also a glitch would help.

User1986
  • 175
  • 10
  • `threading.Thread(target=request(line)).start()` doesn't do what you think it does. – user2357112 Jan 08 '22 at 23:31
  • 1
    The `target=request(line)` part executes `request(line)` and sets the keyword argument `target` equal to what it returns (i.e. `None`). Use `Thread(target=lambda line=line: request(line))` instead. – martineau Jan 09 '22 at 00:37
  • fixed it, i copied the wrong code from an older file – User1986 Jan 09 '22 at 09:29

1 Answers1

0

You can reset your connection, like you said, by reconnecting to the network. There is, as of my knowlegde, no module to intentionally reset a connection, but you can achieve a simular result using this method:

  • first, connect via Ethernet (cable)
  • then use the "winwifi" module, to reset your connection example:
import winwifi
def reset():
  winwifi.disconnect()

because you are connected to ethernet, the connection is restored within a fraction of a second, and therefore, resets. I hope this helped you and have a great journey on your coding adventures ;)