File: YourVideo.aspx.cs

package info (click to toggle)
gdata-sharp 2.2.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 12,092 kB
  • sloc: cs: 67,781; xml: 38,234; python: 163; makefile: 149; sh: 27
file content (96 lines) | stat: -rw-r--r-- 3,588 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using Google.GData.Client;
using Google.GData.Extensions.MediaRss;
using Google.GData.YouTube;


public partial class YourVideo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void CheckForUpload()
    {
        string status = Request.QueryString["status"];
        string id = Request.QueryString["id"];
        
        if (status != null)
        {
            if (status == "200")
            {
                Response.Write("<div>Video uploaded successfully!</div>");
            }
            else
            {
                Response.Write("<div>Video failed with code " + status);
            }
        }
    }

    protected void SubmitVideo_ServerClick(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(this.Title.Text) == false &&
            String.IsNullOrEmpty(this.Description.Text) == false &&
            String.IsNullOrEmpty(this.Category.SelectedValue) == false &&
            String.IsNullOrEmpty(this.Keyword.Text) == false)
        {

            GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory(ServiceNames.YouTube, "TesterApp");

            YouTubeService service = new YouTubeService(authFactory.ApplicationName,
                "ytapi-FrankMantek-TestaccountforGD-sjgv537n-0",
                "AI39si4v3E6oIYiI60ndCNDqnPP5lCqO28DSvvDPnQt-Mqia5uPz2e4E-gMSBVwHXwyn_LF1tWox4LyM-0YQd2o4i_3GcXxa2Q"
                );

            authFactory.Token = HttpContext.Current.Session["token"] as string;
            service.RequestFactory = authFactory;

            try
            {
                YouTubeEntry entry = new YouTubeEntry();
                
                entry.Media = new Google.GData.YouTube.MediaGroup();
                entry.Media.Description = new MediaDescription(this.Description.Text);
                entry.Media.Title = new MediaTitle(this.Title.Text);
                entry.Media.Keywords = new MediaKeywords(this.Keyword.Text);

                // entry.Media.Categories
                MediaCategory category = new MediaCategory(this.Category.SelectedValue);
                category.Attributes["scheme"] = YouTubeService.DefaultCategory;

                entry.Media.Categories.Add(category);
                FormUploadToken token = service.FormUpload(entry);
                HttpContext.Current.Session["form_upload_url"] = token.Url;
                HttpContext.Current.Session["form_upload_token"] = token.Token;
                string page = "http://" + Request.ServerVariables["SERVER_NAME"];
                if (Request.ServerVariables["SERVER_PORT"] != "80")
                {
                    page += ":" + Request.ServerVariables["SERVER_PORT"];
                }
                page += Request.ServerVariables["URL"];

                HttpContext.Current.Session["form_upload_redirect"] = page;
                Response.Redirect("UploadVideo.aspx");
            }
            catch (GDataRequestException gdre)
            {
                HttpWebResponse response = (HttpWebResponse)gdre.Response;
            }
        }
    }
    protected void Refresh_Click(object sender, EventArgs e)
    {
        this.ObjectDataMostPopular.Select();
    }
}