|
@@ -1,19 +1,46 @@
|
|
|
import console
|
|
import console
|
|
|
|
|
+import re
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class EmptyAttr:
|
|
|
|
|
+ def __str__(self):
|
|
|
|
|
+ return ''
|
|
|
|
|
+
|
|
|
|
|
+ def __format__(self, format_spec):
|
|
|
|
|
+ return ''.__format__(format_spec)
|
|
|
|
|
+
|
|
|
|
|
+ def __getattr__(self, item):
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+ def __getitem__(self, item):
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+Empty = EmptyAttr()
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item:
|
|
class Item:
|
|
|
- def __init__(self, site, title, url, duration='00:00', size=0, artist=None):
|
|
|
|
|
|
|
+ def __init__(self, site):
|
|
|
self.site = site
|
|
self.site = site
|
|
|
- self.original_url = url
|
|
|
|
|
|
|
+
|
|
|
|
|
+ self.title = Empty
|
|
|
|
|
+ self.artist = Empty
|
|
|
|
|
+
|
|
|
|
|
+ self.original_url = Empty
|
|
|
self.download_url = None
|
|
self.download_url = None
|
|
|
- self.title = title
|
|
|
|
|
- self.duration = duration
|
|
|
|
|
- self.size = size
|
|
|
|
|
- self.artist = artist
|
|
|
|
|
|
|
+ self.url_formatted = False
|
|
|
|
|
|
|
|
self.tag_item = None
|
|
self.tag_item = None
|
|
|
|
|
|
|
|
- self.url_formatted = False
|
|
|
|
|
|
|
+ self.size = Empty
|
|
|
|
|
+ self.duration = Empty
|
|
|
|
|
+ self.bitrate = Empty
|
|
|
|
|
+ self.bytes = None
|
|
|
|
|
+ self.duration_seconds = None
|
|
|
|
|
+
|
|
|
|
|
+ # self.calculate_duration_seconds()
|
|
|
|
|
+ # self.calculate_bytes()
|
|
|
|
|
+ # self.calculate_bitrate()
|
|
|
|
|
|
|
|
def format_original_url(self):
|
|
def format_original_url(self):
|
|
|
if not self.url_formatted:
|
|
if not self.url_formatted:
|
|
@@ -21,9 +48,53 @@ class Item:
|
|
|
console.output('Setting original URL to: {0}'.format(self.original_url), console.DBG_INFO)
|
|
console.output('Setting original URL to: {0}'.format(self.original_url), console.DBG_INFO)
|
|
|
self.url_formatted = True
|
|
self.url_formatted = True
|
|
|
|
|
|
|
|
|
|
+ def set_title(self, title):
|
|
|
|
|
+ self.title = title
|
|
|
|
|
+
|
|
|
|
|
+ def set_artist(self, artist):
|
|
|
|
|
+ self.artist = artist
|
|
|
|
|
+
|
|
|
|
|
+ def set_original_url(self, url):
|
|
|
|
|
+ self.original_url = url
|
|
|
|
|
+
|
|
|
|
|
+ def set_duration_string(self, duration):
|
|
|
|
|
+ self.duration = duration
|
|
|
|
|
+ self.calculate_duration_seconds()
|
|
|
|
|
+
|
|
|
|
|
+ def set_size_string(self, size):
|
|
|
|
|
+ self.size = size
|
|
|
|
|
+ self.calculate_bytes()
|
|
|
|
|
+
|
|
|
|
|
+ self.calculate_bitrate()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def set_download_url(self, url):
|
|
def set_download_url(self, url):
|
|
|
console.output('Setting download url to: {0}'.format(url), console.DBG_INFO)
|
|
console.output('Setting download url to: {0}'.format(url), console.DBG_INFO)
|
|
|
self.download_url = url
|
|
self.download_url = url
|
|
|
|
|
|
|
|
|
|
+ def set_bytes(self, bytes):
|
|
|
|
|
+ self.bytes = bytes
|
|
|
|
|
+
|
|
|
def link_tag_item(self, tagitem):
|
|
def link_tag_item(self, tagitem):
|
|
|
- self.tag_item = tagitem
|
|
|
|
|
|
|
+ self.tag_item = tagitem
|
|
|
|
|
+
|
|
|
|
|
+ def calculate_duration_seconds(self):
|
|
|
|
|
+ if self.duration is not Empty:
|
|
|
|
|
+ _split = self.duration.split(':')
|
|
|
|
|
+ minutes = int(_split[0])
|
|
|
|
|
+ seconds = int(_split[1])
|
|
|
|
|
+
|
|
|
|
|
+ self.duration_seconds = (minutes * 60) + seconds
|
|
|
|
|
+
|
|
|
|
|
+ def calculate_bytes(self):
|
|
|
|
|
+ if self.size is not Empty:
|
|
|
|
|
+ match = re.search('\d+\.?\d+', self.size)
|
|
|
|
|
+
|
|
|
|
|
+ if match is not None:
|
|
|
|
|
+ mbytes = float(match.group())
|
|
|
|
|
+ self.bytes = mbytes * 1048576 # 1024^2 -> MB to B
|
|
|
|
|
+
|
|
|
|
|
+ def calculate_bitrate(self):
|
|
|
|
|
+ if self.duration_seconds is not None and self.bytes is not None:
|
|
|
|
|
+ self.bitrate = self.bytes / self.duration_seconds / 1024 * 8 # bytes / seconds / 1024 * 8
|
|
|
|
|
+
|