الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيفية اكمال تحميل نلف عند انقطاع الاتصال

بدأه iranio في 17 يناير 2018 · 1 رد · 1,346 مشاهدة · في لغة Python
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

مساعدة في  طريقة اعادة تحميل ملف من المكان الذي توقف عنده اثناء انقطاع الانترنت

 

def resume(url, fullpath, byte):
	#print (byte)
	#ss= raw_input("TotalSize2: ")
	re = urllib2.Request(url)
	re.headers['Range'] = 'bytes={}'.format(byte)
	rv = urllib2.urlopen(re)

	Size = byte.split('-')
	done = int(Size[0])

	
	#fullpath = "سلامظ?؟m|m.mp4"
	fullpath = "mmm.ogv"
	#fullpath = re.sub(r'[^\w]', ' ', fullpath)

	
	f = open(fullpath, 'ab')
	buff = rv.read(1024)
	#tt= raw_input("Pause Buff")
	gg = 0
	while buff:
		
		f.write(buff)

		done += 1024	
		percent = int(done * 100 / int(Size[1]))
		#print ("\r Downloading... [{} %]".format(percent))#,	
		try:
			buff = rv.read(1024)
		except :
			time.sleep(1)
			continue
#2

لقد حللت المشكلة شكرا لكم  الكود للإفادة:

def resume(url, fullpath, byte):
	#print (byte)
	ss= raw_input("TotalSize2: ")
	re = urllib2.Request(url)
	re.headers['Range'] = 'bytes={}'.format(byte)
	rv = urllib2.urlopen(re)

	Size = byte.split('-')
	done = int(Size[0])
	fullpath = "mmm.ogv"
	f = open(fullpath, 'ab')
	buff = rv.read(1024)
	tt= raw_input("Pause Buff")
	gg = 0
	while buff:
		if gg == 0:
			f.write(buff)

		done += 1024	
		percent = int(done * 100 / int(Size[1]))
		#print ("\r Downloading... [{} %]".format(percent))#,
		try:
			if gg == 1:
				re.headers['Range'] = 'bytes={}'.format(str(done) + "-" + str(Size[1]))          
				rv = urllib2.urlopen(re)
			buff = rv.read(1024)
			gg = 0

		except:
			time.sleep(1)
			done -= 1024
			gg = 1

مواضيع مشابهة