#!/usr/bin/python

import shutil
import requests
import wolfpack.alpha.settings as settings

class DLFile(object):
    def __init__(self, url):
        self.url = url
        self.name = self.url.split('/')[-1]

        self.available_chunks = list()
        self.downloaded_chunks = list()
        self.downloading_chunks = list()

        r = requests.head(url)
‌        self.size = int(r.headers['content-length'])
        self.headers = r.headers    # TODO: Is it needed?

        self.calculate_ranges()
		self.num_part=0 #count chunks

    def calculate_ranges(self):
        if self.size < settings.CHUNK_SIZE:
            self.available_chunks.append("%d-%d" %(0, self.size - 1))  #just one part to download

        self.num_part = self.size / settings.CHUNK_SIZE
		
        for i in range(self.num_part):
            self.available_chunks.append((i * settings.CHUNK_SIZE, 
                                          ((i + 1) * settings.CHUNK_SIZE) - 1))
        if not self.size % settings.CHUNK_SIZE:
            self.available_chunks.append((self.num_part * settings.CHUNK_SIZE,
                                          self.size - 1))
			self.num_part+=1
    def request_chunk(self):
 #       for item in self.available_chunks:
  #          self.downloading_chunks.append(
   #             self.available_chunks.pop(self.available_chunks.index(item)) 
    #        ) 
		for i in range(1,self.num_part):
			self.downloading_chunks.append(
				self.available_chunks.pop(i)
            return [self.url, self.downloading_chunks[-1][0], self.downloading_chunks[-1][1]]

        if not len(self.available_chunks):
            if not len(self.downloaded_chunks):
                self.merge_parts()
                return ["Downloaded",]
            else:
                return ["Downloading",]


    def merge_parts(self):
        final_file = open(self.name, 'wb')
        for i in range(self.num_part):
            shutil.copyfileobj(open("%s.%d" % (self.name, i), 'rb'), final_file)
        final_file.close()


@@ -361,9 +361,8 @@
 rl)%0A
-%E2%80%8C
     
@@ -410,16 +410,16 @@
 ngth'%5D)%0A
+
         
@@ -501,18 +501,24 @@
 anges()%0A
-%09%09
+        
 self.num
@@ -775,11 +775,9 @@
 IZE%0A
-%09%09
 %0A
+
     
@@ -877,17 +877,16 @@
 NK_SIZE,
- 
 %0A       
@@ -1143,19 +1143,28 @@
 e - 1))%0A
-%09%09%09
+            
 self.num
@@ -1172,16 +1172,17 @@
 part+=1%0A
+%0A
     def 
@@ -1368,17 +1368,16 @@
 x(item))
- 
 %0A    #  
@@ -1387,12 +1387,17 @@
    )
- %0A%09%09
+%0A        
 for 
@@ -1425,19 +1425,28 @@
 _part):%0A
-%09%09%09
+            
 self.dow
@@ -1472,13 +1472,8 @@
 end(
-%0A%09%09%09%09
 self
@@ -1496,16 +1496,18 @@
 s.pop(i)
+)%0A
 %0A       
@@ -2009,16 +2009,16 @@
 l_file)%0A
+
         
@@ -2036,9 +2036,8 @@
 close()%0A
-%0A

Fix a lot of indentation issues