<commit_before>
import logging
import os
import sys
from pprint import pprint, pformat

import sloelib
from sloeyoutube import SloeYouTubePlaylist, SloeYouTubeSession, SloeYouTubeUpload

class SloePluginYoutube(sloelib.SloeBasePlugIn):

    def command_youtubeauth(self, params, options):
        session_r = SloeYouTubeSession("r")
        session_r()
        session_w = SloeYouTubeSession("w")
        session_w()    
        session_upload = SloeYouTubeSession("upload")
        session_upload()


    def command_youtubedumptree(self, params, options):
        session_r = SloeYouTubeSession("r")
        tree = sloeyoutube.SloeYouTubeTree(session_r)
        tree.read()
        print tree



    def _get_youtube_spec_for_item(self, item, remoteitem, transferspec):
        youtube_spec = {
            "filepath": item.get_file_path(),
        }
        
        elements = (
            "category",
            "description",
            "privacy",
            "tags",
            "title"
        )
        
        for element in elements:
            youtube_spec[element] = sloelib.SloeOutputUtil.substitute_for_remote_item(
                getattr(transferspec, 'youtube_' + element), item, remoteitem, transferspec)
         
           
        tags = youtube_spec["tags"].split(":,")
        tags.append("oarstackremoteitem=%s" % remoteitem.uuid)
        youtube_spec["tags"] = ",".join([x.strip() for x in tags])

        return youtube_spec
    

    def do_item_transfer_job(self, item, transferspec):
        try:
            remoteitem = sloelib.SloeOutputUtil.find_remoteitem(item, transferspec)
            
            youtube_spec = self._get_youtube_spec_for_item(item, remoteitem, transferspec)
            
            logging.debug("youtube_spec=%s" % pformat(youtube_spec))
            youtube_session = SloeYouTubeSession("upload")
            remote_id = sloeyoutube.SloeYouTubeUpload.do_upload(youtube_session, youtube_spec)

            remoteitem.update({
                "description": youtube_spec["description"],
                "remote_id": remote_id,
                "remote_url": "http://youtu.be/%s" % remote_id,
                "title": youtube_spec["title"]
            })
            
            remoteitem.verify_creation_data()<commit_msg>Youtube upload fix<commit_after>
import logging
import os
import sys
from pprint import pprint, pformat

import sloelib
from sloeyoutube import SloeYouTubePlaylist, SloeYouTubeSession, SloeYouTubeUpload

class SloePluginYoutube(sloelib.SloeBasePlugIn):

    def command_youtubeauth(self, params, options):
        session_r = SloeYouTubeSession("r")
        session_r()
        session_w = SloeYouTubeSession("w")
        session_w()    
        session_upload = SloeYouTubeSession("upload")
        session_upload()


    def command_youtubedumptree(self, params, options):
        session_r = SloeYouTubeSession("r")
        tree = SloeYouTubeTree(session_r)
        tree.read()
        print tree



    def _get_youtube_spec_for_item(self, item, remoteitem, transferspec):
        youtube_spec = {
            "filepath": item.get_file_path(),
        }
        
        elements = (
            "category",
            "description",
            "privacy",
            "tags",
            "title"
        )
        
        for element in elements:
            youtube_spec[element] = sloelib.SloeOutputUtil.substitute_for_remote_item(
                getattr(transferspec, 'youtube_' + element), item, remoteitem, transferspec)
         
           
        tags = youtube_spec["tags"].split(":,")
        tags.append("oarstackremoteitem=%s" % remoteitem.uuid)
        youtube_spec["tags"] = ",".join([x.strip() for x in tags])

        return youtube_spec
    

    def do_item_transfer_job(self, item, transferspec):
        try:
            remoteitem = sloelib.SloeOutputUtil.find_remoteitem(item, transferspec)
            
            youtube_spec = self._get_youtube_spec_for_item(item, remoteitem, transferspec)
            
            logging.debug("youtube_spec=%s" % pformat(youtube_spec))
            youtube_session = SloeYouTubeSession("upload")
            remote_id = SloeYouTubeUpload.do_upload(youtube_session, youtube_spec)

            remoteitem.update({
                "description": youtube_spec["description"],
                "remote_id": remote_id,
                "remote_url": "http://youtu.be/%s" % remote_id,
                "title": youtube_spec["title"]
            })
            
            remoteitem.verify_creation_data()
{'fraction_non_alphanumeric': 0.09576103667911268, 'fraction_numerical': 0.0, 'mean_word_length': 2.2786177105831533, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1764927', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1289, 'n_words': 229}