diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-06-05 00:41:15 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-06-05 00:41:15 -0700 |
commit | ae5fd9eb009c6522e7d7971e0bdea57faaaf2b3c (patch) | |
tree | 424a1c1e3923edd99b7b14a8ca6492b97c1b96f8 /youtube/local_playlist.py | |
parent | ccb795e31f2f9944b1c8b061906eb752009f8ea7 (diff) | |
download | yt-local-ae5fd9eb009c6522e7d7971e0bdea57faaaf2b3c.tar.lz yt-local-ae5fd9eb009c6522e7d7971e0bdea57faaaf2b3c.tar.xz yt-local-ae5fd9eb009c6522e7d7971e0bdea57faaaf2b3c.zip |
Make thumbnails work and other stuff
Diffstat (limited to 'youtube/local_playlist.py')
-rw-r--r-- | youtube/local_playlist.py | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py index e354013..d083e33 100644 --- a/youtube/local_playlist.py +++ b/youtube/local_playlist.py @@ -33,33 +33,7 @@ def add_to_playlist(name, video_info_list): if id not in ids: file.write(info + "\n") missing_thumbnails.append(id) - gevent.spawn(download_thumbnails, name, missing_thumbnails) - -def download_thumbnail(playlist_name, video_id): - url = "https://i.ytimg.com/vi/" + video_id + "/mqdefault.jpg" - save_location = os.path.join(thumbnails_directory, playlist_name, video_id + ".jpg") - try: - thumbnail = util.fetch_url(url, report_text="Saved local playlist thumbnail: " + video_id) - except urllib.error.HTTPError as e: - print("Failed to download thumbnail for " + video_id + ": " + str(e)) - return - try: - f = open(save_location, 'wb') - except FileNotFoundError: - os.makedirs(os.path.join(thumbnails_directory, playlist_name)) - f = open(save_location, 'wb') - f.write(thumbnail) - f.close() - -def download_thumbnails(playlist_name, ids): - # only do 5 at a time - # do the n where n is divisible by 5 - i = -1 - for i in range(0, int(len(ids)/5) - 1 ): - gevent.joinall([gevent.spawn(download_thumbnail, playlist_name, ids[j]) for j in range(i*5, i*5 + 5)]) - # do the remainders (< 5) - gevent.joinall([gevent.spawn(download_thumbnail, playlist_name, ids[j]) for j in range(i*5 + 5, len(ids))]) - + gevent.spawn(util.download_thumbnails, os.path.join(thumbnails_directory, name), missing_thumbnails) def get_local_playlist_page(name): @@ -84,7 +58,7 @@ def get_local_playlist_page(name): videos_html += html_common.video_item_html(info, html_common.small_video_item_template) except json.decoder.JSONDecodeError: pass - gevent.spawn(download_thumbnails, name, missing_thumbnails) + gevent.spawn(util.download_thumbnails, os.path.join(thumbnails_directory, name), missing_thumbnails) return local_playlist_template.substitute( page_title = name + ' - Local playlist', header = html_common.get_header(), |