Class: Quvi::Handle

Inherits:
Object
  • Object
show all
Defined in:
lib/quvi/handle.rb,
ext/quvi_ext/quvi_ext.c

Constant Summary collapse

DEFAULT_USER_AGENT =
"Mozilla/5.0".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/quvi_ext/quvi_ext.c', line 81

VALUE qv_handle_init(int argc, VALUE *argv, VALUE self)
{
    qv_handle_t *handle = DATA_PTR(self);
    VALUE opts,
          user_agent = qv_DEFAULT_USER_AGENT,
          autoproxy = Qfalse;

    rb_scan_args(argc, argv, "01", &opts);
    if (opts != Qnil) {
        VALUE arg;
        Check_Type(opts, T_HASH);
        arg = rb_hash_lookup2(opts, qv_sym_autoproxy, Qundef);
        if (arg != Qundef) {
            autoproxy = arg;
        }
        arg = rb_hash_aref(opts, qv_sym_user_agent);
        if (arg != Qnil) {
            Check_Type(arg, T_STRING);
            user_agent = arg;
        }
    }
    handle->q = quvi_new();
    if (quvi_ok(handle->q) == QUVI_FALSE) {
        qv_raise(handle, "unable create quvi_t handle");
    }
    rb_funcall2(self, rb_intern("autoproxy="), 1, &autoproxy);
    rb_funcall2(self, rb_intern("user_agent="), 1, &user_agent);
    return self;
}

Instance Attribute Details

#allow_cookiesObject

Returns the value of attribute allow_cookies.



5
6
7
# File 'lib/quvi/handle.rb', line 5

def allow_cookies
  @allow_cookies
end

#user_agentObject

Returns the value of attribute user_agent.



5
6
7
# File 'lib/quvi/handle.rb', line 5

def user_agent
  @user_agent
end

Instance Method Details

#autoproxy=(val) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'ext/quvi_ext/quvi_ext.c', line 111

VALUE qv_handle_autoproxy_set(VALUE self, VALUE val)
{
    qv_handle_t *handle = DATA_PTR(self);
    int new_val = RTEST(val);

    quvi_set(handle->q, QUVI_OPTION_AUTOPROXY, new_val);
    rb_ivar_set(self, rb_intern("@autoproxy"), new_val ? Qtrue : Qfalse);
    return new_val;
}

#supports?(*args) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'ext/quvi_ext/quvi_ext.c', line 148

VALUE qv_handle_supports_p(int argc, VALUE *argv, VALUE self)
{
    VALUE opts;
    qv_supports_params_t params;

    params.handle  = DATA_PTR(self);
    params.type = QUVI_SUPPORTS_TYPE_ANY;
    params.mode = QUVI_SUPPORTS_MODE_OFFLINE;
    params.res = QUVI_FALSE;
    rb_scan_args(argc, argv, "11", &params.url, &opts);
    Check_Type(params.url, T_STRING);
    if (opts != Qnil) {
        VALUE arg;
        Check_Type(opts, T_HASH);
        arg = rb_hash_lookup2(opts, qv_sym_online, Qundef);
        if (arg != Qundef) {
            params.mode = RTEST(arg) ? QUVI_SUPPORTS_MODE_ONLINE : QUVI_SUPPORTS_MODE_OFFLINE;
        }
        arg = rb_hash_aref(opts, qv_sym_type);
        if (arg != Qnil) {
            if (arg == qv_sym_media) {
                params.type = QUVI_SUPPORTS_TYPE_MEDIA;
            } else if (arg == qv_sym_playlist) {
                params.type = QUVI_SUPPORTS_TYPE_PLAYLIST;
            } else if (arg == qv_sym_subtitle) {
                params.type = QUVI_SUPPORTS_TYPE_SUBTITLE;
            } else if (arg == qv_sym_any) {
                params.type = QUVI_SUPPORTS_TYPE_ANY;
            } else {
                rb_raise(rb_eArgError, "unknown type: %s", StringValuePtr(arg));
            }
        }
    }
    rb_thread_call_without_gvl(qv_handle_supports_p_nogvl, &params, RUBY_UBF_IO, 0);
    if (params.res == QUVI_TRUE) {
        return Qtrue;
    }
    if (quvi_errcode(params.handle) != QUVI_ERROR_NO_SUPPORT) {
        qv_raise(params.handle, "unable to check if URL supported");
    }
    return Qfalse;
}