#!/usr/bin/env python # -*- coding: utf-8 -*- # Tubedl Video İndirme Aracı # http://tubedl.googlecode.com/ """ Copyright (C) 2007 - 2008 Oğuzhan Eroğlu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import os import sys import re try: import urlgrabber import urlgrabber, urlgrabber.progress except(ImportError): print "Hata[0]: Sisteminizde urlgrabber modülü kurulu değil." sys.exit() # Uygulama için gerekli olan değişkenleri tanımlıyoruz prgs = urlgrabber.progress.text_progress_meter() destek = ("youtube.com", "google.com", "izlesene.com", "trtube.com", "capturetv.com", "vidivodo.com", "metacafe.com", "dailymotion.com", "break.com") arguman = ("--yardim", "--destek") yardim_metni = \ """ Kullanım Şekli: tubedl "adres" [isim veya fonksiyonu] [çevirilecek dosya türü veya fonksiyonu] [ekstra fonksiyon] İsim Fonksiyonları: -at = Dosya adı yerine verdiğiniz adresin başlığını yazar. Çevirme fonksiyonları: -cevirme = Flv dosyasını çevirmez. Ekstra Fonksiyonlar: -flvsil = Flv dosyasını siler. Desteklenen siteler için "tubedl --destek" komutuna bakın. Uyarı: Bazı sitelerin adreslerinde & karakteri bulunduğu için adresleri "" karakterleri arasına yazın. Örnek Kullanım: tubedl http://www.youtube.com/watch?v=YVGj44PeGaI deneme-youtube avi """ # Verilen dosya isminin olup olmadığını kontrol ediyoruz. def dkontrol(dosya_adi, cisim): def soru(): if cevap == "h": print "Program sonlandırılıyor..." sys.exit() if cevap == "e": pass if (os.path.exists("%s.%s" % (dosya_adi, cisim)) or os.path.exists(dosya_adi)): print "Hata[3] Dosya Hatası:\nBelirtilen dosya zaten var (%s*)." % (dosya_adi) cevap = raw_input("Devam edilsinmi? ('e'vet, 'h'ayır): ") soru() while cevap not in ("e", "h"): print " * Geçersiz seçenek..." cevap = raw_input("Devam edilsinmi? ('e'vet, 'h'ayır): ") soru() # otomatik isim alma fonksiyonları def at(url_read, name, cisim): title = re.compile("(.*?)", re.IGNORECASE).findall(url_read)[0] try: if sys.argv[2] == "-at": return title else: return name except: pass # Çevirme fonksiyonu def cevir(name, uzanti): if cisim != "-cevirme": print "\033[01;34mDosya %s'ye çeviriliyor\033[0m" % (uzanti) os.system("ffmpeg -i '%s' '%s.%s'" % (name, name, uzanti)) print "\033[1;36mVideo %s'ye çevirildi.\033[0m" % (uzanti) try: if sys.argv[4] == "-flvsil": os.remove(name) print "\033[1;33mflv dosyası silindi...\033[0m" except: pass else: pass # Siteler için indirme ve çevirme fonksiyonları def indircevir(adres, name, cisim): urlgrabber.urlgrab(adres, name, progress_obj=prgs) cevir(name, cisim) # İndirme fonksiyonları def youtube_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) paramr = re.compile("var swfArgs.*").findall(url_read)[0] param = re.compile('"t": "(.*?)"').findall(paramr)[0] video_id = re.compile('"video_id": "(.*?)"').findall(paramr)[0] final_url = "http://youtube.com/get_video.php?video_id="+video_id+"&t="+param indircevir(final_url, name, cisim) def izlesene_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) flv = re.compile("(http://.*?.flv)").findall(url_read) flv_dl = flv[1] indircevir(flv_dl, name, cisim) def trtube_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) flv_dl = re.compile("(http://www.trtube.com/vid./.*?.flv)").findall(url_read)[0] indircevir(flv_dl, name, cisim) def capturetv_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) flv = url[56:67] flv_dl = "http://www.youtube.com/watch?v=%s" % (flv) youtube_com(flv_dl, name, cisim) def vidivodo_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) url_flv = re.compile("vidservers/server../videos/.{4}/../../../.{22}.flv") flv = flv = url_flv.findall(url_read) flv_dl = "http://www.vidivodo.com/%s" % (flv[0]) indircevir(flv_dl, name, cisim) def metacafe_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) flv_url = re.compile("http://akvideos.metacafe.com/ItemFiles/.*?.flv").findall(url_read)[0].replace("%5B", "[").replace("%5D", "]").replace("%20", " ") indircevir(flv_url, name, cisim) def dailymotion_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) url_flv = re.compile("http%3A%2F%2Fwww.dailymotion.com%2Fget%2F..%2F...x...%2Fflv%2F.{7}.flv%3Fkey%3D.{39}") flv_read = url_flv.findall(url_read)[0] flv_dl = flv_read.replace("%2F", "/").replace("%3A", ":").replace("%3F", "?").replace("%3D", "=") indircevir(flv_dl, name, cisim) def break_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) url_flv = re.compile("http://media1.break.com/dnet/media/.{26}/.{19}.flv").findall(url_read)[0] url_d1 = re.compile("sGlobalContentFilePath='.{4}/.?'").findall(url_read)[0] url_d1_c1 = url_d1[24:-1] url_d2 = re.compile("sGlobalFileName='.*?'").findall(url_read)[0] url_d2_c1 = url_d2[17:-1] url_dl = url_flv.replace("'+sGlobalContentFilePath+'", url_d1_c1).replace("'+sGlobalFileName+'", url_d2_c1) indircevir(url_dl, name, cisim) def google_com(url, name, cisim): url_read = urlgrabber.urlread(url) name = at(url_read, name, cisim) url_flv = re.compile('