Advertisement
agafron

Untitled

Jul 29th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. version=0.8.9
  4. size=512
  5. config_FILE=$HOME/.imdb-thumbnailer/config
  6.  
  7. video_extensions='
  8. application@ogg
  9. application@smil
  10. application@vnd.rn-realmedia
  11. application@vnd.rn-realvideo
  12. application@x-extension-m4a
  13. application@x-extension-mp4
  14. application@x-flash-video
  15. application@x-matroska
  16. application@x-ms-asf
  17. application@x-ogg
  18. application@x-quicktime-media-link
  19. application@x-shockwave-flash
  20. application@x-shorten
  21. application@x-smil
  22. application@xspf@xml
  23. audio@x-pn-realaudio
  24. image@vnd.rn-realpix
  25. image@vnd.rn-realpix
  26. misc@ultravox
  27. video@3gpp
  28. video@dv
  29. video@mp4
  30. video@mpeg
  31. video@msvideo
  32. video@quicktime
  33. video@vnd.divx
  34. video@vnd.rn-realvideo
  35. video@x-anim
  36. video@x-avi
  37. video@x-flc
  38. video@x-fli
  39. video@x-m4v
  40. video@x-matroska
  41. video@x-mpeg
  42. video@x-ms-asf
  43. video@x-msvideo
  44. video@x-ms-wmv
  45. video@x-nsv
  46. video@x-ogm@ogg
  47. '
  48.  
  49. parse_filename () { :;}
  50.  
  51. help ()
  52. {
  53. {
  54. case $LANG in
  55. es_* )
  56. echo "
  57. ACTIVAR/DESACTIVAR EL THUMBNAILER:
  58. Para completar la instalación es necesario activar el thumbnailer para el usuario actual para thunar y/o nautilus.
  59.  
  60. --set-nautilus
  61. Activa el thumbnailer para nautilus (--unset-nautilus para desactivar)
  62. --set-thunar
  63. Activa el thumbnailer para thunar (--unset-thunar para desactivar)
  64. --set-caja
  65. Activa el thumbnailer para caja (--unset-caja para desactivar)
  66. CONFIGURACIÓN:
  67. archivo: $config_FILE
  68.  
  69. imdb-thumbnailer funcionará solo para las rutas especificadas en el archivo de configuración.
  70.  
  71. Ejemplo:
  72. films_path=(
  73. '/home/user/Films'
  74. '/home/user/Trailers'
  75. )
  76. Siempre se deben usar rutas completas.
  77.  
  78. Es posible cambiar el tema agragando lo siguiente:
  79. theme_name='nombre del tema' (shadow|none)
  80.  
  81. OPCIONES:
  82. -s tamaño entrada salida
  83. El tamaño máximo es 128, para tamaños más grandes será usado el thumbnailer por defecto.
  84. --set video1 portada1 video2 portada2 etc...
  85. Especifica una portada alternativa y llama a la función update (ver --update).
  86. --update video1 video2 etc...
  87. Fuerza al explorador de archivos a reconstruir los thumbnails para los videos especificados cambiando sus tiempos de modificación un segundo.
  88. --remove video1 video2 etc...
  89. Borra los thumbnails para los videos especificados.
  90. --name video nombre
  91. Usa 'nombre' para buscar la portada y establecer la miniatura para 'video'.
  92. "
  93. ;;
  94. de_* ) # translated by thoughtcrime
  95. echo "
  96. DEN THUMBNAILER (DE)AKTIVIEREN:
  97. Um die Installation zu vervollständigen, muss der Thumbnailer für den aktuellen Benutzer bei Nautilus und/oder Thunar aktiviert werden.
  98.  
  99. --set-nautilus
  100. Aktiviert den Thumbnailer für Nautilus (deaktivieren mit --unset-nautilus)
  101. --set-thunar
  102. Aktiviert den Thumbnailer für Thunar (deaktivieren mit --unset-thunar)
  103. --set-caja
  104. Aktiviert den Thumbnailer für Caja (deaktivieren mit --unset-caja)
  105. KONFIGURATION:
  106. Datei: $config_FILE
  107.  
  108. Imdb-Thumbnailer lädt nur Film-Poster als Vorschaubilder in den Pfaden herunter, die in der Konfigurationsdatei eingetragen wurden.
  109.  
  110. Beispiele:
  111. films_path=(
  112. '/home/user/Filme'
  113. '/home/user/Trailer'
  114. )
  115.  
  116. Das Thema kann wie folgt geändert werden:
  117. theme_name='Name des Themas' (shadow|none)
  118.  
  119. OPTIONEN:
  120. -s Größe input output
  121. Der größte Wert für -s ist 128.
  122. --set video1 cover1 video2 cover2 etc...
  123. Setzt eigene Cover als Vorschaubilder und ruft die Update-Funktion auf (siehe auch --update).
  124. --update video1 video2 etc...
  125. Zwingt den Dateibrowser neue Vorschaubilder für die genannten Videos zu erstellen, indem die letzte Bearbeitungszeit um eine Sekunde geändert wird.
  126. --remove video1 video2 etc...
  127. Löscht die Vorschaubilder für entsprechende Videodateien.
  128. --name Video Suchbegriff
  129. Für 'Video' 'Suchbegriff' verwenden, um bessere Ergebnisse zu finden.
  130. "
  131. ;;
  132. * )
  133. echo "
  134. SET/UNSET THE THUMBNAILER:
  135. To complete the installation you must set the thumbnailer for the current user for thunar and/or nautilus.
  136.  
  137. --set-nautilus
  138. Sets the thumbnailer for nautilus (use --unset-nautilus to remove)
  139. --set-thunar
  140. Sets the thumbnailer for thunar (use --unset-thunar to remove)
  141. --set-caja
  142. Sets the thumbnailer for caja (use --unset-caja to remove)
  143.  
  144. CONFIGURATION:
  145. file: $config_FILE
  146.  
  147. imdb-thumbnailer will work only for the paths specified in the configuration file.
  148.  
  149. Example:
  150. films_path=(
  151. '/home/user/Films'
  152. '/home/user/Trailers'
  153. )
  154. Always use full paths.
  155.  
  156. You can change the theme adding the following:
  157. theme_name='name of the theme' (shadow|none)
  158.  
  159. OPTIONS:
  160. -s size input output
  161. Maximun size is 128, else the default thumbnailer will be used.
  162. --set video1 cover1 video2 cover2 etc...
  163. Set custom covers and call the update function (see --update).
  164. --update video1 video2 etc...
  165. Force the filebrowser to rebuild the thumbnails for the specified videos by changing their modification time 1 second.
  166. --remove video1 video2 etc...
  167. Remove thumbnails for the specified videos.
  168. --name video name
  169. Set the thumbnail for 'video' using 'name' to search for the cover.
  170. "
  171. esac
  172. } | cut -c6- | fmt
  173. }
  174.  
  175. set_thumbnail ()
  176. {
  177. file_path=$1
  178. grabber_picture=$2
  179.  
  180. if [[ -f "$file_path" && -n $grabber_picture ]]; then
  181. file_time_size=$(stat --format=%y-%s "$file_path")
  182. file_time_size=${file_time_size//.*-/-}
  183.  
  184. cover_name=$file_time_size
  185. cover_path=$HOME/.imdb-thumbnailer/covers
  186.  
  187. if ! [[ -d "$cover_path" ]] ; then
  188. mkdir -p "$cover_path"
  189. fi
  190. #ffmpegthumbnailer -i "$grabber_picture" -thumbnail -s 256 -o "$cover_path/$cover_name.png"
  191. #ffmpeg -i "$grabber_picture" -vframes 1 "$cover_path/$cover_name.png"
  192. #ffmpeg -i "$grabber_picture" "$cover_path/$cover_name.png"
  193. convert "$grabber_picture" -thumbnail ${size}x${size} "$cover_path/$cover_name.png"
  194. update_thumbnail "$file_path"
  195. elif ! [[ -f "$file_path" ]]; then
  196. echo "ERROR:\"$file_path\" does not exist"
  197. exit 1
  198. else
  199. echo "ERROR: no cover for: $file_path"
  200. exit 1
  201. fi
  202. }
  203.  
  204. remove_thumbnail ()
  205. {
  206. thumb2delete=$(echo "$1" | sed "s|'|\\\'|g" )
  207. thumb2delete_URI=$(python2 -c "import gnomevfs; print gnomevfs.get_uri_from_local_path('$thumb2delete')")
  208. MD5=$(echo -n "$thumb2delete_URI" | md5sum) MD5=${MD5%% *}
  209.  
  210. remove_thumbnail_files $MD5
  211.  
  212. #delete thunar thumbnail:
  213. if [[ "$(echo "$1" | egrep ':|,' )" ]]; then
  214. thumb2delete_URI=${thumb2delete_URI//%2C/,} thumb2delete_URI=${thumb2delete_URI//%3A/:}
  215. MD5=$(echo -n "$thumb2delete_URI" | md5sum) MD5=${MD5%% *}
  216.  
  217. remove_thumbnail_files $MD5
  218. fi
  219. }
  220.  
  221. remove_thumbnail_files ()
  222. {
  223. local folder
  224.  
  225. for folder in fail large normal
  226. {
  227. if [[ -f $HOME/.cache/thumbnails/$folder/$1.png ]]; then
  228. rm $HOME/.cache/thumbnails/$folder/$1.png
  229. echo "removed: $HOME/.cache/thumbnails/$folder/$1.png"
  230. fi
  231. }
  232. }
  233.  
  234. update_thumbnail ()
  235. {
  236. file_path=$1
  237.  
  238. if [[ -f "$file_path" ]]; then
  239. file_time_size=$(stat --format=%y-%s "$file_path")
  240. file_time_size=${file_time_size//.*-/-}
  241. file_time=${file_time_size%-*}
  242. file_size=${file_time_size##*-}
  243.  
  244. if [[ $file_time ]]; then
  245. cover_name=$file_time_size
  246. cover_path=$HOME/.imdb-thumbnailer/covers
  247.  
  248. second=${file_time:18:19}
  249.  
  250. case $second in
  251. [13579] ) second=$((second-1)) ;;
  252. * ) second=$((second+1)) ;;
  253. esac
  254.  
  255. incomplete_time=${file_time:0:18}
  256.  
  257. new_cover_name=$incomplete_time$second-$file_size
  258.  
  259. if [[ -f $cover_path/$cover_name.png ]]; then
  260. mv "$cover_path/$cover_name.png" "$cover_path/$new_cover_name.png"
  261. fi
  262.  
  263. touch "$file_path" -d "$incomplete_time$second"
  264. fi
  265. else
  266. echo "ERROR:\"$file_path\" does not exist"
  267. exit 1
  268. fi
  269. }
  270.  
  271. default_video_thumbnailer ()
  272. # {
  273. # if [[ $(type -fp gnome-video-thumbnailer) ]]; then
  274. # totem-video-thumbnailer -m -s $size -i "$SOURCE_url" -o "$OUTPUT_path"
  275. # elif [[ $(type -fp totem-video-thumbnailer) ]]; then
  276. # totem-video-thumbnailer -m -s $size -i "$SOURCE_url" -o "$OUTPUT_path"
  277. # elif [[ $(type -fp mplayer-video-thumb.sh) ]]; then
  278. # ffmpegthumbnailer -m -s $size -i "$SOURCE_url" -o "$OUTPUT_path" -f
  279. # elif [[ $(type -fp ffmpegthumbnailer) ]]; then
  280. # ffmpegthumbnailer -m -s $size -i "$SOURCE_url" -o "$OUTPUT_path" -f
  281. # fi
  282. # }
  283.  
  284. {
  285. if [[ $(type -fp ffmpegthumbnailer) ]]; then
  286. ffmpegthumbnailer -m -s $size -i "$SOURCE_url" -o "$OUTPUT_path" -f
  287. fi
  288. }
  289.  
  290.  
  291. restart_nautilus ()
  292. {
  293. echo -n "Should I restart nautilus? (This will close all open windows) [yN] "
  294. read answer
  295. if [ $answer:x = y:x ]; then
  296. nautilus -q
  297. else
  298. echo "The changes will not be done until you restart nautilus with:"
  299. echo "nautilus -q"
  300. fi
  301. }
  302. restart_caja ()
  303. {
  304. echo -n "Should I restart caja? (This will close all open windows) [yN] "
  305. read answer
  306. if [ $answer:x = y:x ]; then
  307. caja -q
  308. else
  309. echo "The changes will not be done until you restart c with:"
  310. echo "caja -q"
  311. fi
  312. }
  313. init_configfile ()
  314. {
  315. if ! [[ -f $HOME/.imdb-thumbnailer/config ]]; then
  316. echo
  317. echo "Please edit $config_FILE"
  318. echo "and insert your Video paths there."
  319. echo "Always use full paths!"
  320.  
  321. mkdir -p $HOME/.imdb-thumbnailer
  322. {
  323. echo 'films_path[0]="$HOME/Trailers"'
  324. echo 'films_path[1]='
  325. echo 'films_path[2]='
  326. echo 'films_path[3]='
  327. } > $config_FILE
  328. fi
  329. }
  330.  
  331. set_thumbnailer_for_nautilus ()
  332. {
  333. local configFile=$HOME/.local/share/thumbnailers/imdb.thumbnailer
  334. mkdir -p ${configFile%/*}
  335.  
  336. if [[ $1 = -r ]];then
  337. thumbnailer='/usr/bin/totem-video-thumbnailer -s %s %u %o'
  338. rm $configFile
  339. else
  340. rmdir $configFile &>/dev/null #fixes bug
  341. thumbnailer="$(which imdb-thumbnailer) -s %s %u %o"
  342.  
  343. {
  344. echo '[Thumbnailer Entry]'
  345. echo 'TryExec=/usr/bin/imdb-thumbnailer'
  346. echo 'Exec=/usr/bin/imdb-thumbnailer -s %s %u %o'
  347. echo 'MimeType=application/mxf;application/ogg;application/ram;application/sdp;application/vnd.ms-wpl;application/vnd.rn-realmedia;application/x-extension-m4a;application/x-extension-mp4;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktimeplayer;application/x-shorten;image/vnd.rn-realpix;image/x-pict;misc/ultravox;text/x-google-video-pointer;video/3gpp;video/dv;video/fli;video/flv;video/mp2t;video/mp4;video/mp4v-es;video/mpeg;video/msvideo;video/ogg;video/quicktime;video/vivo;video/vnd.divx;video/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;audio/x-pn-realaudio;audio/3gpp;audio/ac3;audio/AMR;audio/AMR-WB;audio/basic;audio/midi;audio/mp2;audio/mp4;audio/mpeg;audio/ogg;audio/prs.sid;audio/vnd.rn-realaudio;audio/x-aiff;audio/x-ape;audio/x-flac;audio/x-gsm;audio/x-it;audio/x-m4a;audio/x-matroska;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;audio/x-ms-wma;audio/x-musepack;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-wav;audio/x-pn-windows-acm;audio/x-realaudio;audio/x-real-audio;audio/x-sbc;audio/x-speex;audio/x-tta;audio/x-wav;audio/x-wavpack;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-xm;application/x-flac;'
  348. } > $configFile
  349. fi
  350.  
  351. for i in $video_extensions; do
  352. echo Setting Key for $i
  353. gconftool-2 -s "/desktop/gnome/thumbnailers/$i"/command -t string "$thumbnailer"
  354. gconftool-2 -s "/desktop/gnome/thumbnailers/$i"/enable -t boolean 'true'
  355. done
  356.  
  357. restart_nautilus
  358.  
  359. [[ $1 != -r ]] && init_configfile
  360. }
  361.  
  362. set_thumbnailer_for_caja ()
  363. {
  364. local configFile=$HOME/.local/share/thumbnailers/imdb.thumbnailer
  365. mkdir -p ${configFile%/*}
  366.  
  367. if [[ $1 = -r ]];then
  368. thumbnailer='/usr/bin/totem-video-thumbnailer -s %s %u %o'
  369. rm $configFile
  370. else
  371. rmdir $configFile &>/dev/null #fixes bug
  372. thumbnailer="$(which imdb-thumbnailer) -s %s %u %o"
  373.  
  374. {
  375. echo '[Thumbnailer Entry]'
  376. echo 'TryExec=/usr/bin/imdb-thumbnailer'
  377. echo 'Exec=/usr/bin/imdb-thumbnailer -s %s %u %o'
  378. echo 'MimeType=application/mxf;application/ogg;application/ram;application/sdp;application/vnd.ms-wpl;application/vnd.rn-realmedia;application/x-extension-m4a;application/x-extension-mp4;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktimeplayer;application/x-shorten;image/vnd.rn-realpix;image/x-pict;misc/ultravox;text/x-google-video-pointer;video/3gpp;video/dv;video/fli;video/flv;video/mp2t;video/mp4;video/mp4v-es;video/mpeg;video/msvideo;video/ogg;video/quicktime;video/vivo;video/vnd.divx;video/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;audio/x-pn-realaudio;audio/3gpp;audio/ac3;audio/AMR;audio/AMR-WB;audio/basic;audio/midi;audio/mp2;audio/mp4;audio/mpeg;audio/ogg;audio/prs.sid;audio/vnd.rn-realaudio;audio/x-aiff;audio/x-ape;audio/x-flac;audio/x-gsm;audio/x-it;audio/x-m4a;audio/x-matroska;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;audio/x-ms-wma;audio/x-musepack;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-wav;audio/x-pn-windows-acm;audio/x-realaudio;audio/x-real-audio;audio/x-sbc;audio/x-speex;audio/x-tta;audio/x-wav;audio/x-wavpack;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-xm;application/x-flac;'
  379. } > $configFile
  380. fi
  381.  
  382. for i in $video_extensions; do
  383. echo Setting Key for $i
  384. gconftool-2 -s "/desktop/mate/thumbnailers/$i"/command -t string "$thumbnailer"
  385. gconftool-2 -s "/desktop/mate/thumbnailers/$i"/enable -t boolean 'true'
  386. done
  387.  
  388. restart_caja
  389.  
  390. [[ $1 != -r ]] && init_configfile
  391. }
  392.  
  393. set_thumbnailer_for_thunar ()
  394. {
  395. local desktopFile=$HOME/.local/share/thumbnailers/imdb.desktop
  396. mkdir -p ${configFile%/*}
  397.  
  398. if [[ $1 = -r ]]; then
  399. rm $desktopFile
  400. else
  401. mkdir -p $HOME/.local/share/thumbnailers &>/dev/null
  402.  
  403. {
  404. echo '[Desktop Entry]'
  405. echo 'Version=1.0'
  406. echo 'Encoding=UTF-8'
  407. echo 'Type=X-Thumbnailer'
  408. echo 'Name=imdb'
  409. echo -n 'MimeType='
  410.  
  411. for i in $video_extensions; do
  412. echo -n ${i//@/\/}\;
  413. done
  414.  
  415. echo ''
  416. echo "X-Thumbnailer-Exec=$(which imdb-thumbnailer) -s %s %u %o"
  417. } > $desktopFile
  418.  
  419. echo "> $desktopFile"
  420.  
  421. init_configfile
  422. fi
  423. }
  424.  
  425. get_query ()
  426. {
  427. declare -l name=$*
  428.  
  429. name=${name##*/}
  430. name=${name//.[5].[1]} # только для HDRezka
  431. name=${name//.[2].[0]} # только для HDRezka
  432. name=${name%.???}
  433. name=${name//[_\.\-() ]/+}
  434. name=${name//s[0-9][0-9]}
  435. name=${name//e[0-9][0-9]}
  436. #name=${name//[0-9][0-9]} #надо проверить
  437. name=${name//cd[1-9]}
  438. name=${name//[1-9]of[1-9]}
  439. name=${name//fps}
  440. name=${name//webdl}
  441. name=${name//webrip}
  442. name=${name//dvdrip}
  443. name=${name//dvdscr}
  444. name=${name//axxo}
  445. name=${name//fxg}
  446. name=${name//divx}
  447. name=${name//xvid}
  448. name=${name//mkv}
  449. name=${name//720p}
  450. name=${name//720}
  451. name=${name//1080p}
  452. name=${name//1080i}
  453. name=${name//[0-9][0-9][0-9][0-9]} #типа год
  454. name=${name//h+264}
  455. name=${name//x264}
  456. name=${name//h264}
  457. name=${name//264}
  458. name=${name//x265}
  459. name=${name//hddvd}
  460. name=${name//hdrezka}
  461. name=${name//hdrip}
  462. name=${name//hd}
  463. name=${name//blueray}
  464. name=${name//brrip}
  465. name=${name//bdrip}
  466. name=${name//bd}
  467. name=${name//tvrip}
  468. name=${name//yify}
  469. name=${name//aac}
  470. name=${name//ac3}
  471. name=${name//nf}
  472. name=${name//rip}
  473. name=${name//lq}
  474. name=${name//tvshows}
  475. name=${name//selezen}
  476. name=${name//studio}
  477. name=${name//nnmclub}
  478. name=${name//hevc}
  479. name=${name//ужасы}
  480. name=${name//фантастика}
  481. name=${name//боевик}
  482. name=${name//приключения}
  483. name=${name//триллер}
  484. name=${name//детектив}
  485. name=${name//rus}
  486. name=${name//eng}
  487. name=${name//lostfilm}
  488. name=${name//ideafilm}
  489. name=${name//new}
  490. name=${name//tv}
  491. name=${name//".ts"}
  492. name=${name//#[0-9][0-9]}
  493. # name=${name//#[0-9]}
  494. name=${name//'open+matte'}
  495. name=${name//"[nolimits+team]"}
  496. name=${name//"ay+oasis+nnm+club"}
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505. query=$name
  506.  
  507. parse_filename
  508. }
  509.  
  510. get_id ()
  511. {
  512. local search=$*
  513.  
  514. while rdom; do
  515. if [[ $E = h3* ]] && rdom && [[ $E = *https://????imdb.com/title/tt* ]]; then
  516. var href = this href
  517. href=${href%/*}/
  518. href=https:${href#*https:}
  519. get_id_from_url ${href}
  520. return
  521. fi
  522. done < <(wget -U firefox -qO - "google.com/search?q=site:imdb.com/title+$search")
  523. #done < <(wget -U firefox -qO - "google.com/search?q=title%20site:imdb.com")
  524. echo 'get_id_from_google'
  525. echo "href ${href}"
  526.  
  527. #get_id_from_imdb2 "$*"
  528.  
  529. [[ $id ]] || get_id_from_imdb "$*" && get_id_from_bing "$*" && get_id_from_imdb2 "$*"
  530. }
  531.  
  532. get_id_from_bing ()
  533. {
  534. local search=$*
  535.  
  536. while rdom; do
  537. if [[ $E = h2* ]] && rdom && [[ $E = *https://????imdb.com/title/tt* ]]; then
  538. var href = this href
  539. href=${href%/*}/
  540. href=https:${href#*https:}
  541. get_id_from_url ${href}
  542.  
  543. return
  544. fi
  545. done < <(wget -U firefox -qO - "bing.com/search?q=site:imdb.com/title+$search")
  546. #done < <(wget -U firefox -qO - "bing.com/search?q=title%20site:imdb.com")
  547. echo 'get_id_from_bing'
  548. echo "href ${href}"
  549. }
  550. get_id_from_imdb ()
  551. {
  552. local search=$*
  553.  
  554. while rdom; do
  555. if [[ $E = h1* ]] && rdom && [[ $E = *https://????imdb.com/title/tt* ]]; then
  556. var href = this href
  557. echo "href= ${href}"
  558. href=${href%/*}/
  559. echo "href= ${href}"
  560. href=https:${href#*https:}
  561. echo "href= ${href}"
  562. get_id_from_url ${href}
  563.  
  564. return
  565. fi
  566. done < <(wget -U firefox -qO - "imdb.com/find?q=$search")
  567. # #done < <(wget -U firefox -qO - "bing.com/search?q=title%20site:imdb.com")
  568. echo 'get_id_from_imdb'
  569. echo "href ${href}"
  570. echo "link imdb.com/find?q=$search"
  571. }
  572. get_id_from_imdb2 () {
  573. echo "get_id_from_imdb2"
  574. local search=$*
  575.  
  576.  
  577. id=$(wget -U firefox -qO - "imdb.com/find?q=$search" | sed -e '/Titles<\/h3>/,/findMoreMatches/!d' | grep -E -w -o "\/title\/[a-zA-Z0-9]+\/" | head -1 | awk -F"/" '{ print $3}')
  578. echo "id= $id"
  579. echo "imdb.com/find?q=$search"
  580.  
  581. }
  582.  
  583. get_id_from_url ()
  584. {
  585. local IFS=/
  586. set -- $1
  587. case $* in
  588. https:*imdb.*title*tt* ) id=$5
  589.  
  590. ;; *title*tt* ) id=$3
  591.  
  592. ;; tt[0-9]* ) id=$1
  593.  
  594. ;; * | "" ) return 1
  595. esac
  596.  
  597. echo 'get_id_from_url'
  598. echo 'id5: $id'
  599.  
  600. }
  601.  
  602. var () { local return ; "${@:3}" ; eval $1$2\$return;}
  603.  
  604. this ()
  605. {
  606. return=${E#* }
  607. eval local ${return%/}
  608. return=${!1}
  609. }
  610.  
  611. rdom () { local IFS=\> ; read -d \< E C ;}
  612.  
  613. get_grabber_picture ()
  614. {
  615. if [[ $1 ]]; then
  616. id=$1
  617. id=${id%%:*}
  618.  
  619. while rdom; do
  620. #if [[ $E = *'class="poster'* ]]; then
  621. if [[ $E = *'class="poster"'* ]]; then
  622. rdom;rdom;
  623.  
  624. if [[ $E != *add_photo_text* ]]; then
  625. var icon = this src
  626. fi
  627. break
  628. fi
  629. done < <(wget -U firefox -qO - "https://www.imdb.com/title/$id/")
  630.  
  631. [[ $icon ]] && grabber_picture=${icon%@*}@.png #${icon%@@*}@@.png #_V1._SX512_SY512_.png
  632. #[[ $icon ]] && grabber_picture=${icon%@@*}@@._V1._SX${size}_SY${size}_.png
  633. fi
  634. }
  635. # get_grabber_picture ()
  636. # {
  637. # if [[ $1 ]]; then
  638. # id=$1
  639. # id=${id%%:*}
  640.  
  641. # while rdom; do
  642. # if [[ $E = *'og="image"'* ]]; then
  643. # rdom;rdom;
  644.  
  645. # if [[ $E != *add_photo_text* ]]; then
  646. # var icon = this content
  647. # fi
  648. # break
  649. # fi
  650. # done < <(wget -U firefox -qO - "https://www.imdb.com/title/$id/mediaviewer/rm1632284417")
  651.  
  652. # [[ $icon ]] && grabber_picture=${icon%@@*}@@._V1._SX512_SY512_.png
  653. # #[[ $icon ]] && grabber_picture=${icon%@@*}@@._V1._SX${size}_SY${size}_.png
  654. # fi
  655. # }
  656.  
  657. get_custom_cover ()
  658. {
  659. file_time_size=$(stat --format=%y-%s "$SOURCE_pathname") file_time_size=${file_time_size//.*-/-}
  660.  
  661. cover_name=$file_time_size
  662. cover_path=$HOME/.imdb-thumbnailer/covers
  663.  
  664. if [[ -f $cover_path/$cover_name.png ]]; then
  665. grabber_picture=$cover_path/$cover_name.png
  666. fi
  667. }
  668.  
  669. check_path ()
  670. {
  671. #check if it match the current folder:
  672. for i in "${films_path[@]}"; do
  673. if [[ "$1" = "$i/"* ]]; then
  674. return 0
  675. folder2filter=yes
  676. break
  677. fi
  678. done
  679.  
  680. return 1
  681. }
  682.  
  683. get_cover ()
  684. {
  685. #imdb-thumbnailer:
  686. if [[ ! $grabber_picture ]]; then
  687. if [[ -z $id ]]; then
  688. get_query "$SOURCE_url"
  689. get_id "$query"
  690. fi
  691.  
  692. get_grabber_picture $id
  693.  
  694. if [[ -z $grabber_picture ]]; then
  695. default_video_thumbnailer
  696. exit
  697. fi
  698. fi
  699. }
  700.  
  701. make_cover ()
  702. {
  703. case $theme_name in
  704. shadow )
  705. size=$(( $size - 12 ))
  706.  
  707. convert \
  708. "$grabber_picture" -thumbnail ${size}x${size} \
  709. \( +clone -background black -shadow 55x3+3+3 -channel A -evaluate multiply 2 +channel \) \
  710. +swap +repage -gravity center -geometry -0-2 -composite \
  711. "$OUTPUT_path.png"
  712. #ffmpegthumbnailer -i "$grabber_picture" -thumbnail -s 512 -o "$OUTPUT_path.png" -f
  713. echo "OUTPUT_path: $OUTPUT_path"
  714. echo "OUTPUT_path.png: $OUTPUT_path.png"
  715. ;;
  716. movie_strip )
  717. #convert "$grabber_picture" -thumbnail ${size}x${size} "$OUTPUT_path.png"
  718. ffmpegthumbnailer -i "$grabber_picture" -thumbnail -s 512 -o "$OUTPUT_path.png" -f
  719. ;;
  720. * )
  721. convert "$grabber_picture" -thumbnail ${size}x${size} "$OUTPUT_path.png"
  722. ;;
  723. esac
  724. #cp "$OUTPUT_path.png" "/home/ypp/.cache/thumbnails/large"
  725. mv "$OUTPUT_path.png" "$OUTPUT_path"
  726.  
  727.  
  728. }
  729.  
  730. get_SOURCE_pathname ()
  731. {
  732. SOURCE_pathname=${1//\'/\\\'}
  733. #echo "SOURCE_pathname1: $SOURCE_pathname"
  734. SOURCE_pathname=$(python2 -c "from urllib import url2pathname; print url2pathname('$SOURCE_pathname')")
  735. #echo "SOURCE_pathname2: $SOURCE_pathname"
  736. SOURCE_pathname=${SOURCE_pathname#file://}
  737. #echo "SOURCE_pathname3: $SOURCE_pathname"
  738.  
  739. }
  740.  
  741. init ()
  742. {
  743. if [[ -z $1 ]]; then
  744. help
  745. exit
  746. fi
  747.  
  748. [[ -f $config_FILE ]] && . $config_FILE
  749.  
  750. while [[ $1 ]]; do
  751. case $1 in
  752. -s ) shift
  753. #size=$1
  754. size=512
  755. ;;
  756. -s | --set ) shift
  757. while [[ $1 ]]; do
  758. set_thumbnail "$1" "$2"
  759. shift 2
  760. done
  761. exit
  762. ;;
  763. -r | --remove ) shift
  764. while [[ $1 ]]; do
  765. remove_thumbnail "$1"
  766. shift
  767. done
  768. exit
  769. ;;
  770. -u | --update | --refresh )
  771. shift
  772. while [[ $1 ]]; do
  773. update_thumbnail "$1"
  774. shift
  775. done
  776. exit
  777. ;;
  778. -n | --name )
  779. shift
  780. get_id "$2"
  781. #get_id "$query"
  782. get_grabber_picture $id
  783. set_thumbnail "$1" "$grabber_picture"
  784. exit
  785. ;;
  786. --set-nautilus )
  787. set_thumbnailer_for_nautilus
  788. exit
  789. ;;
  790. --unset-nautilus )
  791. set_thumbnailer_for_nautilus -r
  792. exit
  793. ;;
  794. --set-thunar )
  795. set_thumbnailer_for_thunar
  796. exit
  797. ;;
  798. --unset-thunar )
  799. rm $HOME/.local/share/thumbnailers/imdb.desktop && echo "rm $HOME/.local/share/thumbnailers/imdb.desktop" || echo "ERROR: not set"
  800. exit
  801. ;;
  802. --set-caja )
  803. set_thumbnailer_for_caja
  804. exit
  805. ;;
  806. --unset-caja )
  807. set_thumbnailer_for_caja -r
  808. exit
  809. ;;
  810. -t | --theme )
  811. shift
  812. if [ -f "$themes_PATH/$1" ] ; then
  813. theme_name=$1
  814. else
  815. echo "$1 theme does not exist"
  816. exit 1
  817. fi
  818. ;;
  819. --test)
  820. file=$2
  821.  
  822. if check_path "$file"; then
  823. echo "Path IS in the list"
  824. else
  825. echo "Path NOT in the list"
  826. fi
  827.  
  828. SOURCE_url=${file//\'/\\\'}
  829. #SOURCE_url=file://$(python2 -c "from urllib import pathname2url; print pathname2url('$SOURCE_url')")
  830. SOURCE_url=${SOURCE_url#file://}
  831. echo "SOURCE_url: $SOURCE_url"
  832.  
  833. get_SOURCE_pathname "$SOURCE_url"
  834. echo "SOURCE_pathname: $SOURCE_pathname"
  835.  
  836. get_query "$SOURCE_url"
  837. echo "query: $query"
  838.  
  839.  
  840. get_id "$query"
  841. echo "id: $id"
  842. echo "url: https://www.imdb.com/title/$id/"
  843.  
  844. get_grabber_picture $id
  845. echo "grabber_picture: $grabber_picture"
  846. #lsix "$grabber_picture" || echo "grabber_picture does not exist"
  847. set_thumbnail "$2" "$grabber_picture"
  848. exit
  849. ;;
  850. --test-grabber)
  851. id=tt1831804
  852. #id=tt2494362
  853. get_grabber_picture $id
  854. echo "grabber_picture: $grabber_picture"
  855. exit
  856. ;;
  857. --help | -h ) help
  858. exit
  859. ;;
  860. --version | -v )
  861. echo $version
  862. exit
  863. ;;
  864. * ) if [[ -z $SOURCE_url ]]; then
  865. SOURCE_url=$1
  866. elif [[ -z $OUTPUT_path ]]; then
  867. OUTPUT_path=$1
  868. else
  869. echo "$1 is invalid"
  870. exit 1
  871. fi
  872. esac
  873. shift
  874. done
  875.  
  876. #decode filename:
  877. get_SOURCE_pathname "$SOURCE_url"
  878. get_custom_cover
  879.  
  880. if [[ ! $grabber_picture ]]; then
  881. if ! check_path "$SOURCE_pathname"; then
  882. default_video_thumbnailer
  883. exit
  884. fi
  885. fi
  886.  
  887. get_cover
  888. make_cover
  889. }
  890.  
  891. init "$@"
  892.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement