#26 Le 22/09/2014, à 19:51
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Ca y est, premier commit !
Debian 12 sur Thinkpad reconditionné
Hors ligne
#27 Le 01/11/2014, à 22:27
- pguimier
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Bon apparemment l'API de iplayer a changé, et get-iplayer n'a pas encore suivi la modif, cf https://bugs.debian.org/cgi-bin/bugrepo … bug=767331
Malheureusement j'ai bien l'impression que tout le script dépend de ce soft !
Hors ligne
#28 Le 01/11/2014, à 22:32
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Ca confirme le fait qu'il faut remplacer l'appel à get_iplayer par du code à soi.
Il y a du code Python qui fait l'équivalent, je l'ai noté quelque part.
Debian 12 sur Thinkpad reconditionné
Hors ligne
#29 Le 01/11/2014, à 22:42
- pguimier
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Oui ici je crois : https://gitlab.com/k3ck3c/recup_bbc_replay/wikis/home
Pour remplacer get_iplayer (écrit en Perl) on pourra s'inspirer de
https://github.com/rbrito/pkg-youtube-d … bbccouk.py
ou de
EDIT:
En fait get_iplayer n'est plus capable de récupérer le numéro d'une émission, mais il est toujours possible de l'utiliser pour enregistrer les émissions, soit par le PID, soit par l'url. Exemple qui fonctionne si on change dans bbc33.py (ligne 109):
cmds = "get_iplayer --get "+idvideo + " --nopurge --modes=best --subtitles --force -p 'http://"+host+":"+port+"'"
par
cmds = "get_iplayer --url '"+idvideo + "' --nopurge --modes=best --force --subtitles --type=tv --verbose -p 'http://"+host+":"+port+"'"
on peut alors appeler :
./bbc33.py http://www.bbc.co.uk/iplayer/episode/b04nv6kr/doctor-who-series-8-11-dark-water 1
Dernière modification par pguimier (Le 02/11/2014, à 00:53)
Hors ligne
#30 Le 03/11/2014, à 08:26
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Effectivement
https://squarepenguin.co.uk/forums/topi … available/
mais peut-être une solution
https://squarepenguin.co.uk/forums/topi … -tv-cache/
Dernière modification par k3c (Le 03/11/2014, à 08:28)
Debian 12 sur Thinkpad reconditionné
Hors ligne
#31 Le 03/11/2014, à 09:57
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Tiens, l'ancienne version pour la BBC en python sur le site de youtube-dl, c'est pas bien gros en fait
Debian 12 sur Thinkpad reconditionné
Hors ligne
#32 Le 04/11/2014, à 06:05
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Bon problème résolu, faut mettre get_iplayer v 2.90
https://squarepenguin.co.uk/wiki/installation/ubuntu/
bravo aux personnes qui ont "fixé"
Debian 12 sur Thinkpad reconditionné
Hors ligne
#33 Le 19/11/2014, à 23:05
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Jái essaye dínstaller la version 2.90 mais pas reussi.
Il y a ausi depuis quelques mois un nouveau add-on pour firefox (I-player).
Mais naturellement exclusif pour U.K.
Serait il possible pour modifier le script Python (bbc33/py) qui cherche pour un bon Proxy et alors appeler Firefox, peut etre avec Tcl?
Hors ligne
#34 Le 20/11/2014, à 05:50
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Tu as Hola, une extension Firefox qui te permet de regarder avec le proxy d'un pays
Debian 12 sur Thinkpad reconditionné
Hors ligne
#35 Le 02/04/2015, à 15:35
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Enfin je viens de terminer 2 scripts en Python 3 , aprés les idées de 3kc
2 scripts, nommées BBCrecord.py et BBCproxy.py
#!/usr/bin/python3.4.2
#-*- coding:utf-8 -*-
programname = 'BBCrecord.py'
#date 02042015
subl = 'BBCproxy.py' # linux subroutine
subw = 'BBCproxy.py' # windows subroutine (now identical on linux subroutine)
sub = ' '
installdirw = 'C:/Program Files (x86)/get_iplayer/'
# for windows
recordirw = 'D:/Video-lib/' #attention this variable used in subprogram (BBCproxy.py) too!!
# for linux
recordirl = '/home/$USER/Video/'
recordir = ' '
# A USER FRIENDLY INTERFACE TO DOWNLOAD AND RECORD BBC RADIO AND TV PROGRAMS USING GET_IPLAYER in Python 3
# tested on windows 8.1 pro 64 bit, Windows Vista 32 and Linux Mint 17 32 bit with get_iplayer 2.90 (november 2014)
# date = 02-04-2015
# this script is based on scripts found on Ubuntu Users Forum France with some modifications by Bob
# main differences are: it works on Linux as well on Windows platforms
# a few buttons added
# separate screens foreseen for search and for downloading
# status display and filesizes for data and subtitles
# is written in Python3.4 in stead of Python2
# is written by a beginning Python programmer.., (corrections welcome)
#
# the two program PYTHON scripts are BBCrecord.py and BBCproxy.py as well for Linux as for Windows
#
#****GENERAL INSTALLATION REMARKS****
# the output directory for the mp4 and srt files (tv) and wma files (radio) can be specified in the beginning lines of the scripts
# VLC can later be used for PC display of the mp4 files and the srt file can be used for subtitles(English)
# If a TV set is capable of reading mp4 the files can be put on an usb-stick or transferred by network
#
# Pay attention on the ABOUT-key !!!!
#
# known problems: in some cases filesizecounters are not started up (for specific filenames)
#
# recent improvements: auto scroll and window resizing
# display of recent used proxy
# hide cmd window in Windows
# even if only 1 program found, download possible (was error in French script)
# scroll and resize windows possible
# files now found in windows 32 Program File directory and 64 bits Program File (x86) directory
#****LINUX installation****
# use Python 3
# for linux use this program and the subprogram BBCproxy.py
# first install get_iplayer from the Linux repository (all modules are installed at once)
# remark: pay attention you install version 2.90 of get_iplayer and not earlier versions!!
# as long as 2.90 is not foreseen in the normal repositories, instructions for loading from PPA
# can be found in [url]https://github.com/dinkypumpkin/get_iplayer/wiki/ubuntu[/url]
#
#****WINDOWS installation****
# Python installation
# On my Windows system I installed Python 3.4.x in the directory C:\Python34
# For Windows Get-iplayer and all extra modules (these are
# get_iplayer,Mplayer,LAME,FFmpeg,VLC, RTMPDump,Atomic Parsley) are installed by the
# get_iplayer-setup_latest.exe from [url]http://www.infradead.org/get_iplayer(run[/url] as administrator!!, change in properties).
# I choosed for destination directory the default directory (get_iplayer in Program Files) and another directory for the recording files
# After installation check in administrator command window if get_iplayer command works!!!
# sometimes persisting errors wth RTMDump, demanding a newer cersion than 1.8 although 2.4 is used
# check Path parameters maybe REVO uninstall and re-install completely get-iplayer can help
# download bs4 (beautiful soup) and copy bs and bs4 directory to the Python directory
# if pip is not foreseen in python 3.4 go to [url]https://pip.pypa.io/en/latest/installing.html[/url] to install pip
# in cmd window: py -m pip install beautifulsoup4
# to test if it works run alone BBCproxy and result must be IndexError: list index out of range
# the scripts BBCrecord.py and BBCproxy.py are installed in the Python directory directory
#
# Take care to install it in C:\Program Files\get_iplayer or in C:\Program Files (x86)\get_iplayer for 64 bit windows
# (get-iplayer installation asks for its destination, also a destination for recorded videofiles)
# If you choose other locations
# Adapt after installation the PATH if neccesary
# (control panel, system, advanced,environment variable,system variable,PATH...)
# IMPORTANT for WINDOWS
# Make with a txt-editor a small file named get_iplayer.cmd and copy this file into the directory of get_iplayer!!
# this file can contain the following:
#
# @echo off
# cd C:/Program Files (x86)/get_iplayer (or cd C:/Program Files/get_iplayer)
# perl.exe get_iplayer.pl %*
#
# BBCrecord.py can be run through the idle.bat file or from a command window (correct PATH)
# optional:from strawberryperl.com download and install Strawberry.perl (32 or 64 bit version)(in C:\Strawberry
##################################################################################################################################
# POSSIBLE INSTALLATION ERRORS:
# if you get message can t open perl script get_iplayer.pl
# check if get_iplayer.pl is in the right directory (Program Files/get_iplayer?)
# adapt if needed the get_iplayer.cmd file
# if you get message can t locate Env.pm in @INC (@INC contains .}
# check if getplayer.cmd is in right directory C:/Program Files (x86)/get_iplayer]
##################################################################################################################################
# POSSIBLE ECECUTION ERRORS:
# TRICK !! sometimes the program is not found although it is indicated in the website of the BBC that it is available
# for some days (mostly 7 or 28 days)
# Simply specify spaces in the search field and than all available programs are listed
# in alphbetical order and you can also specify the first 3 or 4 digits (PID) in the search field
#################################################################################################################################
import os
try:
from tkinter import *
except:
from Tkinter import *
import tkinter as tk
try:
from ScrolledText import ScrolledText
except ImportError:
import tkinter.scrolledtext
from tkinter.scrolledtext import ScrolledText
import tkinter.filedialog as tk_FileDialog
import tkinter.simpledialog
try:
import tkMessageBox
except ImportError:
import tkinter.messagebox
from tkinter.messagebox import showinfo
from tkinter.simpledialog import askinteger
try:
from tkColorChooser import askcolor
except ImportError:
import tkinter.colorchooser
try:
import tkFileDialog
except ImportError:
import tkinter.filedialog
try:
from io import StringIO
except ImportError:
from cStringIO import StringIO
try:
import ConfigParser
except ImportError:
import configparser
import distutils.dir_util
from queue import Queue, Empty
import subprocess
import queue
import sys
import re
from threading import Thread
import time
from time import ctime
import locale
import glob
ON_POSIX = 'posix' in sys.builtin_module_names
Finished = None
thread1 = None
force = None
tvtype=None
root = None
process = None
queue = Queue()
manager = None
df = None
nom = None
snom = None
nom2 = None
filesSize = None
srtfilesSize = None
exitmessage = None
mpfile = None
srtfile = None
exitmsg = None
tstf0 = None
tstsubtit = None
sz = None
linebuf = None
si = None
if sys.platform != 'linux':
progloc = (os.environ['PROGRAMFILES'])
class IODirector(object):
# A general class for redirecting I/O to this Text widget.
def __init__(self,text_area):
self.text_area = text_area
class StdoutDirector(IODirector):
# A class for redirecting stdout to this Text widget.
def write(self, msg):
self.text_area.insert(END,msg)
def flush(self):
pass
def start_thread(func, *args):
global nom, snom, nom2
t = Thread(target=func, args=args)
t.daemon = True
t.start()
return t
def consume(infile):
global tstf0, tstsubtit,linebuf
for line in iter(infile.readline , ''):
#for line in iter(infile.readline ,b''):
#line = line.decode(sys.stdout.encoding)
queue.put(line)
if line.startswith ('!@!@!@if1') or line.startswith ('Downloaded Thumbnail to '):
tstf0= '1'
Finished = True
if line.startswith ('!@!@!@if2') or line.startswith ('INFO: Recorded '):
tstf0 = '2'
Finished = True
if line.startswith ('!@!@!@if3') or 'Finished writing to temp file.' in line:
tstf0 = '3'
Finished = True
if line.startswith ('!@!@!@if4') or 'Already in history' in line:
tstf0 = '4'
Finished = True
if line.startswith ('!@!@!@if5') or 'Starting download at' in line or 'INFO: Checking existence of default version' in line:
tstf0 = '5'
if line.startswith ('INFO: Subtitles not available'):
tstsubtit = 'N'
if line.startswith ('INFO: Using Proxy'):
tstf0 = '6'
linebuf = line
infile.close()
def qyncontinue():
try:
answer=tkinter.messagebox.askquestion('Quit, are you Sure?', 'Y or N?', icon ="warning")
except:
answer=tkMessageBox.askquestion('Quit, are you Sure?', 'Y or N?', icon ="warning")
if answer == 'no':
showinfo('info','the program will be restarted ')
about()
else:
programend()
return
def programend():
global root
showinfo('info','end of main program')
root.destroy()
class Application(tk.Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.createWidgets()
self.after(100,self.on_after)
self.after(1000, self.on_after2)
def createWidgets(self):
self.dirfilms = StringVar()
self.tvtype = IntVar()
self.refresh = IntVar()
self.force = IntVar()
self.filesSize = StringVar()
self.srtfilesSize = StringVar()
self.filenaam = StringVar()
self.exitmessage = StringVar()
self.exitmsg = StringVar()
self.hdrfs='Filesizes media/subtitle:'
self.dtm=StringVar()
self.hdrout='Outputfiles are recorded in: '
self.outfile=StringVar()
self.hdrproxy='Proxy:'
self.proxy=StringVar()
# upper_frame
self.upper_frame = Frame(background='green', borderwidth=5)
self.upper_frame.grid(row=0,column=0,columnspan=3,sticky=N+S+E+W)
self.df = Entry( textvariable=self.dirfilms,width=80)
self.df.bind('<Return>', (lambda event: self.entry_window())) # enter=button search
self.df.focus_set() # activate the Entrywindow
self.df.grid(column=1,row=0) # location of the Entrywindow
self.bt1 = Button( text = 'SEARCH',justify=RIGHT, command = self.searchcall,bd=4,bg='lightgreen')
self.bt1.grid(row =0,column=1,sticky=E) #location of ****BUTTON SEARCH
self.cb0 = Checkbutton(text='RADIO',variable=self.tvtype) # for cache tvtype
self.cb0.grid(row=0,column=0,sticky=W)
self.cbd = Button(text = ' X ',command = self.deletefields,bd=4,bg='lightgreen')
self.cbd.grid(row=0,column=2)
# location of checkbutton tvtype
self.cb1 = Checkbutton(text='refresh BBC-cache',variable=self.refresh) # for cache refresh
self.cb1.grid(row=0,column=3,sticky=E) #location of checkbutton refresh
# listbox with scrollbar under upper_frame
self.lsb = Listbox(background = 'yellow',width=55,height=10)
self.lsb.grid(column=0,columnspan=3,sticky=N+S+E+W,ipadx=200) #location of listbox
self.yscrollbar = Scrollbar()
self.yscrollbar.grid(row=1, column=2, sticky=N+S+E)
self.yscrollbar.config(command=self.lsb.yview)
self.lsb.configure(yscrollcommand=self.yscrollbar.set) # for autoscrolllling
# General Button_frame part 1
self.btn_frame = Frame(background='green', borderwidth=5) # BUTTONS
self.btn_frame.grid(column=0,columnspan=3,sticky=N+S+E+W)
self.bt2 = Button(text = 'DOWNLOAD',justify=RIGHT, command = self.download,bd=4,bg='lightgreen')
self.bt2.grid(row=2,column=2,sticky=E) #location of ****BUTTON DOWNLOAD
self.cb2 = Checkbutton(text='Force',variable=self.force) # for second download of identical file
self.cb2.grid(row=2,column=3,sticky=W) #location of checkbutton
self.lblfs=Label(self.btn_frame,text=self.hdrfs, justify=LEFT,anchor=W,width=18)
self.lblfs.grid(row=2,column=0,ipady=1,padx=5) #location of label Filesize
self.lblfs2=Label(self.btn_frame,textvariable=self.filesSize, justify=LEFT,width=10)
self.lblfs2.grid(row=2,column=1,ipady=1,padx=1) #location of label Filesize
self.lblfs3=Label(self.btn_frame,textvariable=self.srtfilesSize, justify=RIGHT,width=5)
self.lblfs3.grid(row=2,column=2,ipady=1,padx=10) #location of label srtFilesize
self.lblfs4=Label(self.btn_frame,textvariable=self.exitmessage, justify=LEFT,fg='red',width=28)
self.lblfs4.grid(row=2,column=3,ipady=1) #location of label exitmessage
self.lblfs5=Label(self.btn_frame,textvariable=self.filenaam, justify=LEFT,width=50)
self.lblfs5.grid(row=2,column=4,ipady=1,padx=30,) #location of label filename
self.filesSize.set('0000')
self.srtfilesSize.set ('000')
self.exitmessage.set(' ****** ')
self.filenaam.set('---------------------------')
# Text_area under upper frame
self.text_area = Listbox(width = 55,height=22,bg='light cyan')
top=self.winfo_toplevel() #1
top.rowconfigure(4, weight=1) #2
top.columnconfigure(0, weight=1) #3
self.rowconfigure(4, weight=1) #4
self.columnconfigure(0, weight=1) #5
self.rowconfigure( 1, weight=100 )
self.columnconfigure( 0, weight=1 )
self.text_area.grid(row=4, column=0,columnspan=3,sticky=N+S+E+W,ipadx=200)
self.tayscrollbar= Scrollbar()
self.tayscrollbar.grid(row=4, column=2, sticky=N+S+E)
self.tayscrollbar.config(command=self.text_area.yview)
self.text_area.configure(yscrollcommand=self.tayscrollbar.set)
# *****Date and Time
self.lbldtm=Label(textvariable=self.dtm)
self.lbldtm.grid(row=5,column=0) #location of date and time
self.lblhdrout=Label(text=self.hdrout)
self.lblhdrout.grid(row=5,column=1,sticky=W) #location of header outputfiles
self.lbloutputfile=Label(textvariable=self.outfile,fg='red')
self.lbloutputfile.grid(row=5,column=1,sticky=W,padx=170) #location of outputfiles
self.lblhdrproxy=Label(text=self.hdrproxy)
self.lblhdrproxy.grid(row=5,column=1,sticky=W,padx=295) #location of proxy-header
self.lblproxy=Label(textvariable=self.proxy,width= 20,fg='red')
self.lblproxy.grid(row=5,column=1,sticky=W,padx=350) #location of proxy
# General Button_frame part 2
self.bt3 = Button(text='ABOUT..', command=self.about,justify=LEFT,fg='red',bd=4,bg='white')
self.bt3.grid(row=5,column=3,sticky=W,padx=0) #location of ****BUTTON ABOUT
self.bt4 = Button(text='QUIT ',command=qyncontinue, justify=RIGHT,bd=4,bg='white')
self.bt4.grid(row=5,column=3,sticky=E) #location of ****BUTTON QUIT
def txtprint(self,ligne):
self.text_area.insert(END,ligne)
self.text_area.select_clear(self.text_area.size() - 2) #Clear the current selected line
self.text_area.select_set(END) #Select the new line
self.text_area.yview(END) #Set the scrollbar to the end of the listbox
def on_after(self):
global queue,root,app,text_area,tstf0
while True:
try:
v = queue.get_nowait()
except Empty:
break;
ligne=(v)
self.txtprint(ligne)
tim=ctime()
self.dtm.set(tim)
self.after(200,self.on_after)
def getsize(self,filename):
sz =None
for fn in glob.glob(filename):
sz = os.path.getsize(str(fn))
return sz
def on_after2(self):
global tstf0, mpfile, srtfile,recordir,nom,sz1,sz2
if snom is not None:
msgsdict=dict([(1,'Finishing Download!!!'),
(2,'finishing Download'),
(3,'FINISHED WRITING the media file !!'),
(4,'This FILE is already in history !!!'),
(5,'Now Downloading:'),
(6,'Waiting...'),
(7,'reserve')])
if tstf0 is not None:
idx = int(tstf0)
exitmsg = msgsdict[idx]
self.exitmessage.set((exitmsg))
root.update()
if tstf0 == '4':
self.filesSize.set('0000')
self.srtfilesSize.set('000')
root.update()
if tstf0 == '6':
self.proxy.set(str.strip(linebuf[18:46]))
if tstf0 == '5' or tstf0 == None:
self.filenaam.set((nom2))
self.filesSize.set('0000')
self.srtfilesSize.set('000')
root.update()
if tstf0 == '5':
if self.tvtype.get():
mpfile = str(recordir + nom + '*part*wma')
else:
mpfile = str(recordir + nom + '*partial.m*')
srtfile = str(recordir + nom + '*partial.srt*')
filename = mpfile
sz = '0000'
sz = self.getsize(filename)
sz1 = sz
self.filesSize.set(str(sz1))
root.update()
if tstsubtit != 'N' :
for fn2 in glob.glob(srtfile):
sz2=os.path.getsize(str(fn2))
self.srtfilesSize.set(str(sz2))
else:
self.srtfilesSize.set(' *** ')
root.update()
self.after(1000, self.on_after2)
def busy(self):
root.config(cursor='watch')
self.text_area.config(cursor="watch")
root.update()
def notbusy(self):
global manager
root.config(cursor='')
self.text_area.config(cursor='')
root.update()
def searchcall(self):
global root
self.busy()
root.after_idle(self.entry_window)
def entry_window(self):
if self.tvtype.get():
tvtypetxt = '--type=radio'
else:
tvtypetxt = '--type=tv'
if sys.platform == 'linux':
args = ["get_iplayer", tvtypetxt, self.dirfilms.get()]
if self.refresh.get():
args.append('-f')
app = subprocess.Popen(args=args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
else:
si=None # Hide Windows Command Window!
si=subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
#args = ["C:/Program Files (x86)/get_iplayer/get_iplayer.cmd", tvtypetxt, self.dirfilms.get()]
args = [progloc + "/get_iplayer/get_iplayer.cmd", tvtypetxt, self.dirfilms.get()]
print (args)
if self.refresh.get():
args.append('-f')
app = subprocess.Popen(args=args, stdout=subprocess.PIPE,
startupinfo=si,
stderr=subprocess.STDOUT)
(stdout, stderr) = app.communicate()
self.notbusy()
if app.returncode == 1: # sortie en erreur →
ligne=('get_iplayer failed\n')
self.txtprint(ligne)
else:
encoding = locale.getdefaultlocale()[1]
lines = stdout.decode('latin').split('\n')
for line in lines:
ligne=(line)
self.txtprint(ligne)
n = 1
for line in lines:
if line.startswith('Matches:'):
break
n += 1
lines = lines[n:-3] if n <= len(lines) else []
n = 0
for line in lines:
line = line.replace('\t', ' ')
line = line.replace('Added: ','')
n += 1
self.lsb.insert(END, line) #Insert a new line at the end of the list
self.lsb.select_clear(self.lsb.size() -2) #Clear the current selected line
self.lsb.select_set(END) #Select the new line
self.lsb.yview(END) #Set the scrollbar to the end of the listbox
ligne=('get_iplayer success, %s founds' % (n,))
self.txtprint(ligne)
def deletefields(self):
self.dirfilms.set("") #Clear the entry-field
self.lsb.delete(0,END) #Clear the yellow listbox
self.force.set("0")
self.refresh.set("0")
def download(self):
global process, snom, nom2, nom, x, tstf0,recordir
sel = self.lsb.curselection()
# sel = None if len(sel) == 0 else sel[0] # corrected
if len (sel) == 0: # corrected
sel = None # corrected
else: # corrected
# if sel: # corrected
nom = self.lsb.get(sel).split(':')[1].split(',')[0].strip().replace(' ', '_').replace('/', '_').replace("'",'')
nom2 = self.lsb.get(sel).split(',')[0] # modified
snom = './'+nom+"*"
tstf0 = None
self.filesSize.set('0000')
self.srtfilesSize.set('000')
self.exitmessage.set('***************')
self.filenaam.set('---------------------------')
self.outfile.set(str(recordir))
root.update()
# 28/8/14 for 'after first download'
self.after(100,self.on_after)
self.after(1000, self.on_after2)
if sys.platform == 'linux':
sub = subl
recordir = recordirl
args = ["python3", r"./" + sub] + [str(self.lsb.get(sel)).split(':')[0]]+ [str(self.force.get())] +[str(self.tvtype.get())]
print('args = ',args)
process = subprocess.Popen(args=args, stdout=subprocess.PIPE, universal_newlines=True,
stderr=subprocess.PIPE,close_fds=ON_POSIX)
else:
sub = subw
recordir = recordirw
args = [sys.executable, r"./" +sub] + [str(self.lsb.get(sel)).split(":")[0]] + [str(self.force.get())]+[str(self.tvtype.get())]
print('args = ',args)
si=None # Hide Windows Command Window!
si=subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
process = subprocess.Popen(args=args,startupinfo=si, stdout=subprocess.PIPE, universal_newlines=True,
stderr=subprocess.PIPE,close_fds=ON_POSIX)
if process.returncode == 1:
self.text_area.insert(END, 'call to subroutine failed!!!\n')
print ('call to subroutine failed!!!')
else:
thread1 = start_thread(consume, process.stdout)
# #else: # corrected
# # print # corrected
def about(self):
ligne=('** SYSTEM Info **')
self.txtprint(ligne)
ligne = ('** OS = ' + sys.platform + ' Python Version = ' + sys.version.split()[0]+ ' **')
self.txtprint(ligne)
programname= (sys.argv)
ligne = ('** scriptname = ' + str(programname)+ ' **')
self.txtprint(ligne)
ligne = ('** subprocesses are get_iplayer and ' + sub + ' **')
self.txtprint(ligne)
if os.path.isfile(sub) is True:
ligne = ('** subroutine' + sub + ' is present **')
self.txtprint(ligne)
else:
fileOK = None
ligne = ('** subroutine ' + sub + ' file is not installed!!! **')
self.txtprint (ligne)
if sys.platform != 'linux':
ligne = ('**Location of ProgramFiles = '+ progloc + '**' )
self.txtprint (ligne)
for n in range (1,2):
ligne = '*******************************************************************************'
self.txtprint (ligne)
ligne= ('* If you download another program before the first download is finished *')
self.txtprint(ligne)
ligne = ('* downloads will succeed simultaneously but filecounters will be incorrect! *')
self.txtprint(ligne)
for n in range (1,1):
ligne = '******************************************************************************'
self.txtprint (ligne)
for n in range (1,3):
ligne = '***************************************************************'
self.txtprint (ligne)
ligne = ('* Default are TV-programs, for Radio programs mark RADIO *')
self.txtprint(ligne)
ligne = ('* Subtitles will be loaded, if present in a SRT-file *')
self.txtprint(ligne)
ligne = ('* Enter now a recent BBC TV program-title or the PID-number in the search field *')
self.txtprint(ligne)
for n in range (1,4):
ligne = '********************************************************************************'
self.txtprint (ligne)
def main():
global app, root, dirfilms, refresh, force, tvtype, dtm, snom, nom2, filesSize, srtfilesSize, text_area, lsb, nom, ScrolledText,exitmessage,tstfin,filenaam,recordir,sub,sz,sz1,sz2
if sys.platform == 'linux':
sub = subl
recordir = recordirl
else:
sub = subw
recordir = recordirw
print ('downloaded files are recorded in ',recordir)
root = Tk()
app=Application()
app.master.title(programname+' '+sub)
root.mainloop()
if __name__ == '__main__':
main()
#!usr/bin/env python3.4.2
# -*- coding:utf-8 -*-
programname = 'BBCproxy.py'
#date 02042015
sub = 'get_iplayer'
# file location for video-recording
# for Windows
recordirw = 'D:/Video-lib/'
# for Linux
recordirl = '/home/$USER/Video/'
import subprocess, sys, shlex, os
import random
try:
import urllib.request as urllib2
except:
import urllib2
try:
import bs4 as BeautifulSoup
except:
import bs4 as beautifulsoup
import socket
from threading import Thread
si=None
ON_POSIX = 'posix' in sys.builtin_module_names
Finished = False
listeUserAgents = [ 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; fr-fr) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1',
'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13\
',
'Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) midori',
'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.107 Safari/535.1',
'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.940.0 Safari/535.8' ]
allTimeouts = (3, 10, 15, 20)
if sys.platform != 'linux':
progloc = (os.environ['PROGRAMFILES'])
class FlushFile(object):
"""Write-only flushing wrapper for file-type objects."""
def __init__(self, f):
self.f = f
def write(self, x):
self.f.write(x)
self.f.flush()
def start_thread(func, *args):
#print('start thread',func,args)
t = Thread(target=func, args=args)
t.daemon = True
t.start()
return t
def consume(infile):
global Finished
for line in iter(infile.readline, ''):
if 'Downloaded Thumbnail to ' in line:
print ('!@!@!@if1')
Finished = True
if 'Recorded ' in line:
print ('!@!@!@!if2')
Finished = True
if 'Finished writing to temp file.' in line:
print ('!@!@!@if3')
Finished = True
if 'Already in history' in line:
print ('!@!@!@if4')
Finished = True
print (line,end="")
infile.close()
def getProxy():
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', random.choice(listeUserAgents))]
data = opener.open('http://free-proxy-list.net/uk-proxy.html').read()
opener.close()
soup = BeautifulSoup.BeautifulSoup(data)
lst = []
for tr in soup.tbody.findAll('tr'):
i = 0
slst = []
for td in tr.find_all('td'):
i += 1
if i in (1, 2, 5):
slst.append(td.contents[0])
elif i == 8:
i = 0
lst.append(slst)
slst = []
for href in lst:
yield href
def getValidProxy():
for timeout in allTimeouts:
print ('Timeout =', timeout)
socket.setdefaulttimeout(timeout)
for host, port, typeproxy in getProxy():
try:
print ('Trying %s:%s' % (host, port))
params = (host, int(port))
# buffer_size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(params)
s.close()
yield host, port, typeproxy
except socket.timeout:
pass
except socket.error:
pass
def main():
global Finished
# # Replace stdout with an automatically flushing version
sys.stdout = FlushFile(sys.__stdout__)
idvideo = sys.argv[1]
for host, port, typeproxy in getValidProxy():
print (host, port, typeproxy)
idvideo = sys.argv[1]
tstforce = sys.argv[2]
tstradio = sys.argv[3]
if tstradio == "1":
#modus = " --type=radio "
#modus = " --mode=best"
#modus = " --modes=wma1"
modus = " --aactomp3"
else:
modus = " --subtitles --mode=best"
if sys.platform == 'linux':
if len(sys.argv) > 1 and sys.argv[2] == '1':
cmds = "get_iplayer --get "+idvideo + modus + \
" --attempt=99 --output="+ recordirl + \
" --nopurge --force --proxy=http://"+host+":"+port
else:
cmds = "get_iplayer --get "+idvideo + modus + \
" --attempt=99 --output="+ recordirl + \
" --nopurge --proxy=http://"+host+":"+port
# argments = cmds.split
arguments = shlex.split(cmds)
Finished = False
# print ('cmds=',cmds)
print ('arguments = ',arguments)
process = subprocess.Popen(args=arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
else:
print ("loc = ", progloc)
if len(sys.argv) > 1 and tstforce == '1':
cmds = "\"" + progloc + "/get_iplayer/get_iplayer.cmd \"" + " --get " + idvideo + modus + \
" --check duration --attempt=99 --output=" +\
recordirw + " --nopurge --force --proxy=http://" + host + ":" + port
else:
cmds = "\"" + progloc + "/get_iplayer/get_iplayer.cmd \"" + " --get " + idvideo + modus + \
" --check duration --attempt=99 --output=" + \
recordirw + " --nopurge --proxy=http://" + host + ":" + port
#cmds = "\"C:/Program Files/get_iplayer/get_iplayer.cmd \"" #test syntax
#cmds = "\"" + progloc + "/get_iplayer/get_iplayer.cmd \"" + " -help"
Finished = False
print ('cmds=',cmds)
si=subprocess.STARTUPINFO() # Hide Windows Command Window!
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
process = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
startupinfo=si, universal_newlines=True)
process.communicate
#(stdout, stderr ) = process.communicate()
pid = process.pid
print ('le pid de get_iplayer est ', pid)
thread1 = start_thread(consume, process.stdout)
thread2 = start_thread(consume, process.stderr)
thread1.join() # wait for IO completion
thread2.join() # wait for IO completion
if Finished:
for n in range(0,5):
print ('******Download Finished, Make another Choice, or quit the program, or Select again and mark FORCE to repeat a download')
print (sub + '******Download Finished, Make another Choice')
exitmessage = 'Download Finished, Make another Choice'
exitmessage.set('the file is downloaded now')
root.update()
thread1.close()
thread2.close()
break;
if __name__ == "__main__":
main()
Dernière modification par BobW (Le 04/04/2015, à 12:10)
Hors ligne
#36 Le 02/04/2015, à 16:03
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
intéressant, tu peux mettre entre balises code, cela sera plus propre ?
Debian 12 sur Thinkpad reconditionné
Hors ligne
#37 Le 03/04/2015, à 00:22
- dzecniv
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
salut,
tout ça a l'air super, mais vous ne pouvez pas le mettre sur un site de partage de code ? par exemple gitlab: (gratuit, logiciel libre, projets privés possibles): https://gitlab.com/
par contre il faut connaître les bases de git. (je peux vous aider)
merci !
Hors ligne
#38 Le 03/04/2015, à 06:34
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Pour simplifier l'installation, on pourrait dockeriser cette application, comme je lai fait pour Captvty
Je vais tester l'application, pour l'instant, j'ai
gg@gg-P15SM-A-SM1-A:~$ python BBCrecord.py
File "BBCrecord.py", line 428
SyntaxError: Non-ASCII character '\xe2' in file BBCrecord.py on line 428, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Debian 12 sur Thinkpad reconditionné
Hors ligne
#39 Le 03/04/2015, à 12:33
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
C' est toutafait nouveau pour moi, mais j'ai mis les 2 scripts sur gitlab.
Nom du projet: Use-get_iplayer
Je ne suis pas certain si ca marche, mais pour commencer je l ai mis comme projet prive, moi méme comme master, et j'ai ajouté
déjá un user "k3c'' comme developer. (ésperant quíl s'ágit de la meme personne?
dzecniv je ne pouvais pas retrouver sur gitlab, mais il a proposé de m'aider donc j'atttend volontierement
ses suggestions et corrections au niveau de gitlab...
merci!
@k3c dockeriser??
@k3c Python 3 ?
Hors ligne
#40 Le 03/04/2015, à 13:00
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
@ bobw
Oui, c'est bien moi que tu as ajouté, j'ai été notifié, merci
Debian 12 sur Thinkpad reconditionné
Hors ligne
#41 Le 03/04/2015, à 14:21
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
J'ai fait une petite correction dans les deux programmes:
La correction est fait dans les versions sur gitlab et aussi ici.
Dernière modification par BobW (Le 03/04/2015, à 16:17)
Hors ligne
#42 Le 03/04/2015, à 21:26
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Bon, pour le lancer avec Python3, il faut installer python3-tk
sudo apt-get install python3-tk
sinon j'ai une erreur plus loin
gg@gg-P15SM-A-SM1-A:~$ python3 BBCrecord.py
Traceback (most recent call last):
File "BBCrecord.py", line 167, in <module>
progloc = (os.environ['PROGRAMFILES'])
File "/usr/lib/python3.4/os.py", line 631, in __getitem__
raise KeyError(key) from None
KeyError: 'PROGRAMFILES'
gg@gg-P15SM-A-SM1-A:~$
Debian 12 sur Thinkpad reconditionné
Hors ligne
#43 Le 03/04/2015, à 23:56
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Je te propose de remplacer de partout
/home/bob/Video/
par
/home/$USER/Video/
ainsi ça marchera pour tout le monde.
Debian 12 sur Thinkpad reconditionné
Hors ligne
#44 Le 04/04/2015, à 13:27
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
J'ai fait la modification proposée.
Et encore une petite modification dans l' ABOUT pour Linux
Ca a l'air de marcher en Linux et en Windows.
J'attends les remarques suivantes.
@dzecniv et @k3c encore des ameleriations pour gitlab??? C'est la premiére fois pour moi...
Hors ligne
#45 Le 06/04/2015, à 20:29
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Il est bien sympa ton programme, avec de la couleur et tout, il est bien mieux que le mien.
Je continue à tester et je te fais des retours.
Debian 12 sur Thinkpad reconditionné
Hors ligne
#46 Le 06/04/2015, à 23:33
- dzecniv
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
salut,
excuse-moi, je n'avais pas vu tous les messages.
Cool pour gitlab )))
Tu ne veux pas rendre le projet public ? Ça permet à tout le monde de le regarder, de le tester, de proposer une modif, et je ne vois pas d'inconvénients car tu restes le Master.
Mon nom à moi sous gitlab c'est "vindarel".
En tout cas c'est une bonne chose de faite, ce sera bien plus sympa de parler du code, d'écrire des commentaires et de faire des modifs sur gitlab qu'ici.
Dernière modification par dzecniv (Le 06/04/2015, à 23:45)
Hors ligne
#47 Le 07/04/2015, à 04:58
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
J'ai un souci, je ne récupère pas les proxy, alors que je récupère bien un Montalbano avec mon ancien programme
-rw-rw-r-- 1 gg gg 1961 avril 7 05:52 Inspector_Montalbano_Series_2_-_12._Treasure_Hunt_b01nvwqr_default.partial.srt
drwxrwxr-x 8 gg gg 4096 avril 7 05:52 .
-rw-rw-r-- 1 gg gg 451956736 avril 7 05:55 Inspector_Montalbano_Series_2_-_12._Treasure_Hunt_b01nvwqr_default.partial.mp4.flv
Il faudrait que le programme soit utilisable tel quel, or par défaut PROGRAMFILES n'existe pas, donc soit créer un répertoire, soit utiliser un répertoire qui existe
Debian 12 sur Thinkpad reconditionné
Hors ligne
#48 Le 12/04/2015, à 20:56
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
Pour l´instant mon acces wifi est tres pauvre (adresse de vacances). Quand meme je pourrais trouver le video de l´inspector
et demarrer le download, mais la vitesse de transfert trop pauvre pour terminer le download. je crois que le probleme de malfonction est un mauvais proxy. Je pense que j´ employe la meme technique comme dans l´original, mais je fais un attempt de 99 pour chaque proxy....Mais certaines heures et certains jours il ya des problemes avec les proxy. Je ne vois pas un moyen pout ameloirer cela.
Hors ligne
#49 Le 23/04/2015, à 16:04
- BobW
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
@K3c
Rentré a la maison J-ai fait le download de deux series de l ' ínspecteur Montalbano...
Hors ligne
#50 Le 24/04/2015, à 00:01
- k3c
Re : [script Python] Récupérer les vidéos de la BBC avec get_iplayer
@ BobW
Il y a un problème avec get_iplayer 2.92-ppa22, il ne trouve pas tous les replays, par exemple il y a 2 épisodes de Philby, mais il ne voit que le deuxième actuellement.
Ce n'est pas la première fois que je constate cela, par contre youtube-dl, lui arrive à télécharger les deux épisodes.
donc il faudrait soit importer youtube-dl, soit remplacer l'appel à get_iplayer par la partie bbc de youtube-dl
Debian 12 sur Thinkpad reconditionné
Hors ligne