27 Temmuz 2015 Pazartesi

c# youtube video bilgileri alma

YouTube and Vimeo provide a data API that you can use to get information for their videos. YouTube requires the use of an API key and you can get one for free. At the bottom of the article you will see the required steps to obtain a YouTube API key.

Vimeo on the other hand provides a simple API that does not require an API key. For authenticated read/write requests Vimeo provides the advanced API, which requires an API key. In this article we will see an example with the simple API.
In both cases we perform a web request and get back an JSON file with the video’s data. We will use the using System.Web.Helpers; extension to be able to read the data without writing a class to represent the JSON object.
Note: The post has been updated to reflect the recent changes of the YouTube API
using System.Net;
using System.Web.Helpers;
using System.Web.Script.Serialization;
 
class Video
{
    public const string ytKey = "";
 
    public int Width { get; set; }
    public int Height { get; set; }
    public int Duration { get; set; }
    public string Title { get; set; }
    public string ThumbUrl { get; set; }
    public string BigThumbUrl { get; set; }
    public string Description { get; set; }
    public string VideoDuration { get; set; }
    public string Url { get; set; }
    public DateTime UploadDate { get; set; }
 
    public Video()
    {
    }
 
    public bool YouTubeImport(string VideoID)
    {
        try
        {
            WebClient myDownloader = new WebClient();
            myDownloader.Encoding = System.Text.Encoding.UTF8;
 
            string jsonResponse = myDownloader.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + VideoID + "&key=" + ytKey + "&part=snippet");
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var dynamicObject = Json.Decode(jsonResponse);
            var item = dynamicObject.items[0].snippet;
 
            Title = item.title;
            ThumbUrl = item.thumbnails.@default.url;
            BigThumbUrl = item.thumbnails.high.url;
            Description = item.description;
            UploadDate = Convert.ToDateTime(item.publishedAt);
 
            jsonResponse = myDownloader.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + VideoID + "&key=" + ytKey + "&part=contentDetails");
            dynamicObject = Json.Decode(jsonResponse);
            string tmp = dynamicObject.items[0].contentDetails.duration;
            Duration = Convert.ToInt32(System.Xml.XmlConvert.ToTimeSpan(tmp).TotalSeconds);
 
            Url = "http://www.youtube.com/watch?v=" + VideoID;
 
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
 
    public bool VimeoImport(string VideoID)
    {
        try
        {
            WebClient myDownloader = new WebClient();
            myDownloader.Encoding = System.Text.Encoding.UTF8;
 
            string jsonResponse = myDownloader.DownloadString("http://vimeo.com/api/v2/video/" + VideoID + ".json");
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var dynamicObject = Json.Decode(jsonResponse);
            var item = dynamicObject[0];
 
            Title = item.title;
            Description = item.description;
            Url = item.url;
            ThumbUrl = item.thumbnail_small;
            BigThumbUrl = item.thumbnail_large;
            UploadDate = Convert.ToDateTime(item.upload_date);
            Width = Convert.ToInt32(item.width);
            Height = Convert.ToInt32(item.height);
            Duration = Convert.ToInt32(item.duration);
 
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
}
Note: The Vimeo API can give its data in XML, JSON and PHP format. This can be done easily by setting the URL’s suffix to ‘.xml’ or ‘.json’ or ‘.php’.

How to get a YouTube API key

  1. First, you need to login tohttps://console.developers.google.com/.
  2. Go to APIs and auth and then APIs. You need to search and enable the YouTube Data API as well as theFreebase API.
  3. Set its status to ON and accept it’s Terms of Use.
  4. Go to APIs and auth and then Credentials and create a new key in the Public API access area.
Note that this API key is not only for YouTube, but for many Google services such as Google Maps API, Custom Search API, etc.

Links

26 Temmuz 2015 Pazar

C# içinde kod derleme nasıl yapılır



ÖNEMLİ: Bu makale, Microsoft Makine Çevirisi Düzenleme yazılımı tarafından tercüme edilmiş olup, yüksek olasılıkla profesyonel bir çevirmen yerine CTF teknolojisi kullanılarak, Microsoft Topluluğu tarafından düzenlenmiştir. Microsoft, Bilgi Bankamız içindeki tüm makaleleri kendi dilinizde okuyabilmeniz için size hem profesyonel çevirmenler tarafından tercüme edilen hem de makine tarafından tercüme edildikten sonra Topluluk tarafından kontrol edilen makaleler sunar. Bununla birlikte, makine tarafından tercüme edilen, hatta Topluluk tarafından kontrol edilen bir makale bile her zaman mükemmel dil kalitesinde olmayabilir. Makalede dilinizi konuşan yabancı birisinin yapabileceği türden sözcük, söz dizimi veya dilbilgisi hataları bulunabilir. Microsoft, içeriğin hatalı tercümesinin veya müşterilerimiz tarafından kullanımının doğurabileceği olası yanlış anlamalar, hatalar veya zararlardan sorumlu değildir. Öte yandan Microsoft, Makine Çevirisi Düzenleme işlemini geliştirmek amacıyla Makine Çevirisi Düzenleme yazılımını ve araçlarını sık sık güncelleştirmektedir.

Bu makalede Visual Basic .NET sürümü için bkz: 
ÖZET
.NET Framework, C# dil derleyici program aracılığıyla erişmek izin sınıflarını sunar. Kendi kodu derleme yardımcı programları yazmak istiyorsanız yararlı olabilir. Bu makale, metin kaynak kodundan derlemek sağlayan örnek kodu sağlar. Uygulama ya da sadece yürütülebiliri oluştur veya yürütülebiliri oluştur ve çalıştırmak izin verir. Derleme işlemi sırasında oluşan hataları formda görüntülenir.
DAHA FAZLA BİLGİ

Adım 1: gereksinimleri

  • Visual Studio
  • Visual C# dil derleyici

Adım 2: Program aracılığıyla Kodu derlemek nasıl

.NET Framework ICodeCompiler derleyici yürütme arabirimi sağlar. CSharpCodeProvider sınıf bu arabirimini uygulayan ve C# kod üreticisi ve derleyici kod örneklerinin erişim sağlar. Aşağıdaki örnek koduCSharpCodeProvider bir örneğini oluşturur ve ICodeCompiler arabirimi başvuru almak için kullanır.

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
    

ICodeCompiler arabirimi başvuru edindikten sonra kaynak kodunuzu derlemek için kullanabilirsiniz.CompilerParameters sınıfını kullanarak derleyici için parametreleri geçirir. İşte bir örnek:

System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
CompilerResults results = icc.CompileAssemblyFromSource(parameters,SourceString);
    

Yukarıdaki kod Derleyici yürütülebilir bir dosya (DLL) yerine oluşturmak istediğiniz ve disk için oluşturulan derleme çıktısını almak istediğiniz söylemek için CompilerParameters nesnesini kullanır. CompileAssemblyFromSource için burada derleme derlenmiş çağrısıdır. Bu yöntem parametreleri nesne ve kaynak kodu, bir dize alır. Kodunuzu derlemek sonra derleme hataları olup olmadığını görmek için kontrol edebilirsiniz. Bir CompilerResults nesnesiCompileAssemblyFromSource, gelen bir dönüş değeri kullanın. Bu nesne, derleme sırasında oluşan hatalar içeren bir hata koleksiyonu içerir.

   if (results.Errors.Count > 0)
   {
    foreach(CompilerError CompErr in results.Errors)
    {
     textBox2.Text = textBox2.Text +
         "Line number " + CompErr.Line + 
         ", Error Number: " + CompErr.ErrorNumber + 
         ", '" + CompErr.ErrorText + ";" + 
         Environment.NewLine + Environment.NewLine;
    }
   }
    

Derleme, bir dosyadan derleme gibi diğer seçenekleri vardır. Aynı anda birden fazla dosya veya kaynakları derlemek yani derleme toplu iş. Bu sınıflar hakkında ek bilgi MSDN Çevrimiçi Kitaplığı'nda bulunabilir:
Adım 3: Adım adım yordam örneği
  1. Yeni bir Visual C# .NET Windows uygulaması oluşturun. Varsayılan olarak, Form1 oluşturulur.
  2. Düğme denetimi Form1'e ekleyin ve sonra Yapı Text özelliğini değiştirin.
  3. Başka bir Düğme denetimi Form1'e ekleyin ve çalıştırınve Text özelliğini değiştirin.
  4. İki TextBox denetimi Form1'e ekleyin, her iki denetimin Multiline özelliğini Trueolarak ayarlar ve sonra bu denetimleri her biri birden çok metin satırı yapıştırabilirsiniz şekilde boyutlandırmak.
  5. Kod Düzenleyicisi'nde, Form1.cs kaynak dosyasını açın.
  6. Form1 sınıfında düğme tıklama işleyicisini yapıştırın.
    private void button1_Click(object sender, System.EventArgs e)
    {
        CSharpCodeProvider codeProvider = new CSharpCodeProvider();
        ICodeCompiler icc = codeProvider.CreateCompiler();
        string Output = "Out.exe";
        Button ButtonObject = (Button)sender;
    
        textBox2.Text = "";
        System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
        //Make sure we generate an EXE, not a DLL
        parameters.GenerateExecutable = true;
        parameters.OutputAssembly = Output;
        CompilerResults results = icc.CompileAssemblyFromSource(parameters, textBox1.Text);
    
        if (results.Errors.Count > 0)
        {
            textBox2.ForeColor = Color.Red;
            foreach (CompilerError CompErr in results.Errors)
            {
                textBox2.Text = textBox2.Text +
                            "Line number " + CompErr.Line +
                            ", Error Number: " + CompErr.ErrorNumber +
                            ", '" + CompErr.ErrorText + ";" +
                            Environment.NewLine + Environment.NewLine;
            }
        }
        else
        {
            //Successful Compile
            textBox2.ForeColor = Color.Blue;
            textBox2.Text = "Success!";
            //If we clicked run then launch our EXE
            if (ButtonObject.Text == "Run") Process.Start(Output);
        }
    }
    Add the beginning of the file, add these using statements:
    using System.CodeDom.Compiler;
    using System.Diagnostics;
    using Microsoft.CSharp;
    
    Not: CSharpCodeProvider sınıf Visual Studio 2005 veya Visual Studio 2008 kullanıyorsanız, onaylanmaz.Bunun yerine, aşağıdaki button1_Click uygulanmasında gösterildiği gibi CodeDomProvider sınıfını kullanabilirsiniz.
    private void button1_Click(object sender, System.EventArgs e)
    {
        CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
        string Output = "Out.exe";
        Button ButtonObject = (Button)sender;
    
        textBox2.Text = "";
        System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
        //Make sure we generate an EXE, not a DLL
        parameters.GenerateExecutable = true;
        parameters.OutputAssembly = Output;
        CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, textBox1.Text);
    
        if (results.Errors.Count > 0)
        {
            textBox2.ForeColor = Color.Red;
            foreach (CompilerError CompErr in results.Errors)
            {
                textBox2.Text = textBox2.Text +
                            "Line number " + CompErr.Line +
                            ", Error Number: " + CompErr.ErrorNumber +
                            ", '" + CompErr.ErrorText + ";" +
                            Environment.NewLine + Environment.NewLine;
            }
        }
        else
        {
            //Successful Compile
            textBox2.ForeColor = Color.Blue;
            textBox2.Text = "Success!";
            //If we clicked run then launch our EXE
            if (ButtonObject.Text == "Run") Process.Start(Output);
        }
    }
    Add the beginning of the file, add these using statements:
    using System.CodeDom.Compiler;
    using System.Diagnostics;
    
  7. Form1.cs dosyasýnýn Form1 kurucusunu bulun.
  8. Form1 kurucusunda InitializeComponent çağrısının ekledikten sonra düğmesi kablo aşağıdaki kodu işleyiciye Form1'e eklediğiniz her iki düğmesi tıklatın.
    public Form1()
    {
        InitializeComponent();
        this.button1.Click += new System.EventHandler(this.button1_Click);
        this.button2.Click += new System.EventHandler(this.button1_Click);
    }
    
  9. Projeyi çalıştırın. Form1 yüklendikten sonra Oluştur düğmesini tıklatın. Derleyici hatası aldığınız dikkat edin.
  10. Daha sonra varolan herhangi bir metni değiştirme metin kutusuna, aşağıdaki metni kopyalayın:
    
    using System;
    
    namespace HelloWorld
    {
     /// <summary>
     /// Summary description for Class1.
     /// </summary>
     class HelloWorldClass
     {
      static void Main(string[] args)
      {
       Console.WriteLine("Hello World!");
       Console.ReadLine();
      }
     }
    }
         
  11. Yeniden Oluştur ' u tıklatın. Derleme başarılı olması gerekir.
  12. Çalıştır' ı tıklatın ve bu kodu derlemek ve ortaya çıkan yürütülebilir dosyayı çalıştırın. Derleme çalıştırdığınız uygulama ile aynı klasörde kaydedilir "Out.exe" adlı bir yürütülebilir dosya oluşturur.

    NOT Farklı derleyici hataları görmek için metin kutusu kodu değiştirebilirsiniz. Örneğin, noktalı birini silin ve kodu yeniden oluşturun.
  13. Son olarak, metin kutusunda metin konsol penceresine başka bir satır çıktısını almak için kodu değiştirin.Çýktýyý görmek için Çalıştır ' ı tıklatın.

21 Temmuz 2015 Salı

c# crwaler yapımı 1

public ISet<string> GetNewLinks(string content)
{
    Regex regexLink = new Regex("(?<=<a\\s*?href=(?:'|\"))[^'\"]*?(?=(?:'|\"))");

    ISet<string> newLinks = new HashSet<string>();    
    foreach (var match in regexLink.Matches(content))
    {
        if (!newLinks.Contains(match.ToString()))
            newLinks.Add(match.ToString());
    }

    return newLinks;
}

13 Temmuz 2015 Pazartesi

c# kaldıgı yerden devam etmek için

c# kaldıgı numaradan devam etmek için kodlar..


 private void SonIDOku()
        {
            try
            {
                string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string str2 = "";
                if (File.Exists(folderPath + @"\lastid.txt"))
                {
                    StreamReader reader = new StreamReader(folderPath + @"\lastid.txt");
                    str2 = reader.ReadLine();
                    reader.Close();
                    this.index_value = Convert.ToInt32(str2);
                }
                else
                {
                    this.index_value = 0;
                }
            }
            catch (Exception)
            {
                this.index_value = 0;
            }
        }

        private void SonIDYaz()
        {
            try
            {
                string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                File.Create(folderPath + @"\lastid.txt").Close();
                TextWriter writer = new StreamWriter(folderPath + @"\lastid.txt", true);
                int num = this.index_value + 1;
                writer.Write(num);
                writer.Close();
            }
            catch (Exception)
            {
            }
        }

C# ip adresi alma öğrenme kullanma

c# ile ip adresi bulma kaynak kod ip adresi ,wan ip adresini bulmak için ,internetten ip almak için gerekli kod.

 private string getExternalIp()
        {
            try
            {
                return new WebClient().DownloadString("http://ipinfo.io/ip");
            }
            catch
            {
                return null;
            }
        }

C# http request oluşturma

c# ile http request oluşturmak için gerekli kaynak kod


            // Create a request for the URL. 
            WebRequest request = WebRequest.Create (
              "http://www.contoso.com/default.html");
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            WebResponse response = request.GetResponse ();
            // Display the status.
            Console.WriteLine (((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader (dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd ();
            // Display the content.
            Console.WriteLine (responseFromServer);
            // Clean up the streams and the response.
            reader.Close ();
            response.Close ();

2 kelime arasını alma

c# ile 2 kelime arasındaki ifadeyi almak kaynak kodu regex

try {
                Match m = Regex.Match(metin, "<" + kelime + ">(.*?)</" + kelime + ">");
                return m.Groups[1].Captures[0].Value;
         
 }catch { return "hata"; }

10 Temmuz 2015 Cuma

C# FFmpeg Download Link

C# ffmpeg download link 32 bit http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z

C# FFmpeg Komutlar Video birleştirme ses ekleme

ses silme:
ffmpeg -i video.mp4 -c copy -an videoo.mp4



ses ekleme:
ffmpeg.exe -i oo.mp3 -i f.mp4 -acodec copy -vcodec copy muxed.mp4



video hızlandırma ses sorunlu
ffmpeg -i video.mp4 -vf setpts=(0.8)*PTS output.mp4


parta bölme
ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4



video birleştirme

ffmpeg -f concat -i file-list.txt -c copy output.mp4


ses kaldırma

ffmpeg -i video.mp4 -an mute-video.mp4


müziği alma:

ffmpeg -i video.mp4 -vn -ab 256 audio.mp3

video gif çevirme :

ffmpeg -i video.mp4 -vf scale=500:-1 -t 10 -r 10 image.gif


video resme çevirme:
ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png


videoyu yeniden boyutlandırma:

ffmpeg -i input.mp4 -s 480x320 -c:a copy output.mp4

video yazı ekleme :

ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv

video sesin miktarını değiştirme:

ffmpeg -i input.wav -af 'volume=0.5' output.wav

video yönünü değiştirme:

ffmpeg -i input.mp4 -filter:v 'transpose=1' rotated-video.mp4


ffmpeg -i input.mp4 -filter:v 'transpose=2,transpose=2' rotated-video.mp4