#!/bin/bash

# Define the list of playlist URLs
PLAYLISTS=(
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDv5eyBLEd9l3ZZzVoroxIZ"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAVjRNEOLkUu3ydfppeuxa7"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDYbs0jJdGefNN8eZRSwWqy"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDXsRuRGz1OnYd2zMSFkZej"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCG1CLu2--iTx554s-hSmdb"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBrtymuJUiv9Lq5CAYpN8Gl"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAHdJdtEl0-XiRfPRAvpbSz"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBkvpSIgwchk0glHLz7CQ-7"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDPsneZWaOFg0H2wsundyGr"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBhgcpA8eTYYWg7im72LgLt"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBbSLZjvleMwldX8jGgXV6a"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBuKtLgPR_zWYnrwv-JllpA"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBYxWxJtLi8c6PGjNKGYGZZ"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCSvv2N_6jhnEOZnq_419XJ"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGA8Vys-f48mAH9OKSUyav0q"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBqMdJssJaiG3c9RooWQiU3"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDV6SnbINlVUd0o2xT4JbMu"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDdduy0IPDDHYnUx66Vc4ed"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDi9F_slcQK7knjtO8TUvUs"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCbpkBEMiCaiu_3OL-_Bz_8"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBBnHFDEANbv9q8T4CONGZE"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBuWk2MR-drcaZAh8hdRUHq"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBmwvjJoWhM4Lg5MceSbsja"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBsINfLVidNVaZ-7_v1NJIo"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGC04FAovs0lswXTPXeomORn"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBI2ZFuyZOl5Q7sptR7PwYN"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCkg2uj3PxUWhMDuTw3VKjM"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGD3PLy3DZHr6-LpCY7irPU8"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBxQO2r_kmxn-0UqL_Rkj0t"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGA31Z378O2ef9AmpcMxpgh9"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCshbAx1JpBtNoKh8iKAAiy"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBPw1sFodruZUPheWVKchlM"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDQ5DrbIl20Zu9hx1IjeVhO"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBMdkKFn3HasZnnAqVjzHn_"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBzfXLWLSYVy8EbTdpGbUIG"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDgp7nGSUnnXihbTLFZJ79B"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBywvNsQ-1vEWwg3ITxbPPK"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBsvRxJJOzG4r4k_zLKrnxl"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAjkwJocj7vlc_mFU-4wXJq"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCQ_4eYaBs63qYWBHrzu-vK"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBaTsb1nse1UU48d_q7glGT"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBwibXFtPtflztSNPGuIB_d"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAcbMi1sH6oAMk4JHw91mC_"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAKIXv8Yr6nhGJ9Vlcjyymq"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDexNbWi0uPBP6buduUZO3Q"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAp287UuTE0-K7Ty-b8rGAX"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAfHxsK6bji7trLS-N0nKF-"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDdipQX00Uqw3EOoL8HEezh"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCzVMGCPi1kwvABu7eWv08P"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGD25IGk9Xf7oC3wiT9gC75x"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGChV7XQAqGqy0tFkD3BuwIU"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAKWClAD_iKpNC0bGHxGhcx"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDdCg0Jli_WTZd5JIliDY62"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCS7sMM-19z9_ud7F2SINJq"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDiJSXfsJTASx9eMq_HlenQ"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBpuvPW0aHa7mKdn_k9SPKO"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAdmjrf1RaZIJe2_3fGbhbu"
"https://www.youtube.com/playlist?list=PL7969A91C1F783A50"
"https://www.youtube.com/playlist?list=PLA128BFABEF2AF41E"
"https://www.youtube.com/playlist?list=PLD0D54219E5F2544D"
"https://www.youtube.com/playlist?list=PL210C2267A8922854"
"https://www.youtube.com/playlist?list=PLAB8BC9A8377E9EB1"
"https://www.youtube.com/playlist?list=PL998613A92710000C"
"https://www.youtube.com/playlist?list=PLDA9AF6952AA79306"
"https://www.youtube.com/playlist?list=PL043CDFD9CB6028AE"
"https://www.youtube.com/playlist?list=PL1512BD72E7C9FFCA"
"https://www.youtube.com/playlist?list=PL32BC9C878BA72085"
"https://www.youtube.com/playlist?list=PL3F6711C7BA727A5B"
"https://www.youtube.com/playlist?list=PL081AC329706B2953"
"https://www.youtube.com/playlist?list=PL9BB0E73446108855"
"https://www.youtube.com/playlist?list=PL83352B54BB64CBFB"
"https://www.youtube.com/playlist?list=PLC1322B5A0180C946"
"https://www.youtube.com/playlist?list=PLC601DEA22187BBF1"
"https://www.youtube.com/playlist?list=PLC6CB99FD653EEFBD"
"https://www.youtube.com/playlist?list=PL6B08BAA57B5C7810"
"https://www.youtube.com/playlist?list=PLA0B3471F221DBEBA"
"https://www.youtube.com/playlist?list=PLB86ED5918E79871A"
"https://www.youtube.com/playlist?list=PL53A392AD7B7FE261"
"https://www.youtube.com/playlist?list=PL0EE421AE8BCEBA4A"
"https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83"
"https://www.youtube.com/playlist?list=PLFF967D7CA020E636"
"https://www.youtube.com/playlist?list=PL442FA2C127377F07"
"https://www.youtube.com/playlist?list=PL46F0A159EC02DF82"
"https://www.youtube.com/playlist?list=PLAF739DF5F2D9506C"
"https://www.youtube.com/playlist?list=PLA5A1D544934F701B"
"https://www.youtube.com/playlist?list=PL4E7C4E197E814CAA"
"https://www.youtube.com/playlist?list=PL2F07DBCDCC01493A"
"https://www.youtube.com/playlist?list=PL9D20AB6CB5C8DBEC"
"https://www.youtube.com/playlist?list=PLD6327E00257AF1D0"
"https://www.youtube.com/playlist?list=PL53038489615793F7"
"https://www.youtube.com/playlist?list=PL640F44F1C97BA581"
"https://www.youtube.com/playlist?list=PLF67AD05E832199C4"
"https://www.youtube.com/playlist?list=PL079864199285AB36"
"https://www.youtube.com/playlist?list=PLFB14C99D7D219600"
"https://www.youtube.com/playlist?list=PL27BCE863B6A864E3"
"https://www.youtube.com/playlist?list=PL2660E16F8D75401F"
"https://www.youtube.com/playlist?list=PL26DCFC30381A4D5A"
"https://www.youtube.com/playlist?list=PLF2E4759682AD02E8"
"https://www.youtube.com/playlist?list=PLEB02A67A4C8FB8D6"
"https://www.youtube.com/playlist?list=PLA331A6709F40B79D"
"https://www.youtube.com/playlist?list=PL67D94BE42620925B"
"https://www.youtube.com/playlist?list=PLA12BF2F8CC489A50"
"https://www.youtube.com/playlist?list=PL4304A495B550ACE8"
"https://www.youtube.com/playlist?list=PL8E21BDD0981FDF66"
"https://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28"
"https://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA"
"https://www.youtube.com/playlist?list=PL78280D6BE6F05D34"
"https://www.youtube.com/playlist?list=PLC315B2A086BA6AAF"
"https://www.youtube.com/playlist?list=PL4C7FF93BF4770A10"
"https://www.youtube.com/playlist?list=PLF541C2C1F671AEF6"
"https://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28"
"https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83"
"https://www.youtube.com/playlist?list=PL081AC329706B2953"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAcbMi1sH6oAMk4JHw91mC_"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAKIXv8Yr6nhGJ9Vlcjyymq"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBpuvPW0aHa7mKdn_k9SPKO"
"https://www.youtube.com/playlist?list=PLC1322B5A0180C946"
"https://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA"
"https://www.youtube.com/playlist?list=PL46F0A159EC02DF82"
"https://www.youtube.com/playlist?list=PL442FA2C127377F07"
"https://www.youtube.com/playlist?list=PL32BC9C878BA72085"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK"
"https://www.youtube.com/playlist?list=PL2F07DBCDCC01493A"
"https://www.youtube.com/playlist?list=PLF541C2C1F671AEF6"
"https://www.youtube.com/playlist?list=PLC601DEA22187BBF1"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAKWClAD_iKpNC0bGHxGhcx"
"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCzVMGCPi1kwvABu7eWv08P"
)

# Define rclone remote name and destination folder
RCLONE_REMOTE="od_danishynayeem176:Public/YouTube/thenewboston"

# Loop through each playlist
for PLAYLIST_URL in "${PLAYLISTS[@]}"; do
    echo "Processing playlist: $PLAYLIST_URL"

    # Fetch the playlist title for folder naming
    PLAYLIST_TITLE=$(yt-dlp --flat-playlist --get-title "$PLAYLIST_URL" | head -n 1)

    # Replace spaces with underscores in the folder name
    FOLDER_NAME=$(echo "$PLAYLIST_TITLE" | tr ' ' '_')
    
    # Create a folder and download playlist
    echo "Downloading playlist to folder: $FOLDER_NAME"
    mkdir -p "$FOLDER_NAME"
    yt-dlp -P "$FOLDER_NAME" --yes-playlist "$PLAYLIST_URL" -f bestvideo+bestaudio

    # Check if download was successful
    if [ $? -ne 0 ]; then
        echo "Failed to download playlist: $PLAYLIST_URL"
        continue
    fi

    # Upload the folder to rclone remote
    echo "Uploading $FOLDER_NAME to rclone remote: $RCLONE_REMOTE"
    rclone -P copy "$FOLDER_NAME" "$RCLONE_REMOTE/$FOLDER_NAME"

    # Check if upload was successful
    if [ $? -eq 0 ]; then
        echo "Upload successful, deleting local folder: $FOLDER_NAME"
        rm -rf "$FOLDER_NAME"
    else
        echo "Upload failed for $FOLDER_NAME. Retaining local folder for manual handling."
    fi

    echo "Completed processing for playlist: $PLAYLIST_URL"
    echo "---------------------------------------------"
done

echo "All playlists processed."

