<commit_before># youtube_uploader.py 
# youtbe specific code

# caled from post_yt.py 
# which someday will be jsut post.py with a yt parameter.

# http://code.google.com/apis/youtube/1.0/developers_guide_python.html
# http://code.google.com/apis/youtube/2.0/reference.html

import gdata.media
import gdata.geo
import gdata.youtube
import gdata.youtube.service

from gdata.media import YOUTUBE_NAMESPACE
from atom import ExtensionElement

from gdata.youtube.service import YouTubeError

import pw
import progressbar


widgets = [
        'Upload: ',
        progressbar.Percentage(), ' ',
        progressbar.Bar(marker=progressbar.RotatingMarker()), ' ', 
        progressbar.ETA(), ' ',
        progressbar.FileTransferSpeed(),
        ]



def progress(current, blocksize, total):
    """
    Displaies upload percent done, bytes sent, total bytes.
    """
    elapsed = datetime.datetime.now() - self.start_time 
    remaining_bytes = total-current
    if elapsed.seconds: 
        bps = current/elapsed.seconds
        remaining_seconds = remaining_bytes / bps 
        eta = datetime.datetime.now() + datetime.timedelta(seconds=remaining_seconds)
        sys.stdout.write('\r%3i%%  %s of %s MB, %s KB/s, elap/remain: %s/%s, eta: %s' 
          % (100*current/total, current/(1024**2), total/(1024**2), bps/1024, stot(elapsed.seconds), stot(remaining_seconds), eta.strftime('%H:%M:%S')))
    else:
        sys.stdout.write('\r%3i%%  %s of %s bytes: remaining: %s'
          % (100*current/total, current, total, remaining_bytes, ))


class ProgressFile(file):
    def __init__(self, *args, **kw):
        file.__init__(self, *args, **kw)

        self.seek(0, 2)
        self.len = self.tell()
        self.seek(0)

        self.pbar = progressbar.ProgressBar(
            widgets=widgets, maxval=self.len)
        self.pbar.start()

    def size(self):
        return self.len

    def __len__(self):
        return self.size()

    def read(self, size=-1):
        if (size > 1e3):
                size = int(1e3)
        try:
            self.pbar.update(self.tell())
            return file.read(self, size)
        finally:
            self.pbar.update(self.tell())
            if self.tell() >= self.len:
                self.pbar.finish()

class Uploader(object):

    # input attributes:
    files = []
    thumb = ''
    meta = {}
    upload_user = ''
    old_url = ''
    user=''
    private=False
    debug_mode=False

    # return attributes:
    ret_text = ''
    new_url = ''

    def auth(self):
         
        yt_service = gdata.youtube.service.YouTubeService()
        gauth = pw.yt[self.user]

        yt_service.email = gauth['email']
        yt_service.password = gauth['password']
        yt_service.source = 'video eyebaal review'
        yt_service.developer_key = gauth['dev_key']
        yt_service.client_id = self.user

        yt_service.ProgrammaticLogin()

        return yt_service
       
    def media_group(self):
        # prepare a media group object to hold our video's meta-data

        tags = self.meta['tags']
        tags = [tag for tag in tags if " " not in tag]
        tags =','.join(tags) 

        media_group = gdata.media.Group(
            title=gdata.media.Title(
                text=self.meta['title']),
            description=gdata.media.Description(
                description_type='plain',
                text=self.meta['description']),
            keywords=gdata.media.Keywords(
                text=tags ),
            category=[gdata.media.Category(
                # label=self.meta['category'],
                # text=self.meta['category'],
                label="Education",
                text="Education",
                scheme='http://gdata.youtube.com/schemas/2007/categories.cat',
                )],
            player=None
            )

        if self.private:
            media_group.private=gdata.media.Private()

        return media_group


    def geo(self):
        # prepare a geo.where object to hold the geographical location
        # of where the video was recorded
        where = gdata.geo.Where()
        # where.set_location((37.0,-122.0))
        where.set_location(self.meta['latlon'])

        return where

 
    def upload(self):

        yt_service = self.auth()

        video_entry = gdata.youtube.YouTubeVideoEntry(
                media=self.media_group())

        if self.meta.has_key('latlon'):
            video_entry.geo = self.geo()

        # add some more metadata -  more tags
        print self.meta['tags']
        video_entry.AddDeveloperTags(self.meta['tags'])

        pathname= self.files[0]['pathname']

        pf = ProgressFile(pathname, 'r')
        try:
            # actually upload
            self.new_entry = yt_service.InsertVideoEntry(video_entry, pf)
            self.ret_text = self.new_entry.__str__()
            link = self.new_entry.GetHtmlLink()
            self.new_url = link.href.split('&')[0]
            print self.new_url
            ret = True

        except gdata.youtube.service.YouTubeError as e:<commit_msg>exclude tags with spaces<commit_after># youtube_uploader.py 
# youtbe specific code

# caled from post_yt.py 
# which someday will be jsut post.py with a yt parameter.

# http://code.google.com/apis/youtube/1.0/developers_guide_python.html
# http://code.google.com/apis/youtube/2.0/reference.html

import gdata.media
import gdata.geo
import gdata.youtube
import gdata.youtube.service

from gdata.media import YOUTUBE_NAMESPACE
from atom import ExtensionElement

from gdata.youtube.service import YouTubeError

import pw
import progressbar


widgets = [
        'Upload: ',
        progressbar.Percentage(), ' ',
        progressbar.Bar(marker=progressbar.RotatingMarker()), ' ', 
        progressbar.ETA(), ' ',
        progressbar.FileTransferSpeed(),
        ]



def progress(current, blocksize, total):
    """
    Displaies upload percent done, bytes sent, total bytes.
    """
    elapsed = datetime.datetime.now() - self.start_time 
    remaining_bytes = total-current
    if elapsed.seconds: 
        bps = current/elapsed.seconds
        remaining_seconds = remaining_bytes / bps 
        eta = datetime.datetime.now() + datetime.timedelta(seconds=remaining_seconds)
        sys.stdout.write('\r%3i%%  %s of %s MB, %s KB/s, elap/remain: %s/%s, eta: %s' 
          % (100*current/total, current/(1024**2), total/(1024**2), bps/1024, stot(elapsed.seconds), stot(remaining_seconds), eta.strftime('%H:%M:%S')))
    else:
        sys.stdout.write('\r%3i%%  %s of %s bytes: remaining: %s'
          % (100*current/total, current, total, remaining_bytes, ))


class ProgressFile(file):
    def __init__(self, *args, **kw):
        file.__init__(self, *args, **kw)

        self.seek(0, 2)
        self.len = self.tell()
        self.seek(0)

        self.pbar = progressbar.ProgressBar(
            widgets=widgets, maxval=self.len)
        self.pbar.start()

    def size(self):
        return self.len

    def __len__(self):
        return self.size()

    def read(self, size=-1):
        if (size > 1e3):
                size = int(1e3)
        try:
            self.pbar.update(self.tell())
            return file.read(self, size)
        finally:
            self.pbar.update(self.tell())
            if self.tell() >= self.len:
                self.pbar.finish()

class Uploader(object):

    # input attributes:
    files = []
    thumb = ''
    meta = {}
    upload_user = ''
    old_url = ''
    user=''
    private=False
    debug_mode=False

    # return attributes:
    ret_text = ''
    new_url = ''

    def auth(self):
         
        yt_service = gdata.youtube.service.YouTubeService()
        gauth = pw.yt[self.user]

        yt_service.email = gauth['email']
        yt_service.password = gauth['password']
        yt_service.source = 'video eyebaal review'
        yt_service.developer_key = gauth['dev_key']
        yt_service.client_id = self.user

        yt_service.ProgrammaticLogin()

        return yt_service
       
    def media_group(self):
        # prepare a media group object to hold our video's meta-data

        tags = self.meta['tags']
        tags = [tag for tag in tags if " " not in tag]
        tags =','.join(tags) 
        print tags

        media_group = gdata.media.Group(
            title=gdata.media.Title(
                text=self.meta['title']),
            description=gdata.media.Description(
                description_type='plain',
                text=self.meta['description']),
            keywords=gdata.media.Keywords(
                text=tags ),
            category=[gdata.media.Category(
                # label=self.meta['category'],
                # text=self.meta['category'],
                label="Education",
                text="Education",
                scheme='http://gdata.youtube.com/schemas/2007/categories.cat',
                )],
            player=None
            )

        if self.private:
            media_group.private=gdata.media.Private()

        return media_group


    def geo(self):
        # prepare a geo.where object to hold the geographical location
        # of where the video was recorded
        where = gdata.geo.Where()
        # where.set_location((37.0,-122.0))
        where.set_location(self.meta['latlon'])

        return where

 
    def upload(self):

        yt_service = self.auth()

        video_entry = gdata.youtube.YouTubeVideoEntry(
                media=self.media_group())

        if self.meta.has_key('latlon'):
            video_entry.geo = self.geo()

        # add some more metadata -  more tags
        print self.meta['tags']

        tags = self.meta['tags']
        tags = [tag for tag in tags if " " not in tag]
        tags =','.join(tags) 
        print tags
        video_entry.AddDeveloperTags(tags)

        pathname= self.files[0]['pathname']

        pf = ProgressFile(pathname, 'r')
        try:
            # actually upload
            self.new_entry = yt_service.InsertVideoEntry(video_entry, pf)
            self.ret_text = self.new_entry.__str__()
            link = self.new_entry.GetHtmlLink()
            self.new_url = link.href.split('&')[0]
            print self.new_url
            ret = True

        except gdata.youtube.service.YouTubeError as e:
{'fraction_non_alphanumeric': 0.12153352145567772, 'fraction_numerical': 0.009146638123966138, 'mean_word_length': 2.0818590704647675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3077944', 'n_tokens_mistral': 3266, 'n_tokens_neox': 3054, 'n_words': 630}