Browse Source

DownloadItem: Add playlist support

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
56b95055fe
3 changed files with 49 additions and 19 deletions
  1. 36
      tests/test_ditem.py
  2. 18
      youtube_dl_gui/downloadmanager.py
  3. 14
      youtube_dl_gui/mainframe.py

36
tests/test_ditem.py

@ -46,7 +46,9 @@ class TestItemInit(unittest.TestCase):
"percent": "0%",
"speed": "-",
"eta": "-",
"status": "Queued"}
"status": "Queued",
"playlist_size": "",
"playlist_index": ""}
)
@ -144,7 +146,9 @@ class TestUpdateStats(unittest.TestCase):
"speed": "200.00KiB/s",
"eta": "00:38",
"status": "Downloading",
"path": path})
"path": path,
"playlist_size": "10",
"playlist_index": "1"})
self.assertEqual(self.ditem.path, path)
self.assertEqual(self.ditem.filenames, ["somefilename"])
@ -157,10 +161,14 @@ class TestUpdateStats(unittest.TestCase):
"percent": "2.0%",
"speed": "200.00KiB/s",
"eta": "00:38",
"status": "Downloading"}
"status": "Downloading",
"playlist_size": "10",
"playlist_index": "1"}
)
self.ditem.update_stats({"filename": "someotherfilename", "extension": ".m4a"})
self.ditem.update_stats({"filename": "someotherfilename",
"extension": ".m4a",
"playlist_index": "2"})
self.assertEqual(self.ditem.filenames, ["somefilename", "someotherfilename"])
self.assertEqual(self.ditem.extensions, [".mp4", ".m4a"])
@ -172,7 +180,9 @@ class TestUpdateStats(unittest.TestCase):
"percent": "2.0%",
"speed": "200.00KiB/s",
"eta": "00:38",
"status": "Downloading"}
"status": "Downloading",
"playlist_size": "10",
"playlist_index": "2"}
)
def test_update_stats_invalid_input(self):
@ -185,7 +195,9 @@ class TestUpdateStats(unittest.TestCase):
"percent": "",
"speed": "",
"eta": "",
"status": ""})
"status": "",
"playlist_size": "",
"playlist_index": ""})
self.assertEqual(
self.ditem.progress_stats,
@ -195,7 +207,9 @@ class TestUpdateStats(unittest.TestCase):
"percent": "0%",
"speed": "-",
"eta": "-",
"status": "Queued"}
"status": "Queued",
"playlist_size": "",
"playlist_index": ""}
)
def test_update_stats_not_string(self):
@ -246,7 +260,9 @@ class TestReset(unittest.TestCase):
"percent": "100%",
"speed": "-",
"eta": "00:00",
"status": "Error"
"status": "Error",
"playlist_size": "10",
"playlist_index": "8"
}
self.ditem.reset()
@ -263,7 +279,9 @@ class TestReset(unittest.TestCase):
"percent": "0%",
"speed": "-",
"eta": "-",
"status": "Queued"}
"status": "Queued",
"playlist_size": "",
"playlist_index": ""}
)
def test_reset_paused_stage(self):

18
youtube_dl_gui/downloadmanager.py

@ -129,7 +129,9 @@ class DownloadItem(object):
"percent": "0%",
"speed": "-",
"eta": "-",
"status": self.stage
"status": self.stage,
"playlist_size": "",
"playlist_index": ""
}
self.progress_stats = dict(self.default_values)
@ -659,13 +661,13 @@ class Worker(Thread):
# Build the playlist status if there is an update
# REFACTOR re-implement this on DownloadItem or ListCtrl level?
if self._data['playlist_index'] is not None:
if 'status' in temp_dict or 'playlist_index' in temp_dict:
temp_dict['status'] = '{status} {index}/{size}'.format(
status=self._data['status'],
index=self._data['playlist_index'],
size=self._data['playlist_size']
)
#if self._data['playlist_index'] is not None:
#if 'status' in temp_dict or 'playlist_index' in temp_dict:
#temp_dict['status'] = '{status} {index}/{size}'.format(
#status=self._data['status'],
#index=self._data['playlist_index'],
#size=self._data['playlist_size']
#)
if len(temp_dict):
self._talk_to_gui('send', temp_dict)

14
youtube_dl_gui/mainframe.py

@ -1234,10 +1234,20 @@ class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
self._list_index += 1
def _update_from_item(self, row, download_item):
for key in download_item.progress_stats:
progress_stats = download_item.progress_stats
for key in self.columns:
column = self.columns[key][0]
self.SetStringItem(row, column, download_item.progress_stats[key])
if key == "status" and progress_stats["playlist_index"]:
# Not the best place but we build the playlist status here
status = "{0} {1}/{2}".format(progress_stats["status"],
progress_stats["playlist_index"],
progress_stats["playlist_size"])
self.SetStringItem(row, column, status)
else:
self.SetStringItem(row, column, progress_stats[key])
def add_url(self, url):
"""Adds the given url in the ListCtrl.

Loading…
Cancel
Save