Explorar el Código

Merge branch 'fix_song_skip' of DebenOldert/Music-Downloader into master

Deben Oldert hace 6 años
padre
commit
896e3de836
Se han modificado 2 ficheros con 13 adiciones y 17 borrados
  1. 11 12
      sites/helper/download.py
  2. 2 5
      sites/helper/tagging.py

+ 11 - 12
sites/helper/download.py

@@ -65,25 +65,24 @@ def savefileprogress(name, full_name, file, item):
         if item.bytes is not None:
             bar = console.ProgressBar(total=item.bytes)
 
-            for chunk in file.iter_content(chunk_size=4096):
-                progress += len(chunk)
-                f.write(chunk)
-                bar.report_progress(progress=progress)
+            for chunk in file.iter_content(chunk_size=1024):
+                if chunk:
+                    progress += len(chunk)
+                    f.write(chunk)
+                    bar.report_progress(progress=progress)
+            bar.destroy()
 
         else:
-            bar = console.ProgressBar()
             f.write(file.content)
 
-        bar.destroy()
+    tags = tagging.search_tags(item)
 
-        tags = tagging.search_tags(item)
+    if tags is not None:
+        item.link_tag_item(tags)
 
-        if tags is not None:
-            item.link_tag_item(tags)
+        tagging.download_artwork(tags)
 
-            tagging.download_artwork(tags)
-
-            tagging.write_tags_to_file(f, item)
+        tagging.write_tags_to_file(full_name, item)
 
     full_save_name = '{0}/{1}'.format(Settings.SaveDir, name)
     os.rename(full_name, full_save_name)

+ 2 - 5
sites/helper/tagging.py

@@ -46,10 +46,7 @@ def search_tags(item):
 
 
 def write_tags_to_file(file, item):
-    try:
-        mp3 = ID3(file.name)
-    except ID3NoHeaderError:
-        mp3 = ID3()
+    mp3 = ID3(file)
 
     tagitem = item.tag_item
 
@@ -65,7 +62,7 @@ def write_tags_to_file(file, item):
                        desc='Cover',
                        data=tagitem.cover_image)
 
-    mp3.save(file.name)
+    mp3.save(file)
 
 
 def download_artwork(tag):