Clean duplicates from playlist

This commit is contained in:
Maks Snegov 2024-02-02 17:56:36 -08:00
parent b00e309aa0
commit f33297382e

16
main.py
View File

@ -221,6 +221,11 @@ def main():
parser_move.add_argument('-l', '--limit', type=int, default=-1, parser_move.add_argument('-l', '--limit', type=int, default=-1,
help='Limit number of videos to process') help='Limit number of videos to process')
parser_dups = subparsers.add_parser('dups', help='Remove duplicate videos in a playlist')
parser_dups.add_argument('playlist', help='Playlist name/ID')
parser_dups.add_argument('-l', '--limit', type=int, default=-1,
help='Limit number of videos to process')
args = parser.parse_args() args = parser.parse_args()
# Disable OAuthlib's HTTPS verification when running locally. # Disable OAuthlib's HTTPS verification when running locally.
@ -262,6 +267,17 @@ def main():
continue continue
add_video_to_playlist(youtube, video, playlist, args.dry_run) add_video_to_playlist(youtube, video, playlist, args.dry_run)
elif args.command == 'dups':
playlist = get_playlist_id(args.playlist)
videos = list_playlist(youtube, playlist)
video_map = {}
for video in videos[:args.limit]:
video_id = video['snippet']['resourceId']['videoId']
if video_id in video_map:
remove_video_from_playlist(youtube, video, playlist, args.dry_run)
else:
video_map[video_id] = video
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())