mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
changed add_player function of in preparation for scan_filesystem
This commit is contained in:
parent
6510b5af15
commit
0369f4d574
@ -218,6 +218,7 @@ class YoutubeVideo:
|
||||
CONFIG = AppConfig().config
|
||||
ES_URL = CONFIG['application']['es_url']
|
||||
CACHE_DIR = CONFIG['application']['cache_dir']
|
||||
VIDEOS = CONFIG['application']['videos']
|
||||
|
||||
def __init__(self, youtube_id):
|
||||
self.youtube_id = youtube_id
|
||||
@ -294,13 +295,23 @@ class YoutubeVideo:
|
||||
|
||||
return vid_basic
|
||||
|
||||
def add_new_player(self):
|
||||
def add_player(self, missing_vid):
|
||||
""" add player information for new videos """
|
||||
cache_path = self.CACHE_DIR + '/download/'
|
||||
videos = self.VIDEOS
|
||||
|
||||
if missing_vid:
|
||||
# coming from scan_filesystem
|
||||
channel_name, file_name, _ = missing_vid
|
||||
vid_path = os.path.join(videos, channel_name, file_name)
|
||||
else:
|
||||
# coming from VideoDownload
|
||||
all_cached = os.listdir(cache_path)
|
||||
for file_cached in all_cached:
|
||||
if self.youtube_id in file_cached:
|
||||
vid_path = os.path.join(cache_path, file_cached)
|
||||
break
|
||||
|
||||
duration_handler = DurationConverter()
|
||||
duration = duration_handler.get_sec(vid_path)
|
||||
duration_str = duration_handler.get_str(duration)
|
||||
@ -309,8 +320,6 @@ class YoutubeVideo:
|
||||
"duration": duration,
|
||||
"duration_str": duration_str
|
||||
}
|
||||
break
|
||||
|
||||
self.vid_dict['player'] = player
|
||||
|
||||
def build_file_path(self, channel_name):
|
||||
@ -360,7 +369,7 @@ class YoutubeVideo:
|
||||
print(response.text)
|
||||
|
||||
|
||||
def index_new_video(youtube_id):
|
||||
def index_new_video(youtube_id, missing_vid=False):
|
||||
""" combine video and channel classes for new video index """
|
||||
vid_handler = YoutubeVideo(youtube_id)
|
||||
channel_handler = YoutubeChannel(vid_handler.channel_id)
|
||||
@ -368,7 +377,7 @@ def index_new_video(youtube_id):
|
||||
channel_name = channel_handler.channel_dict['channel_name']
|
||||
vid_handler.build_file_path(channel_name)
|
||||
# add channel and player to video
|
||||
vid_handler.add_new_player()
|
||||
vid_handler.add_player(missing_vid)
|
||||
vid_handler.vid_dict['channel'] = channel_handler.channel_dict
|
||||
# add new channel to es
|
||||
if channel_handler.source == 'scraped':
|
||||
|
@ -337,7 +337,7 @@ def scan_filesystem():
|
||||
if filesystem_handler.to_index:
|
||||
for missing_vid in filesystem_handler.to_index:
|
||||
youtube_id = missing_vid[2]
|
||||
index_new_video(youtube_id)
|
||||
index_new_video(youtube_id, missing_vid=missing_vid)
|
||||
|
||||
|
||||
def reindex_old_documents():
|
||||
|
Loading…
Reference in New Issue
Block a user