import json
import sys
from simple_youtube_api.Channel import Channel
from simple_youtube_api.LocalVideo import LocalVideo


def main():
    # loggin into the channel
    channel = Channel()
    channel.login("client_secret.json", "credentials.storage")

    list_file_path = 'new-videos.txt'
    if len(sys.argv) > 1:
        list_file_path = sys.argv[1]
    print(list_file_path)
    with open(list_file_path, 'r') as list_file:
        for line in list_file.readlines():
            file_path, title, description, playlist_id = json.loads(line.strip())

            # setting up the video that is going to be uploaded
            video = LocalVideo(file_path=file_path)

            # setting snippet
            video.set_title(title)
            video.set_description(description)
            video.set_category("education")
            video.set_default_language("ru-RU")

            # setting status
            # video.set_embeddable(True)
            # video.set_license("creativeCommon")
            video.set_privacy_status("private")
            video.set_public_stats_viewable(True)

            # uploading video and printing the results
            video = channel.upload_video(video)
            print(video.id)
            print(video)

            # add to playlist
            channel.add_video_to_playlist(playlist_id, video)


if __name__ == '__main__':
    main()
