def download_user_videos(session, user): """Download all videos of a user.""" viewkeys = get_recent_video_viewkeys(user) secondary_viewkeys = get_public_user_video_viewkeys(user) viewkeys = set(viewkeys + secondary_viewkeys) print(f'Found {len(viewkeys)} videos.') for viewkey in viewkeys: clip = Clip.get_or_create(session, viewkey, user) # The clip has already been downloaded, skip it. if clip.completed and clip.user == user: continue url = f'https://www.pornhub.com/view_video.php?viewkey={viewkey}' success, info = download_video(url, user.name) if success: clip.title = info['title'] clip.completed = True clip.user = user print(f'New video: {clip.title}') session.commit()
def get_video(args): """Get a single videos.""" session = get_session() folder = args.get("folder") clip = Clip.get_or_create(session, args["viewkey"]) if clip.completed: if clip.title is not None and clip.extension is not None: target_path = get_clip_path(folder, clip.title, clip.extension) link_duplicate(clip, target_path) logger.info("Clip already exists") return success, info = download_video(args["viewkey"], name=folder) clip.title = info["title"] clip.tags = info["tags"] clip.cartegories = info["categories"] clip.completed = True clip.location = info["out_path"] clip.extension = info["ext"] session.commit()
def download_user_videos(session, user): """Download all videos of a user.""" video_viewkeys = get_user_video_viewkeys(user) # Try to get all uploaded videos video_upload_viewkeys = get_video_upload_viewkeys(user) # If that doesn't work, try to get all public uploaded videos if len(video_upload_viewkeys) == 0: video_upload_viewkeys = get_video_upload_viewkeys(user, True) viewkeys = set(video_viewkeys + video_upload_viewkeys) if len(viewkeys) == 0: logger.error(f"Found 0 videos for user {user.key}. Aborting") sys.exit(1) full_success = True logger.info(f"Found {len(viewkeys)} videos.") for viewkey in viewkeys: clip = Clip.get_or_create(session, viewkey, user) # The clip has already been downloaded, skip it. if clip.completed: if clip.title is not None and clip.extension is not None: target_path = get_clip_path(user.name, clip.title, clip.extension) link_duplicate(clip, target_path) if clip.user is None: clip.user = user session.commit() continue success, info = download_video(viewkey, user.name) if success: clip.title = info["title"] clip.tags = info["tags"] clip.cartegories = info["categories"] clip.completed = True clip.user = user clip.location = info["out_path"] clip.extension = info["ext"] logger.info(f"New video: {clip.title}") else: full_success = False session.commit() time.sleep(20) return full_success
def download_playlist_videos(session, playlist): """Download all videos of a playlist.""" viewkeys = get_playlist_video_viewkeys(playlist) print(f'Found {len(viewkeys)} videos.') for viewkey in viewkeys: clip = Clip.get_or_create(session, viewkey) # The clip has already been downloaded, skip it. if clip.completed: continue url = f'https://www.pornhub.com/view_video.php?viewkey={viewkey}' success, info = download_video(url, f'playlists/{playlist.name}') if success: clip.title = info['title'] clip.completed = True print(f'New video: {clip.title}') session.commit()
def download_playlist_videos(session, playlist): """Download all videos of a playlist.""" viewkeys = set(get_playlist_video_viewkeys(playlist)) if len(viewkeys) == 0: logger.error(f"Found 0 videos in playlist {Playlist.id}. Aborting") sys.exit(1) full_success = True logger.info(f"Found {len(viewkeys)} videos.") for viewkey in viewkeys: clip = Clip.get_or_create(session, viewkey) # The clip has already been downloaded, skip it. if clip.completed: if clip.title is not None and clip.extension is not None: target_path = get_clip_path(playlist.name, clip.title, clip.extension) link_duplicate(clip, target_path) continue success, info = download_video(viewkey, f"playlists/{playlist.name}") if success: clip.title = info["title"] clip.tags = info["tags"] clip.cartegories = info["categories"] clip.completed = True clip.location = info["out_path"] clip.extension = info["ext"] logger.info(f"New video: {clip.title}") else: full_success = False session.commit() time.sleep(20) return full_success