def go(self): try: url = self.url_line_edit.text() total_seconds, items = parse_playlist_time(url) text = 'Playlist:\n' for i, (title, time) in enumerate(items, 1): text += ' {}. {} ({})\n'.format(i, title, time) text += '\nTotal time: {} ({} total seconds).'.format( seconds_to_str(total_seconds), total_seconds) self.result_text.setPlainText(text) except Exception as e: import traceback text = str(e) + '\n\n' + traceback.format_exc() self.result_text.setPlainText(text)
progress__line_el = player_progress_el.find_element_by_css_selector( '.progress__bar.progress__progress > .progress__line') while True: try: track_playing_el = driver.find_element_by_css_selector( '.d-track_playing') track = get_track(track_playing_el) except (NoSuchElementException, StaleElementReferenceException): continue total_seconds = track.get_seconds() value = progress__line_el.get_attribute('style') # Example: style="transform: scaleX(0.4728);" m = re.search(r'scaleX\((.+?)\);', value) if m: progress_percent = float(m.group(1)) progress_left = total_seconds * progress_percent progress_left_str = seconds_to_str(progress_left) progress_right_str = seconds_to_str(total_seconds) print( f'{track.title}. {progress_left_str} / {progress_right_str} ({progress_percent:.1%})' ) time.sleep(1) finally: if driver: driver.quit()
rs = requests.get(url, headers=headers) data = get_ytInitialData(rs.text) total_seconds = 0 items = [] for video in get_video_list(data): title = video['title']['simpleText'] duration_text = video['lengthText']['simpleText'] duration_secs = int(video['lengthSeconds']) total_seconds += duration_secs items.append((title, duration_text)) return total_seconds, items if __name__ == '__main__': url = 'https://www.youtube.com/playlist?list=PLndO6DOY2cLyxQYX7pkDspTJ42JWx07AO' total_seconds, items = parse_playlist_time(url) print('Playlist:') for i, (title, time) in enumerate(items, 1): print(' {}. {} ({})'.format(i, title, time)) print() print('Total time: {} ({} total seconds)'.format( seconds_to_str(total_seconds), total_seconds))
} rs = requests.get(url, headers=headers) root = BeautifulSoup(rs.content, 'html.parser') total_seconds = 0 items = [] for tr in root.select('.pl-video-list .pl-video'): title = tr['data-title'] time_str = tr.select_one('.timestamp').text.strip() items.append((title, time_str)) total_seconds += time_to_seconds(time_str) return total_seconds, items if __name__ == '__main__': url = 'https://www.youtube.com/playlist?list=PLndO6DOY2cLyxQYX7pkDspTJ42JWx07AO' total_seconds, items = parse_playlist_time(url) print('Playlist:') for i, (title, time) in enumerate(items, 1): print(' {}. {} ({})'.format(i, title, time)) print() print('Total time: {} ({} total seconds)'.format(seconds_to_str(total_seconds), total_seconds))