|
@@ -1,5 +1,6 @@
|
|
|
import console
|
|
import console
|
|
|
import sites.helper.tagging as tagging
|
|
import sites.helper.tagging as tagging
|
|
|
|
|
+from sites.helper.item import Empty
|
|
|
from .request import RawRequest
|
|
from .request import RawRequest
|
|
|
from pyquery import PyQuery
|
|
from pyquery import PyQuery
|
|
|
from settings import Settings
|
|
from settings import Settings
|
|
@@ -7,6 +8,7 @@ from settings import Settings
|
|
|
import math
|
|
import math
|
|
|
import urllib.parse
|
|
import urllib.parse
|
|
|
import json
|
|
import json
|
|
|
|
|
+import os
|
|
|
|
|
|
|
|
|
|
|
|
|
def download(item, type='GET', parameters=None, headers=None, cookies=None, stream=True):
|
|
def download(item, type='GET', parameters=None, headers=None, cookies=None, stream=True):
|
|
@@ -28,28 +30,40 @@ def download(item, type='GET', parameters=None, headers=None, cookies=None, stre
|
|
|
notExist(item)
|
|
notExist(item)
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- name = urllib.parse.unquote(item.title)
|
|
|
|
|
|
|
+ name = urllib.parse.unquote('{x.artist} - {x.title}'.format(x=item))
|
|
|
|
|
|
|
|
if not name.endswith('.mp3'):
|
|
if not name.endswith('.mp3'):
|
|
|
console.output('Assuming it\'s a mp3 file', console.DBG_INFO)
|
|
console.output('Assuming it\'s a mp3 file', console.DBG_INFO)
|
|
|
name = name + '.mp3'
|
|
name = name + '.mp3'
|
|
|
|
|
|
|
|
- full_name = '{0}/{1}'.format(Settings.SaveDir, name)
|
|
|
|
|
|
|
+ full_name = '{0}/{1}'.format(Settings.tmpDir, name)
|
|
|
|
|
|
|
|
- size = file.headers.get('content-length')
|
|
|
|
|
|
|
+ if item.bitrate is Empty and item.bytes is None:
|
|
|
|
|
+ size = file.headers.get('content-length')
|
|
|
|
|
+ if size is not None:
|
|
|
|
|
+ item.set_bytes(int(size))
|
|
|
|
|
+
|
|
|
|
|
+ console.output('File size: {0}'.format(console.format_bytes(item.bytes)))
|
|
|
|
|
+
|
|
|
|
|
+ if item.duration_seconds is not None:
|
|
|
|
|
+ item.calculate_bitrate()
|
|
|
|
|
+
|
|
|
|
|
+ console.output('Bitrate: {0}kbps'.format(int(item.bitrate)))
|
|
|
|
|
+
|
|
|
|
|
+ ans = console.ask_input('Continue downloading? [y/n]')
|
|
|
|
|
|
|
|
- savefileprogress(name, full_name, file, size, item)
|
|
|
|
|
|
|
+ if ans != 'y':
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
|
|
+ savefileprogress(name, full_name, file, item)
|
|
|
|
|
|
|
|
-def savefileprogress(name, full_name, file, size, item):
|
|
|
|
|
- if size is not None:
|
|
|
|
|
- size = int(size)
|
|
|
|
|
- console.output('Size: {0}'.format(console.format_bytes(size)))
|
|
|
|
|
- console.output('Saving to: {0}'.format(full_name))
|
|
|
|
|
|
|
+
|
|
|
|
|
+def savefileprogress(name, full_name, file, item):
|
|
|
|
|
+ console.output('Saving to: {0}'.format(full_name), level=console.DBG_INFO)
|
|
|
with open(full_name, 'wb') as f:
|
|
with open(full_name, 'wb') as f:
|
|
|
progress = 0
|
|
progress = 0
|
|
|
- if size is not None:
|
|
|
|
|
- bar = console.ProgressBar(total=size)
|
|
|
|
|
|
|
+ if item.bytes is not None:
|
|
|
|
|
+ bar = console.ProgressBar(total=item.bytes)
|
|
|
|
|
|
|
|
for chunk in file.iter_content(chunk_size=4096):
|
|
for chunk in file.iter_content(chunk_size=4096):
|
|
|
progress += len(chunk)
|
|
progress += len(chunk)
|
|
@@ -71,6 +85,10 @@ def savefileprogress(name, full_name, file, size, item):
|
|
|
|
|
|
|
|
tagging.write_tags_to_file(f, item)
|
|
tagging.write_tags_to_file(f, item)
|
|
|
|
|
|
|
|
|
|
+ full_save_name = '{0}/{1}'.format(Settings.SaveDir, name)
|
|
|
|
|
+ os.rename(full_name, full_save_name)
|
|
|
|
|
+ console.output('Moved to {0}'.format(full_save_name), level=console.DBG_INFO)
|
|
|
|
|
+
|
|
|
console.output('Download of {0} completed!'.format(name))
|
|
console.output('Download of {0} completed!'.format(name))
|
|
|
|
|
|
|
|
|
|
|
|
@@ -133,8 +151,6 @@ def krakenfiles(item, returnurl=False):
|
|
|
|
|
|
|
|
item.set_download_url('https:{0}'.format(form.attr('action')))
|
|
item.set_download_url('https:{0}'.format(form.attr('action')))
|
|
|
|
|
|
|
|
- name = pq('span.dfilename').text()
|
|
|
|
|
-
|
|
|
|
|
parameters = {}
|
|
parameters = {}
|
|
|
|
|
|
|
|
parameters['token'] = pq('input#dl-token').val()
|
|
parameters['token'] = pq('input#dl-token').val()
|