suggest_file_name: refactoring and rewriting a bit
[conkeror.git] / modules / page-modes / dailymotion.js
blobfd29feaf5116db82c21955b8cd4c6eb747995c02
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 in_module(null);
10 require("content-buffer.js");
11 require("media.js");
13 function media_scrape_dailymotion(buffer, results) {
14     var text = unescape(buffer.document.documentElement.innerHTML);
15     const reg = /video=([^&]+)&/;
17     const reg2 = /([^\|]*)@@\w+$/;
18     var match = reg.exec(text);
19     var param;
20     if (!match || !(param = match[1]))
21         return;
23     param = unescape(param);
25     match = reg2.exec(param);
26     var path;
27     if (!match || !(path = match[1]))
28         return;
29     let title = get_meta_title(buffer.document);
30     if (title)
31         title = title.replace("Dailymotion : ", "");
32     results.push(load_spec({uri: "http://dailymotion.com" + path,
33                             title: title,
34                             filename_extension: "flv",
35                             source_frame: buffer.top_frame,
36                             mime_type: "video/x-flv"}));
39 define_page_mode("dailymotion_mode",
40     $display_name = "Dailymotion",
41     $enable = function (buffer) {
42         media_setup_local_object_classes(buffer);
43     });
46 var dailymotion_re = build_url_regex($domain = /(?:[^\/]*\.)?dailymotion/);
47 auto_mode_list.push([dailymotion_re, dailymotion_mode]);
48 media_scrapers.unshift([dailymotion_re, media_scrape_dailymotion]);
50 provide("dailymotion");